プリンキピア

第9章リカレントニューラルネットワーク

9.2.2. Tokenization9.2.2 トークン化

Tokens are the atomic (indivisible) units of text. Each time step corresponds to 1 token, but what precisely constitutes a token is a design choice. For example, we could represent the sentence “Baby needs a new pair of shoes” as a sequence of 7 words, where the set of all words comprise a large vocabulary (typically tens or hundreds of thousands of words). Or we would represent the same sentence as a much longer sequence of 30 characters, using a much smaller vocabulary (there are only 256 distinct ASCII characters). Below, we tokenize our preprocessed text into a sequence of characters.
英語のヒント
トークンは、テキストの原子的な(分割できない)単位である。各時間ステップは1トークンに対応するが、厳密に何をトークンとするかは設計上の選択である。たとえば、「Baby needs a new pair of shoes」(赤ちゃんには新しい靴が一足要る)という文を7語の系列として表すこともできる。その場合、すべての単語の集合が大きな語彙(ふつう数万から数十万語)をなす。あるいは、同じ文を、ずっと小さな語彙(異なるASCII文字は256個しかない)を使って、ずっと長い30文字の系列として表すこともある。以下では、前処理したテキストを文字の系列にトークン化する。
@d2l.add_to_class(TimeMachine)  #@save
def _tokenize(self, text):
    return list(text)

tokens = data._tokenize(text)
','.join(tokens[:30])
't,h,e, ,t,i,m,e, ,m,a,c,h,i,n,e, ,b,y, ,h, ,g, ,w,e,l,l,s, '