プリンキピア

第15章自然言語処理:事前学習

15.4. Pretraining word2vec15.4 word2vecの事前学習

We go on to implement the skip-gram model defined in Section 15.1. Then we will pretrain word2vec using negative sampling on the PTB dataset. First of all, let’s obtain the data iterator and the vocabulary for this dataset by calling the d2l.load_data_ptb function, which was described in Section 15.3
英語のヒント
続いて、15.1節で定義したスキップグラムモデルを実装する。それから、PTBのデータセットの上で、負例サンプリングを使ってword2vecを事前学習する。まず、15.3節で説明したd2l.load_data_ptb関数を呼び出して、このデータセットのデータイテレータと語彙を得よう。
import math
import torch
from torch import nn
from d2l import torch as d2l

batch_size, max_window_size, num_noise_words = 512, 5, 5
data_iter, vocab = d2l.load_data_ptb(batch_size, max_window_size,
                                     num_noise_words)