You open your notebook, grab a pre-trained BERT, run customer reviews through it — and get 78% accuracy. Seems decent. But a week later in production, the classifier starts confusing "not bad" with "bad," and the emoji 😊 turns into [UNK]. Sound familiar? This is the classic NLP trap: the model is only as good as the preprocessing. And the first place everything breaks is tokenization.
Why tokenization matters more than you think
Tokenization is not just "splitting text into words." It determines how the model sees your text: which units go into the vocabulary, how rare words, numbers, punctuation, and emojis are handled. Take a simple example: a language with rich morphology. If you use word-level tokenization (as in old spaCy), the words "красивый" and "красивая" become different tokens, and the model won't see the connection between them. BPE (Byte Pair Encoding) solves this by splitting words into subwords: "красив" + "ый", "красив" + "ая". This way the model generalizes better and requires less data.
But there are pitfalls here too. For example, the BERT tokenizer for Russian may split the word "Москва" into "Моск" and "##ква". If you're building a named entity recognition model, such splitting can hinder. The solution is to use a tokenizer trained on your domain or add words to the vocabulary.
Embeddings: where density beats sparsity
We once used TF-IDF and bag of words. They work but don't capture semantics: "chair" and "armchair" are as far apart for them as "chair" and "space." Embeddings (Word2Vec, GloVe, fastText) solve this by placing words in a dense vector space where semantically similar words are close. But they have limitations: one word — one vector, regardless of context. "Key" could be a spring or a tool — Word2Vec can't distinguish.
Contextual embeddings (ELMo, BERT) went further: they build a vector for each occurrence of a word considering its surroundings. This is a breakthrough, but also a cost: the model weighs hundreds of megabytes and requires a GPU for fast inference. If your task is short text classification, fastText with n-grams, which trains in minutes on CPU, might suffice.
Transformer: power and responsibility
The Transformer architecture (2017) changed NLP. The self-attention mechanism allows the model to weigh the importance of each word in a sentence when building a representation for each token. BERT (2018) showed that pre-training on large corpora followed by fine-tuning yields record results. GPT went further in text generation.
But with power comes responsibility. Here are typical mistakes when working with Transformer:
- Too large learning rate. BERT is fine-tuned with learning rates 2e-5, 3e-5, 5e-5. If you set 1e-3, the model will forget everything it knew.
- Small batch size. For stability, use batch size 16 or 32; with 2–4, gradients are noisy, training is unstable.
- Ignoring maximum length. BERT accepts a maximum of 512 tokens. If the text is longer, it will be truncated — and you'll lose important information. Solution: split into chunks or use Longformer.
Practical walkthrough: sentiment classification of reviews
Imagine an online store that wants to automatically detect negative reviews. You have 10,000 labeled examples (positive/negative). Action plan:
- Preprocessing. Clean text from HTML, lowercase, but keep emojis (they carry emotion). Tokenize using the RuBERT tokenizer.
- Model selection. Take pre-trained rubert-base-cased and add a classification head (linear layer over the [CLS] token).
- Training. Split data into train/validation (80/20), use AdamW with lr=2e-5, batch 16, 3 epochs. Early stopping on validation loss.
- Evaluation. Compute accuracy, precision, recall, and F1. Pay attention to class imbalance: if negative reviews are only 10%, accuracy will be deceptively high.
What goes wrong if you skip step 1? Emojis turn into [UNK], and the model loses the signal. If you don't account for imbalance, the model will predict everything as positive, achieving 90% accuracy but 0 recall on negatives.
Learning paths: self-study vs structured
Self-studying NLP means hundreds of articles, tutorials, and Stack Overflow. Pros: free and flexible. Cons: no system, easy to miss important concepts, and no one points out code errors. Courses provide structure and feedback. For example, at asibiont.com the NLP course is built so that after each module you submit a practical assignment and a test, and an AI tutor answers questions. This doesn't replace a mentor but helps you avoid getting stuck for a week over a single tokenization error.
Let's compare on three parameters:
| Criterion | Self-study | Course |
|---|---|---|
| Time to first project | 2–6 months (depends on experience) | 1–2 months structured |
| Feedback | Forums, Stack Overflow (may not get an answer) | AI tutor, assignment review |
| Depth | Can dig as much as you want | Limited by curriculum, but can go deeper if desired |
If you're already familiar with Python and machine learning, the self-study path with the book "Natural Language Processing with Transformers" (from Hugging Face) may be more effective. If you're a beginner and want to avoid typical mistakes, a structured course will save you nerves.
Who needs this and who doesn't
NLP is worth learning if you work with text data: review analytics, chatbots, entity extraction, machine translation. Also if you're an ML engineer and want to expand your competencies. Don't go into NLP if you're not ready for experimentation: there are many heuristics and few guarantees. If your task is just to count word frequencies, regular expressions and Python's Counter will suffice.
In conclusion, I want to emphasize: NLP is a field where 80% of success depends on data quality and preprocessing, and only 20% on model choice. Start small: take a review dataset, try TF-IDF + logistic regression, then move to BERT. And don't be afraid to make mistakes — every tokenization error teaches better than any theory. If you want to systematically go from tokenization to Transformer architectures with practice on Hugging Face and PyTorch, check out the course Natural Language Processing (NLP).