第16章自然言語処理:応用
16.3. Sentiment Analysis: Using Convolutional Neural Networks16.3 感情分析:畳み込みニューラルネットワークを使う
In Section 7, we investigated mechanisms for processing two-dimensional image data with two-dimensional CNNs, which were applied to local features such as adjacent pixels. Though originally designed for computer vision, CNNs are also widely used for natural language processing. Simply put, just think of any text sequence as a one-dimensional image. In this way, one-dimensional CNNs can process local features such as -grams in text.
英語のヒント
第7章では、2次元のCNNで2次元の画像データを処理する仕組みを調べた。そこでは、CNNは隣り合う画素のような局所的な特徴に当てはめられた。CNNはもともとコンピュータビジョンのために設計されたが、自然言語処理にも広く使われている。簡単に言えば、どんなテキストの系列も1次元の画像だと考えればよい。こうして、1次元のCNNは、テキストの中のグラムのような局所的な特徴を処理できる。
In this section, we will use the textCNN model to demonstrate how to design a CNN architecture for representing single text (Kim, 2014). Compared with Fig. 16.2.1 that uses an RNN architecture with GloVe pretraining for sentiment analysis, the only difference in Fig. 16.3.1 lies in the choice of the architecture.
英語のヒント
Fig. 16.3.1図16.3.1
This section feeds pretrained GloVe to a CNN-based architecture for sentiment analysis.
英語のヒント
この節では、事前学習したGloVeを、感情分析のためのCNNにもとづくアーキテクチャに入れる。
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)