Токен
У контексті AI і NLP, токен - це фундаментальна одиниця тексту, наприклад, слово, частина слова або знак пунктування, що використовується для обробки та аналізу.
Токенізація – це процес розбиття тексту на ці токени. Це важливий крок у підготовці текстових даних для моделей машинного навчання, що дозволяє моделям розуміти та обробляти текст. Конкретні правила токенізації можуть відрізнятися залежно від завдання та використовуваної моделі, при цьому різні токенізатори дають різні результати.
Методи токенізації варіюються від простого розділення пробілами до більш складних методів, які враховують підсловові одиниці або представлення на рівні символів. Вибір токенізатора значно впливає на продуктивність моделей NLP. Наприклад, токенізатор на основі слів може розглядати 'cat' та 'cats' як окремі токени, тоді як підслововий токенізатор може розбити 'cats' на 'cat' та 's'.
graph LR
Center["Токен"]:::main
Pre_cryptography["cryptography"]:::pre --> Center
click Pre_cryptography "/terms/cryptography"
Rel_machine_learning["machine-learning"]:::related -.-> Center
click Rel_machine_learning "/terms/machine-learning"
Rel_token["token"]:::related -.-> Center
click Rel_token "/terms/token"
Rel_tokenizer["tokenizer"]:::related -.-> Center
click Rel_tokenizer "/terms/tokenizer"
classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
linkStyle default stroke:#4b5563,stroke-width:2px;
🧠 Перевірка знань
🧒 Простими словами
A [token](/uk/terms/token) is like a single Lego brick that makes up a sentence. AI breaks sentences into these bricks (words, parts of words, or punctuation) so it can understand and build new sentences.
🤓 Expert Deep Dive
Tokenization is a critical preprocessing step in NLP pipelines. Subword tokenization algorithms like BPE, WordPiece, and SentencePiece have become dominant because they balance vocabulary size with the ability to represent rare words and morphology. BPE iteratively merges frequent pairs of characters or bytes, while WordPiece uses a likelihood-based approach. SentencePiece treats text as a sequence of Unicode characters and learns subword units directly, making it language-agnostic. The choice of tokenizer impacts downstream tasks: a word-level tokenizer struggles with OOV words, while character-level tokenizers result in very long sequences. Subword tokenizers offer a compromise, allowing models to handle morphology (e.g., 'running' -> 'run', '##ing') and unknown words by composing them from known subwords. The mapping from tokens to numerical IDs and then to dense vector embeddings (e.g., Word2Vec, GloVe, or contextual embeddings from Transformers) is where semantic meaning is encoded for the model.