0Pricing
Deep Learning Academy · レッスン

トークン化して語彙を構築する

テキストを整数IDに対応付けます

「トークン化して語彙を構築する」はCoddyKit上の無料Deep Learning Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDeep Learning Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Deep Learning Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Networks Only Eat Numbers

A neural net cannot read raw letters. Before any learning happens, you must turn text into numbers the model can crunch. 🔢

First Step: Tokenize

To tokenize means to split text into small pieces called tokens. The simplest choice is to split a sentence on spaces into words.

text = "I love deep learning"
tokens = text.split()
# ["I", "love", "deep", "learning"]

Tokens Can Be Smaller

A token need not be a whole word. It can be a character or a sub-word piece, which helps the model handle rare or unseen words.

Build a Vocabulary

A vocabulary is the full set of unique tokens your model knows. You collect every distinct token across your training text.

Give Each Token an Id

Each unique token gets one integer id. This mapping from token to id is how words become numbers the network can index.

vocab = {"i": 0, "love": 1, "deep": 2, "learning": 3}

Encode a Sentence

To encode text, you look up each token in the vocabulary and replace it with its id, producing a list of integers.

ids = [vocab[t] for t in ["i", "love", "deep"]]
# [0, 1, 2]

Handle Unknown Words

Some tokens at test time were never seen in training. Map them to a special unknown token so the model still gets a valid id.

unk_id = vocab.get("dragons", vocab["<unk>"])

Special Tokens Help

Add special tokens like padding, start, and end markers. They give the model structure beyond the plain words themselves.

Lowercase and Clean

Normalizing text by lowercasing and stripping punctuation shrinks the vocabulary so Cat and cat share a single id.

Limit the Vocabulary Size

Real corpora have huge vocabularies. Keep only the most frequent tokens to control the vocab size; the rest become unknown.

Now Text Is a Tensor

Once encoded, a sentence is a list of ids you can wrap in a tensor. The pipeline from raw text to model input is complete.

import torch
ids = torch.tensor([0, 1, 2, 3])

Quick Check

What does building a vocabulary give every unique token?

Recap

You split text into tokens, gather the unique ones into a vocabulary, and map each to an integer id so text becomes numbers. ✅

よくある質問

「トークン化して語彙を構築する」レッスンは無料ですか?

はい。「トークン化して語彙を構築する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Deep Learning Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Deep Learning Academyコースには全4レッスンが含まれています。

「トークン化して語彙を構築する」で何を学びますか?

テキストを整数IDに対応付けます ブラウザで直接実行するハンズオンコードでDeep Learning Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Deep Learning Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDeep Learning Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「トークン化して語彙を構築する」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDeep Learning Academyレッスンでコードを書いて実行できますか?

はい。すべてのDeep Learning Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. トークン化して語彙を構築する
  2. nn.Embedding:学習可能な単語ベクトル
  3. 埋め込みが意味を捉える理由
  4. テキスト分類器を学習する
← Deep Learning Academyに戻る