ngrams

torchhd.ngrams(input: VSATensor, n: int = 3) VSATensor[来源]

创建一个包含输入\(n\)-gram统计信息的超向量。

\[\bigoplus_{i=0}^{m - n} \bigotimes_{j = 0}^{n - 1} \Pi^{n - j - 1}(V_{i + j})\]

注意

对于\(n=1\),请使用multiset()代替,对于\(n=m\),请使用bind_sequence()代替。

Parameters:
  • input (VSATensor) – 值超向量。

  • n (int, optional) – 每个 \(n\)-gram 的大小,\(1 \leq n \leq m\)。默认值:3

Shapes:
  • 输入: \((*, m, d)\)

  • 输出: \((*, d)\)

示例:

>>> x = torchhd.random(5, 6)
>>> x
tensor([[-1., -1., -1.,  1.,  1.,  1.],
        [ 1., -1.,  1.,  1.,  1.,  1.],
        [-1., -1.,  1.,  1., -1., -1.],
        [-1., -1.,  1.,  1., -1.,  1.],
        [ 1., -1.,  1.,  1., -1.,  1.]])
>>> torchhd.ngrams(x)
tensor([-1., -1.,  1., -3., -1., -3.])