MCPcopy Create free account
hub / github.com/MotrixLab/FineMoGen / positional_encoding

Function positional_encoding

mogen/models/rnns/t2m_bigru.py:32–40  ·  view source on GitHub ↗
(batch_size, dim, pos)

Source from the content-addressed store, hash-verified

30# batch_size, dimension and position
31# output: (batch_size, dim)
32def positional_encoding(batch_size, dim, pos):
33 assert batch_size == pos.shape[0]
34 positions_enc = np.array(
35 [[pos[j] / np.power(10000, (i - i % 2) / dim) for i in range(dim)]
36 for j in range(batch_size)],
37 dtype=np.float32)
38 positions_enc[:, 0::2] = np.sin(positions_enc[:, 0::2])
39 positions_enc[:, 1::2] = np.cos(positions_enc[:, 1::2])
40 return torch.from_numpy(positions_enc).float()
41
42
43def get_padding_mask(batch_size, seq_len, cap_lens):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected