speechbrain.nnet.embedding 模块
实现 embedding 的库。
- 作者
Abdelwahab Heba 2020
摘要
类
计算 embedding x = wx。 |
参考
- class speechbrain.nnet.embedding.Embedding(num_embeddings, embedding_dim=128, consider_as_one_hot=False, blank_id=0)[source]
基类:
Module
计算 embedding x = wx。
- 参数:
示例
>>> from speechbrain.nnet.embedding import Embedding >>> import torch >>> emb = Embedding( ... num_embeddings=40, ... embedding_dim=39, ... consider_as_one_hot=True, ... blank_id=39 ... ) >>> inputs = torch.Tensor([10,5,2,0,39]).long() >>> output = emb(inputs) >>> output.shape torch.Size([5, 39]) >>> output tensor([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]) >>> emb = Embedding(num_embeddings=5, embedding_dim=3, consider_as_one_hot=False) >>> e = emb(torch.LongTensor([[0, 1, 2], [3, 4, 2]])) >>> e.shape torch.Size([2, 3, 3])