import torch
from fastNLP.embeddings import StaticEmbedding
from fastNLP import Vocabulary
vocab = Vocabulary()
vocab.add_word_lst("this is a demo .".split())
embed = StaticEmbedding(vocab, model_dir_or_name='en-glove-840b-300d')
words = torch.LongTensor([[vocab.to_index(word) for word in "this is a demo .".split()]]) # 将文本转为index
print(embed(words).size()) # StaticEmbedding的使用和pytorch的nn.Embedding是类似的
Got error message while running following code from Part II: 使用预训练的静态embedding
Error message: