Token
トークンがAIにおける基本的な情報単位として機能する仕組みを学びます。NLP、コンピュータビジョン、そしてYOLO26を用いたオープンボキャブラリー検出におけるトークンの役割を探りましょう。
In the sophisticated architecture of modern artificial intelligence, a token represents the fundamental, atomic unit of information that a model processes. Before an algorithm can interpret a sentence, analyze a software script, or recognize objects in an image, the raw input data must be broken down into these discrete, standardized elements. This segmentation is a pivotal step in data preprocessing, transforming unstructured inputs into a numerical format that neural networks can efficiently compute. While humans perceive language as a continuous stream of thoughts or images as seamless visual scenes, computational models require these granular building blocks to perform operations like pattern recognition and semantic analysis.
Link to this sectionトークンとトークン化#
機械学習 (ML)のメカニズムを把握するためには、データの単位とその作成に使用されるプロセスを区別することが不可欠です。この区別は、データパイプラインを設計し、Ultralytics Platformでトレーニング素材を準備する際の混乱を防ぐために重要です。
- トークン化: これは、生のデータを断片に分割するアルゴリズムプロセス(動詞)です。テキストの場合、これはNatural Language Toolkit (NLTK)のようなライブラリを使用して、ある単位がどこで終わり、別の単位がどこで始まるかを決定することを含みます。
- トークン: これは生成された出力(名詞)です。最終的に埋め込み (embedding)として知られる数値ベクトルにマッピングされる、単語、サブワード、画像パッチなどの実際のデータの塊のことです。
Link to this section異なるAI領域におけるトークン#
トークンの性質は、処理されるデータのモダリティ、特にテキスト領域と視覚領域の間で大幅に異なります。
Link to this sectionNLPにおけるテキストトークン#
自然言語処理 (NLP)の分野では、トークンは大規模言語モデル (LLM)の入力となります。初期のアプローチでは厳密に単語全体にマッピングしていましたが、現代のアーキテクチャではByte Pair Encoding (BPE)のようなサブワードアルゴリズムが利用されています。この手法により、モデルは珍しい単語を意味のある音節に分解することで、語彙サイズと意味的カバレッジのバランスを取りながら処理できるようになります。例えば、「unhappiness」という単語は「un」、「happi」、「ness」にトークン化される可能性があります。
Link to this sectionコンピュータビジョンにおけるビジュアルトークン#
The concept of tokenization has expanded into computer vision with the advent of the Vision Transformer (ViT). Unlike traditional convolutional networks that process pixels in sliding windows, Transformers divide an image into a grid of fixed-size patches (e.g., 16x16 pixels). Each patch is flattened and treated as a distinct visual token. This approach enables the model to use self-attention mechanisms to understand the relationship between distant parts of an image, similar to how Google Research originally applied transformers to text.
Link to this section実社会での応用#
トークンは、数え切れないほどのアプリケーションにおいて、人間が扱うデータとマシンインテリジェンスの架け橋として機能します。
-
オープンボキャブラリー物体検出: YOLO-Worldのような高度なモデルは、テキストトークンが視覚的特徴と相互作用するマルチモーダルアプローチを使用します。ユーザーはカスタムテキストプロンプト(例:「青いヘルメット」)を入力でき、モデルはこれをトークン化して画像内のオブジェクトと照合します。これによりゼロショット学習が可能になり、モデルが明示的にトレーニングされていないオブジェクトを検出できるようになります。
-
生成AI: チャットボットのようなテキスト生成システムでは、AIはシーケンス内の次のトークンの確率を予測することで動作します。最も可能性の高い後続トークンを繰り返し選択することで、システムは一貫した文や段落を構築し、自動カスタマーサポートからバーチャルアシスタントに至るまで、さまざまなツールを支えています。
Link to this sectionPythonの例:検出のためのテキストトークンの使用#
以下のコードスニペットは、ultralyticsパッケージがどのようにテキストトークンを使用して物体検出をガイドするかを示しています。最先端のYOLO26は高速で固定クラスの推論に推奨されますが、YOLO-Worldのアーキテクチャは、ユーザーが実行時にクラスをテキストトークンとして定義できるという独自の利点があります。
from ultralytics import YOLO
# Load a pre-trained YOLO-World model capable of understanding text tokens
model = YOLO("yolov8s-world.pt")
# Define specific classes; these text strings are tokenized internally
# The model will look specifically for these "tokens" in the visual data
model.set_classes(["bus", "backpack"])
# Run prediction on an image using the defined tokens
results = model.predict("https://ultralytics.com/images/bus.jpg")
# Display the results showing only the tokenized classes
results[0].show()トークンを理解することは、生成AIと高度なアナリティクスの状況を把握するために不可欠です。チャットボットの流暢な会話を可能にする場合でも、ビジョンシステムが微妙なオブジェクトクラスを区別するのを助ける場合でも、トークンはPyTorchやTensorFlowのようなフレームワークで使用されるマシンインテリジェンスの重要な通貨であり続けます。






