第9章リカレントニューラルネットワーク
9.2. Converting Raw Text into Sequence Data9.2 生のテキストを系列データに変換する
Throughout this book, we will often work with text data represented as sequences of words, characters, or word pieces. To get going, we will need some basic tools for converting raw text into sequences of the appropriate form. Typical preprocessing pipelines execute the following steps:
英語のヒント
この本を通じて、単語、文字、あるいは単語の断片の系列として表されたテキストデータを扱うことが多い。始めるにあたって、生のテキストを適切な形の系列に変換するための基本的な道具が必要になる。典型的な前処理のパイプラインは、次の手順を実行する。
- Load text as strings into memory.
英語のヒント
テキストを文字列としてメモリに読み込む。 - Split the strings into tokens (e.g., words or characters).
英語のヒント
文字列をトークン(たとえば単語や文字)に分割する。 - Build a vocabulary dictionary to associate each vocabulary element with a numerical index.
英語のヒント
語彙の辞書を作り、語彙の各要素に数値のインデックスを対応づける。 - Convert the text into sequences of numerical indices.
英語のヒント
テキストを数値のインデックスの系列に変換する。
import collections
import random
import re
import torch
from d2l import torch as d2l