Lexeme vs Token: What Each Term Means and How They Differ
Lexeme vs token explained for linguistics, compilers and NLP tokenizers, with worked examples and what tokenizing or lemmatizing actually changes in your text.
Both terms name units of text, which is why they get confused. They sit at different levels of abstraction, and their meaning depends on the field. In linguistics and corpus analysis, a token is one concrete occurrence of a word in running text, and a lexeme is the abstract word that occurrence belongs to. In compiler design, the roles are reversed. The lexeme is the concrete string of characters, and the token is the category assigned to it. This guide explains both senses, shows worked examples, and covers what happens to your text when a tool splits it into tokens or groups tokens into lexemes.
The short answer
| Context | Lexeme | Token |
| Linguistics and corpus analysis | An abstract dictionary unit that groups all inflected forms of a word, for example RUN covering run, runs, ran and running | A single occurrence of a word form at a specific position in a text |
| Compilers and lexical analysis | The actual character sequence matched in the source code, for example count | The category assigned to that sequence, for example identifier, often with an attached attribute value |
| NLP and language-model tokenizers | Usually not part of the vocabulary | Whatever unit the tokenizer produces: a whole word, a subword piece, a punctuation mark or a single character |
Rule of thumb: first check which field you are reading. In linguistics, the token is the concrete piece and the lexeme is abstract. In compiler terminology, it is the other way round.
In linguistics: occurrences versus abstract words
Linguists use three levels. A token is each individual occurrence of a word form. A type is each distinct form, however often it appears. A lexeme is the abstract unit that ties related forms together. A lexeme is conventionally represented by its lemma, the citation form you would look up in a dictionary.
Sentence: She runs daily, ran yesterday, and will run again.
Word tokens (9): She | runs | daily | ran | yesterday | and | will | run | again
Word types (9): each form above is distinct
Lexemes (7): SHE, RUN, DAILY, YESTERDAY, AND, WILL, AGAIN
(runs, ran and run all belong to RUN)
If a tokenizer also keeps punctuation, the two commas and the final period become tokens too, for a total of 12. Whether punctuation counts is a convention of the tool or study, not a fixed rule. Always check this before comparing token counts from different sources.
Mapping tokens to lexemes is not purely mechanical. Different forms can belong to one lexeme, as with ran and run. A single form can also belong to different lexemes: saw can be the past tense of SEE or the noun SAW, and will can be a modal verb or a noun. Tools resolve this from context, usually with part-of-speech tagging, and that step can be wrong. The problem grows in heavily inflected languages such as Russian, where one noun or verb lexeme has many case, number, gender or tense forms.
In compilers: the string versus its category
In lexical analysis, the scanner reads source code and matches character sequences against patterns. Each matched sequence is a lexeme. The scanner then emits a token: a token name, often paired with an attribute such as a symbol-table reference or a literal value. The pattern is the rule that decides which lexemes qualify for a token, for example a letter followed by any mix of letters and digits for an identifier.
Source: count = count + 1;
Lexeme Token
count identifier
= assignment operator
count identifier
+ plus operator
1 number literal
; semicolon
Two different lexemes, such as count and total, both become identifier tokens. Whitespace and comments are usually consumed without producing tokens. Exact token names vary between language specifications and scanner tools, so the labels above are illustrative, not standard.
Tokens in NLP and language-model tokenizers
Modern language-model tokenizers often split text into subword units, so a token may be a whole word, part of a word, or a single character or byte. These tokenizers do not identify lexemes, and token boundaries do not necessarily match morphemes or dictionary forms. Token counts from such tools are therefore not word counts. Two tokenizers can also count the same text differently, so check the specific tool before relying on its numbers.
What tokenizing and lemmatizing actually change
Neither operation is a visual effect. Both produce new data derived from your text, and the original stays intact only if you keep it.
- Tokenization segments text into units. Ideally it changes no characters, and better tools record each token's start and end offsets in the original.
- Many tokenizers also normalize along the way. They may lowercase, apply Unicode normalization, drop punctuation, or split contractions; some conventions turn don't into do plus n't. These are real character changes, not just segmentation.
- Character-level splitting by code point can separate a base letter from a combining accent, or break an emoji built from several code points. Segmenting by grapheme cluster avoids this.
- Lemmatization replaces each token with its lemma, mapping ran to run, for example. This collapses forms into lexemes but discards tense, number, case and similar information. It cannot be reversed from the output alone.
- Stemming is not the same as finding lexemes. It strips endings by rule and can produce fragments that are not real words, and it may merge words that belong to different lexemes.
Will the output stay readable and usable?
Token lists and lemma sequences are analysis data, not prose. The example sentence lemmatized becomes something like: she run daily run yesterday and will run again. The vocabulary survives, but the grammar and timeline do not. Pasted into a document or read aloud by a screen reader, this output reads as fragments. The original sentence is what people need for reading, quoting, editing or accessible publishing.
Search is a mixed case. Indexing by lexeme lets a query for run match ran and runs, which usually helps recall. It can also merge unrelated words that share a form, or miss matches when the lemmatizer guesses wrong. The safest workflow keeps three things: the original text, the token offsets, and the derived tokens or lemmas. That way, any result can be traced back to the exact passage it came from.
Which unit fits your use?
- Counting text, measuring model input length or parsing code: work with tokens, and confirm how your specific tool defines them.
- Vocabulary studies, frequency lists by word, dictionary lookups or search that should match inflected forms: group tokens into lexemes through lemmatization. The main benefit is that word forms collapse into one entry; the decisive tradeoff is lost grammatical detail and occasional misassignment of ambiguous forms.
- Anything people will read, quote, edit or access with assistive technology: use the plain original text, not tokens or lemmas.
- Reading compiler or parser documentation: remember that the lexeme is the matched string and the token is its category.
Limits of this overview: no specific tokenizer, lemmatizer or scanner was tested for it. Normalization rules, punctuation handling, contraction splitting and accuracy on ambiguous forms vary by tool and language, especially for highly inflected languages. Before choosing a workflow, run a short sample of your own text through the tool and compare the output against the original.