def forward(self, x):
arr = list()
for sentence in x:
# Sentence embedding
sent_emb = list()
for word in sentence:
word = np.array(word)
word = torch.from_numpy(word)
word = Variable(word)
# Gets the embedding for each character in
# the word
char_emb = self.embedding(word)
# Computes the mean between all character level
# embeddings. MxN -> 1xN
char_emb = torch.mean(char_emb, 0)
sent_emb.append(char_emb)
arr.append(sent_emb)
return arr
lang_model.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录