プリンキピア

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

15.3. The Dataset for Pretraining Word Embeddings15.3 単語埋め込みを事前学習するためのデータセット

Now that we know the technical details of the word2vec models and approximate training methods, let’s walk through their implementations. Specifically, we will take the skip-gram model in Section 15.1 and negative sampling in Section 15.2 as an example. In this section, we begin with the dataset for pretraining the word embedding model: the original format of the data will be transformed into minibatches that can be iterated over during training.
英語のヒント
word2vecのモデルと近似的な訓練方法の技術的な詳細がわかったので、それらの実装を順に見ていこう。具体的には、15.1節のスキップグラムモデルと15.2節の負例サンプリングを例にとる。この節では、単語埋め込みモデルを事前学習するためのデータセットから始める。データの元の形式は、訓練のあいだに反復して取り出せるミニバッチに変換される。
import collections
import math
import os
import random
import torch
from d2l import torch as d2l