第16章自然言語処理:応用
16.2. Sentiment Analysis: Using Recurrent Neural Networks16.2 感情分析:リカレントニューラルネットワークを使う
Like word similarity and analogy tasks, we can also apply pretrained word vectors to sentiment analysis. Since the IMDb review dataset in Section 16.1 is not very big, using text representations that were pretrained on large-scale corpora may reduce overfitting of the model. As a specific example illustrated in Fig. 16.2.1, we will represent each token using the pretrained GloVe model, and feed these token representations into a multilayer bidirectional RNN to obtain the text sequence representation, which will be transformed into sentiment analysis outputs (Maas et al., 2011). For the same downstream application, we will consider a different architectural choice later.
英語のヒント
単語の類似度や類推のタスクと同じように、事前学習した単語ベクトルを感情分析に当てはめることもできる。16.1節のIMDbのレビューのデータセットはあまり大きくないので、大規模なコーパスで事前学習したテキストの表現を使うと、モデルの過学習を減らせるかもしれない。図16.2.1に示す具体的な例として、事前学習したGloVeモデルを使って各トークンを表し、これらのトークンの表現を多層の双方向RNNに入れてテキストの系列の表現を得る。この表現は感情分析の出力に変換される(Maas et al., 2011)。同じ下流の応用について、後で別のアーキテクチャの選び方を考える。
Fig. 16.2.1図16.2.1
This section feeds pretrained GloVe to an RNN-based architecture for sentiment analysis.
英語のヒント
この節では、事前学習したGloVeを、感情分析のためのRNNにもとづくアーキテクチャに入れる。
import torch
from torch import nn
from d2l import torch as d2l
batch_size = 64
train_iter, test_iter, vocab = d2l.load_data_imdb(batch_size)