NLP (Concepts & Pipeline)
Tokenization
In shortSplitting text into smaller units called tokens, such as words, subwords or characters, so a model can process it. The first step in most NLP pipelines.
Tokenisation is the step in natural language processing that splits text into smaller units called tokens. Depending on the method, a token can be a word, part of a word, a punctuation mark or a single character. Every NLP model, from topic modelling to large language models, works on tokens rather than raw text, so tokenisation shapes what the model can see.
How it works
There are three broad approaches:
- Word tokenisation splits on spaces and punctuation, so “Don’t index this page.” becomes tokens like do, n’t, index, this, page and the full stop. Libraries such as NLTK and spaCy apply language-specific rules for contractions, hyphens and URLs.
- Subword tokenisation, used by BERT (WordPiece) and most LLMs (byte-pair encoding and similar methods), breaks rare words into frequent pieces, so a new term like “tokenisation” might become token, isation. This keeps the vocabulary manageable and handles unseen words.
- Character tokenisation treats each character as a token, which is useful for fuzzy matching on character n-grams.
In classic pipelines, tokenisation is followed by lower-casing, stop word removal and stemming or lemmatisation before text is turned into vectors such as a bag of words or TF-IDF.
How it’s used in SEO and marketing
- Topic modelling: LDA needs clean word tokens to build its dictionary and corpus.
- Keyword extraction: KeyBERT uses scikit-learn’s CountVectorizer to tokenise text into candidate unigrams, bigrams and trigrams before embedding them.
- N-gram analysis of keyword lists to find common modifiers.
- LLM costs and limits: API pricing and context windows are measured in tokens, so long pages cost more and may need splitting.
- Chunking for AI search: retrieval systems split pages into token-limited chunks, which is one reason self-contained sections matter.
Example
Running MLforSEO’s LDA notebook on a site crawl, each page’s main text is tokenised, lower-cased, stripped of stop words, numbers and punctuation, and lemmatised. “Optimising” and “optimised” both become “optimise”, so they count as one term, and the topics that come out are built from meaningful words instead of filler.
Limitations and things to watch
- Tokenisers differ between models, so token counts from one LLM do not transfer to another.
- Splitting can break meaningful phrases such as “New York” unless you add n-grams or phrase detection.
- Languages without spaces between words, such as Chinese and Japanese, need specialised tokenisers.
- Over-aggressive cleaning removes words that matter in your niche; review your stop word list.
Learn it on MLforSEO
- Topic Modelling for SEO with LDA (Latent Dirichlet Allocation)
- How to do keyword clustering with KeyBERT
- What Machine Learning Clustering Is, and Where It Fits in SEO
- The Introduction to Machine Learning for SEO course, where tokenisation is part of the LDA, BERTopic and KeyBERT practicals
Where Tokenization shows up on MLforSEO
Sources and further reading
Other terms from NLP (Concepts & Pipeline)
- Content ModerationUsing NLP to flag text that may be harmful or sensitive, such as toxic, insulting or violent content, so it ca…
- Corpus (Text Corpus)A corpus is the collection of text documents you analyse or train a model on, such as your site's pages, revie…
- Emotion detection/analysisAn NLP task that labels text with specific emotions such as joy, anger, sadness, fear and disgust, going beyon…
- Entity Extraction (NER)Named entity recognition: finding names of people, organisations, places, products and other things in text an…
- Entity Sentiment AnalysisNLP that scores the sentiment expressed towards each entity in a text, so one review can be positive about one…
- Lemmatisation and StemmingTwo ways to reduce words to a base form so variants count as one: stemming chops off endings, lemmatisation re…
- Lexical or morphological analysisThe first phase of NLP: splitting text into words and analysing their structure (roots, prefixes, suffixes) so…
- N-gram (Unigram, Bigram, Trigram)A contiguous sequence of n words or characters from a text: unigrams (1), bigrams (2), trigrams (3) and so on,…
- Natural Language Processing (NLP)The field of AI that enables computers to process, analyse and generate human language, from tokenisation and…