プリンキピア

第16章自然言語処理:応用

16.2.2. Loading Pretrained Word Vectors16.2.2 事前学習した単語ベクトルを読み込む

Below we load the pretrained 100-dimensional (needs to be consistent with embed_size) GloVe embeddings for tokens in the vocabulary.
英語のヒント
以下では、語彙のトークンについて、事前学習した100次元の(embed_sizeと一致している必要がある)GloVeの埋め込みを読み込む。
glove_embedding = d2l.TokenEmbedding('glove.6b.100d')
Print the shape of the vectors for all the tokens in the vocabulary.
英語のヒント
語彙のすべてのトークンについて、ベクトルの形状を表示する。
embeds = glove_embedding[vocab.idx_to_token]
embeds.shape
torch.Size([49346, 100])
We use these pretrained word vectors to represent tokens in the reviews and will not update these vectors during training.
英語のヒント
これらの事前学習した単語ベクトルを使ってレビューの中のトークンを表し、訓練のあいだはこれらのベクトルを更新しない。
net.embedding.weight.data.copy_(embeds)
net.embedding.weight.requires_grad = False