Tagging with probabilities from an annotated corpusÉtiqueter avec des probabilités tirées d'un corpus annoté

TRA2600 S5 · in classS5 · en classe

A rule-based tagger

Taggers can be written as rules. The oldest ones worked in two stages: a dictionary listing every possible tag of every word, then thousands of hand-written constraints that rule out the tags incompatible with the context (Jurafsky & Martin, 2026). The dictionary alone is tens of thousands of entries, every one of them written by a person, and the constraints have to be written again for every language. It can be done, and it was, but the cost pushed the field toward its second paradigm, machine learning machine learning (ML)apprentissage automatique machine learningapprentissage automatique An approach to artificial intelligence in which a model is trained on data or experience so that its adjustable parameters come to reflect patterns relevant to a task.Approche de l'intelligence artificielle dans laquelle un modèle est entraîné sur des données ou sur l'expérience, de sorte que ses paramètres ajustables en viennent à refléter des régularités pertinentes pour une tâche. (see also the turn to machine learning page, in the Foundations of AI & NLP module) (voir aussi la page Le virage vers l'apprentissage automatique, dans le module Fondements de l'IA et du TAL).

The most frequent tag

A tagger built by machine learning starts from a corpus corpuscorpus corporacorpus A collection of written texts, speech recordings or transcribed language assembled for analysis or use in language technology (plural: corpora).Ensemble de textes écrits, d'enregistrements de parole ou de langue transcrite réuni pour l'analyse ou pour les technologies langagières. that people have already tagged, and the simplest thing to count in it is how often each word appears under each tag. Book is a noun more often than it is a verb, so a tagger that labels every occurrence of book as a noun will be right most of the time (Figure 6figure 6). This tagger asks the question that comes to mind first: of all the occurrences of book, what share are nouns? A tagger built on that one count for every word, the most frequent tag, is right for about 92 % of the words of an English text, against 97 % for the best taggers and for people (Jurafsky & Martin, 2026; Figure 7figure 7). The gap between a method that ignores the context entirely and the best taggers is five points. That is why a score is read against this kind of simple method before it is called good (see also the Baselines page, in the Evaluating language technology module) (voir aussi la page Les étalons, dans le module L'évaluation des technologies langagières).

The phrase travellers who book a room, each word with the tag it has most often in the small corpus of the worked example and the tag it needs here. travellers NOUN, right; who PRON, right; book NOUN, because the corpus has it 5 times as a noun and twice as a verb, but here it needs VERB, wrong; a DET, right; room NOUN, right.
Figure 6. The most frequent tag on a phrase from the small corpus of the worked example.
A scale from 0 to 100 %, with the stretch from 90 to 100 % enlarged below it. On the enlarged scale, the baseline reaches 92 %, the best systems and people 97 %, and the 5 points between them are marked; the last 3 points, from 97 to 100 %, are beyond human agreement.
Figure 7. Part-of-speech tagging of English: the share of words tagged correctly by the baseline, and by the best systems and by people, with the top of the scale enlarged (Jurafsky & Martin, 2026).

Looking at the previous word

So the challenge is to get from 92 % as close as possible to 97 %. The errors that remain with the naive approach, always using a word’s most frequent tag, mostly come from ambiguous words with more than one possible tag, such as book, which can be a verb or a noun (Figure 6figure 6). To disambiguate such a word, a tagger looks at its context, and a first step is to look not only at the word that needs a tag, but also at the word before it. A bigram is a sequence of two consecutive words, or here of two consecutive tags, and a bigram tagger adds a second count to the first: how often each tag follows the tag of the previous word (Jurafsky & Martin, 2026). The bigram is one case of a general notion, the n-gram, a sequence of n consecutive items: a trigram tagger, for instance, looks at the tags of the two previous words.

The phrase travellers who book a room, with a tag box above each word: NOUN, PRON, a question mark above book, and empty boxes above a and room. An arrow from the PRON box to the question mark asks, of the words that follow PRON, what share are nouns and what share are verbs. An arrow from the word book up to the question mark asks, of the nouns, what share are book, and of the verbs.
Figure 8. The two questions a bigram tagger asks to tag book in travellers who book a room.

The tagger answers the two questions of Figure 8figure 8 with two probabilities, both counted in the tagged corpus, and gives the word the tag for which the two together score highest.

Reading a probability such as P(book | VERB)

A probability is a share: a number between 0 and 1 that says how often something happens out of a set of cases. 0 means never, 1 means always, and 0.25 means one time in four, or 25 %.

The notation P(A | B) is read “the probability of A, given B”. The bar means given, and what comes after it says which cases you count in. Figure 9figure 9 reads P(book | VERB) piece by piece, and the table below reads both probabilities a bigram tagger uses.

P(book | VERB) in large type, each part linked to its reading: P is the probability, book is that a word is book, the bar is given, VERB is that it is a verb.
Figure 9. Reading P(book | VERB).
WrittenRead asCounted as
P(book | VERB)the probability that a word is book, given that it is a verbof all the verbs in the corpus, the share that are book
P(VERB | PRON)the probability that a tag is VERB, given that the previous tag is PRONof all the words that follow a pronoun, the share that are verbs
The two probabilities of a bigram tagger, read aloud and counted.

Both probabilities are plain shares, so you can work them out by hand.

A worked example, step by step

The phrase is travellers who book a room, and the counts come from a small corpus of eight short English sentences, tagged by hand, in which book occurs seven times in the singular (the plural books is another form), five times as a noun and twice as a verb. Figure 10figure 10 builds up with the four steps below.

Mary/PROPN loves/VERB reading/VERB books/NOUN ./PUNCT
On/ADP Monday/PROPN ,/PUNCT she/PRON found/VERB an/DET old/ADJ book/NOUN in/ADP the/DET library/NOUN ./PUNCT
The/DET book/NOUN tells/VERB the/DET story/NOUN of/ADP travellers/NOUN who/PRON book/VERB a/DET room/NOUN in/ADP an/DET old/ADJ hotel/NOUN ./PUNCT
Curious/ADJ ,/PUNCT Mary/PROPN and/CCONJ Tom/PROPN book/VERB a/DET weekend/NOUN there/ADV ./PUNCT
At/ADP the/DET end/NOUN ,/PUNCT she/PRON finds/VERB that/SCONJ the/DET book/NOUN is/AUX a/DET masterpiece/NOUN ./PUNCT
She/PRON decides/VERB to/PART recommend/VERB the/DET book/NOUN to/ADP friends/NOUN ,/PUNCT hoping/VERB that/SCONJ they/PRON will/AUX like/VERB it/PRON too/ADV ./PUNCT
The/DET next/ADJ day/NOUN ,/PUNCT Mary/PROPN starts/VERB a/DET new/ADJ book/NOUN ,/PUNCT because/SCONJ she/PRON ca/AUX n't/PART stop/VERB reading/VERB ./PUNCT
Some/DET call/VERB it/PRON an/DET obsession/NOUN ,/PUNCT but/CCONJ all/DET agree/VERB it/PRON is/AUX harmless/ADJ ./PUNCT

Click the drawing, or a line below, to build it up stage by stage. Cliquez sur le dessin, ou sur une ligne ci-dessous, pour le construire étape par étape.

Figure 10. The worked example for book in travellers who book a room, one stage per step.

Step 1: the candidate tags

The word book with two arrows, one to NOUN with a question mark, one to VERB with a question mark.
Figure 11. Stage 1 of the worked example.

A tagger does not invent a tag: it compares the tags a word can have. The corpus shows two for book, NOUN and VERB, so the tagger computes one score for each, and the higher score wins (Figure 11figure 11).

Step 2: the word, given each tag

A row of 17 squares for the nouns of the corpus, 5 of them coloured for book: 0.294. A row of 16 squares for the verbs, 2 of them coloured for book: 0.125.
Figure 12. Stage 2 of the worked example.

The first question counts, of the words that carry each tag, the share that are book: among the nouns first, then among the verbs, and not among the occurrences of book (Figure 12figure 12).

  • 5 of the 17 nouns are book: 0.294, written P(book | NOUN);
  • 2 of the 16 verbs are book: 0.125, written P(book | VERB).

On this question alone, NOUN is ahead. That is the most frequent tag again, and it is wrong here: the word on its own cannot tell this book from the noun.

Step 3: each tag, given the previous tag

A row of 9 squares for the words that follow a pronoun in the corpus, 4 of them coloured for verbs. No noun: 0. Four verbs: 0.444.
Figure 13. Stage 3 of the worked example.

The second question is what usually comes after the previous tag, which is the information the most frequent tag never used. The word before book is who, a pronoun, and the corpus has 9 words after a pronoun (Figure 13figure 13).

  • none of them is a noun: 0, written P(NOUN | PRON);
  • 4 of them are verbs: 0.444, written P(VERB | PRON).

Step 4: combining the two

Two rows. NOUN: 0.294 times 0 equals 0. VERB: 0.125 times 0.444 equals 0.056, marked as the winner.
Figure 14. Stage 4 of the worked example.

The tagger needs one score per tag that takes both answers into account, so it multiplies them (Figure 14figure 14). A product is high only when both numbers are, and a zero in either makes the whole product zero: NOUN scores 0.294 × 0 = 0, and VERB scores 0.125 × 0.444 = 0.056.

VERB wins. The previous tag has overturned the lead NOUN had on the word alone, and the tagger labels this book a verb, although book is a noun more often than not.

A count of zero decided this case, and in a corpus of a hundred words that happens all the time: a noun can follow a pronoun in English, as in her book, where Universal Dependencies tags her as a pronoun, but the corpus contains no example of it. Real taggers correct for this by giving every count a small minimum, so that a sequence never seen in the corpus is unlikely rather than impossible (Jurafsky & Martin, 2026).

The method as a rule

For every word of a text, a bigram tagger does the same three things with counts from a tagged corpus:

  1. it lists the tags the word can have;
  2. for each tag, it multiplies the share of the word among the words that carry this tag, P(word | tag), by the share of this tag among the words that follow the previous tag, P(tag | previous tag);
  3. it keeps the tag with the larger product.

No rule anywhere says that book after who is a verb, and the method never uses what book means: the counts alone decide.

exercise 1 "the word given the tag, for the noun"exercice 1 « le mot sachant l'étiquette, pour le nom » and the exercises after it apply the same four steps to another word, watch, in she checks her watch, then to he waits, watch in hand, where the rule gives the wrong answer.

Written in English. The French version was automatically generated and I have not revised it. Rédigé en anglais. La version française a été générée automatiquement et je ne l'ai pas révisée. Updated 7 October 2026

Un étiqueteur à base de règles

On peut écrire un étiqueteur sous forme de règles. Les plus anciens fonctionnaient en deux temps : un dictionnaire qui donne toutes les étiquettes possibles de chaque mot, puis des milliers de contraintes écrites à la main qui éliminent les étiquettes incompatibles avec le contexte (Jurafsky & Martin, 2026). Le dictionnaire compte à lui seul des dizaines de milliers d’entrées, toutes rédigées par une personne, et les contraintes sont à réécrire pour chaque langue. C’est faisable, et cela a été fait, mais le coût a poussé le domaine vers son deuxième paradigme, l’apprentissage automatique machine learning (ML)apprentissage automatique machine learningapprentissage automatique An approach to artificial intelligence in which a model is trained on data or experience so that its adjustable parameters come to reflect patterns relevant to a task.Approche de l'intelligence artificielle dans laquelle un modèle est entraîné sur des données ou sur l'expérience, de sorte que ses paramètres ajustables en viennent à refléter des régularités pertinentes pour une tâche. (see also the turn to machine learning page, in the Foundations of AI & NLP module) (voir aussi la page Le virage vers l'apprentissage automatique, dans le module Fondements de l'IA et du TAL).

L’étiquette la plus fréquente

Un étiqueteur construit par apprentissage automatique part d’un corpus corpuscorpus corporacorpus A collection of written texts, speech recordings or transcribed language assembled for analysis or use in language technology (plural: corpora).Ensemble de textes écrits, d'enregistrements de parole ou de langue transcrite réuni pour l'analyse ou pour les technologies langagières. que des personnes ont déjà étiqueté, et la chose la plus simple à y compter est la fréquence de chaque mot sous chaque étiquette. Livre est plus souvent un nom qu’un verbe, donc un étiqueteur qui étiquette toutes les occurrences de livre comme des noms aura raison la plupart du temps (Figure 6figure 6). Cet étiqueteur pose la question qui vient spontanément : parmi les occurrences de livre, quelle part sont des noms ? Un étiqueteur fondé sur ce seul compte pour chaque mot, l’étiquette la plus fréquente, a raison pour environ 92 % des mots d’un texte anglais, contre 97 % pour les meilleurs étiqueteurs et pour les personnes (Jurafsky & Martin, 2026 ; Figure 7figure 7). Entre une méthode qui ignore entièrement le contexte et les meilleurs étiqueteurs, l’écart est de cinq points. C’est pourquoi un score se lit par rapport à ce genre de méthode simple avant d’être jugé bon (see also the Baselines page, in the Evaluating language technology module) (voir aussi la page Les étalons, dans le module L'évaluation des technologies langagières).

Le segment un auteur qui livre ses pensées, chaque mot avec l'étiquette qu'il a le plus souvent dans le petit corpus de l'exemple détaillé et l'étiquette requise ici. un DET, juste ; auteur NOUN, juste ; qui PRON, juste ; livre NOUN, parce que le corpus l'a 5 fois comme nom et 2 fois comme verbe, alors qu'il faut VERB ici, faux ; ses DET, juste ; pensées NOUN, juste.
Figure 6. L'étiquette la plus fréquente sur un segment du petit corpus de l'exemple détaillé.
Une échelle de 0 à 100 %, dont la portion de 90 à 100 % est agrandie en dessous. Sur l'échelle agrandie, l'étalon atteint 92 %, les meilleurs systèmes et les personnes 97 %, et les 5 points qui les séparent sont marqués ; les 3 derniers points, de 97 à 100 %, sont au-delà de l'accord humain.
Figure 7. Étiquetage morphosyntaxique de l'anglais : la proportion de mots étiquetés correctement par l'étalon, par les meilleurs systèmes et par des personnes, avec le haut de l'échelle agrandi (Jurafsky & Martin, 2026).

Regarder le mot précédent

Le défi est donc de passer de 92 % au plus près de 97 %. Les erreurs qui restent avec l’approche naïve, toujours prendre l’étiquette la plus fréquente d’un mot, viennent surtout des mots ambigus qui ont plus d’une étiquette possible, comme livre, qui peut être un verbe ou un nom (Figure 6figure 6). Pour lever l’ambiguïté d’un tel mot, un étiqueteur regarde son contexte, et une première étape consiste à regarder non seulement le mot à étiqueter, mais aussi le mot qui le précède. Un bigramme est une suite de deux mots consécutifs, ou ici de deux étiquettes consécutives, et un étiqueteur bigramme ajoute un second compte au premier : la fréquence de chaque étiquette après l’étiquette du mot précédent (Jurafsky & Martin, 2026). Le bigramme est un cas d’une notion générale, le n-gramme, une suite de n éléments consécutifs : un étiqueteur trigramme, par exemple, regarde les étiquettes des deux mots précédents.

Le segment un auteur qui livre ses pensées, avec une case d'étiquette au-dessus de chaque mot : DET, NOUN, PRON, un point d'interrogation au-dessus de livre, et des cases vides au-dessus de ses et pensées. Une flèche de la case PRON vers le point d'interrogation demande, parmi les mots qui suivent PRON, quelle part sont des noms et quelle part des verbes. Une flèche du mot livre vers le point d'interrogation demande, parmi les noms, quelle part sont livre, et parmi les verbes.
Figure 8. Les deux questions que pose un étiqueteur bigramme pour étiqueter livre dans un auteur qui livre ses pensées.

L’étiqueteur répond aux deux questions de Figure 8figure 8 par deux probabilités, toutes deux comptées dans le corpus étiqueté, et donne au mot l’étiquette pour laquelle les deux ensemble obtiennent le meilleur score.

Lire une probabilité comme P(livre | VERB)

Une probabilité est une proportion : un nombre entre 0 et 1 qui dit combien de fois quelque chose se produit dans un ensemble de cas. 0 veut dire jamais, 1 toujours, et 0,25 une fois sur quatre, soit 25 %.

La notation P(A | B) se lit « la probabilité de A sachant B ». La barre veut dire sachant, et ce qui la suit dit parmi quels cas on compte. La Figure 9figure 9 lit P(livre | VERB) morceau par morceau, et le tableau ci-dessous lit les deux probabilités qu’utilise un étiqueteur bigramme.

P(livre | VERB) en grands caractères, chaque partie reliée à sa lecture : P est la probabilité, livre est qu'un mot soit livre, la barre est sachant, VERB est qu'il est un verbe.
Figure 9. Lire P(livre | VERB).
NotationSe litSe compte
P(livre | VERB)la probabilité qu’un mot soit livre, sachant que c’est un verbeparmi tous les verbes du corpus, la proportion qui sont livre
P(VERB | PRON)la probabilité qu’une étiquette soit VERB, sachant que l’étiquette précédente est PRONparmi tous les mots qui suivent un pronom, la proportion de verbes
Les deux probabilités d'un étiqueteur bigramme, lues à voix haute et comptées.

Les deux probabilités sont de simples proportions, et vous pouvez les calculer à la main.

Un exemple détaillé, étape par étape

Le segment est un auteur qui livre ses pensées, et les comptes viennent d’un petit corpus de huit courtes phrases françaises, étiquetées à la main, où livre apparaît sept fois au singulier (le pluriel livres est une autre forme), cinq fois comme nom et deux fois comme verbe. La Figure 10figure 10 se construit au fil des quatre étapes ci-dessous.

Marie/PROPN adore/VERB lire/VERB des/DET livres/NOUN ./PUNCT
Hier/ADV ,/PUNCT elle/PRON a/AUX trouvé/VERB un/DET livre/NOUN ancien/ADJ dans/ADP la/DET bibliothèque/NOUN ./PUNCT
Ce/DET livre/NOUN raconte/VERB l'/DET histoire/NOUN d'/ADP un/DET auteur/NOUN qui/PRON livre/VERB ses/DET pensées/NOUN avec/ADP passion/NOUN ./PUNCT
Intriguée/ADJ ,/PUNCT Marie/PROPN se/PRON livre/VERB alors/ADV à/ADP une/DET lecture/NOUN attentive/ADJ ./PUNCT
À/ADP la/DET fin/NOUN ,/PUNCT elle/PRON trouve/VERB que/SCONJ ce/DET livre/NOUN est/AUX un/DET chef-d'œuvre/NOUN ./PUNCT
Elle/PRON décide/VERB de/ADP recommander/VERB ce/DET livre/NOUN à/ADP ses/DET amis/NOUN ,/PUNCT espérant/VERB qu'/SCONJ ils/PRON l'/PRON apprécieront/VERB autant/ADV que/SCONJ elle/PRON ./PUNCT
Le/DET lendemain/NOUN ,/PUNCT Marie/PROPN commence/VERB un/DET nouveau/ADJ livre/NOUN ,/PUNCT car/CCONJ elle/PRON ne/ADV peut/VERB pas/ADV s'/PRON arrêter/VERB de/ADP lire/VERB ./PUNCT
Ce/PRON peut/VERB surprendre/VERB certains/PRON ,/PUNCT mais/CCONJ ce/PRON est/AUX vrai/ADJ ./PUNCT

Click the drawing, or a line below, to build it up stage by stage. Cliquez sur le dessin, ou sur une ligne ci-dessous, pour le construire étape par étape.

Figure 10. L'exemple détaillé pour livre dans un auteur qui livre ses pensées, une phase par étape.

Étape 1 : les étiquettes candidates

Le mot livre avec deux flèches, l'une vers NOUN suivi d'un point d'interrogation, l'autre vers VERB suivi d'un point d'interrogation.
Figure 11. Étape 1 de l'exemple détaillé.

Un étiqueteur n’invente pas d’étiquette : il compare les étiquettes qu’un mot peut avoir. Le corpus en montre deux pour livre, NOUN et VERB, donc l’étiqueteur calcule un score pour chacune, et le plus haut l’emporte (Figure 11figure 11).

Étape 2 : le mot, sachant chaque étiquette

Une rangée de 16 carrés pour les noms du corpus, dont 5 colorés pour livre : 0,313. Une rangée de 17 carrés pour les verbes, dont 2 colorés pour livre : 0,118.
Figure 12. Étape 2 de l'exemple détaillé.

La première question compte, parmi les mots qui portent chaque étiquette, la part qui sont livre : parmi les noms d’abord, puis parmi les verbes, et non parmi les occurrences de livre (Figure 12figure 12).

  • 5 des 16 noms sont livre : 0,313, qui s’écrit P(livre | NOUN) ;
  • 2 des 17 verbes sont livre : 0,118, qui s’écrit P(livre | VERB).

Sur cette seule question, NOUN est en tête. C’est encore l’étiquette la plus fréquente, et elle est fausse ici : le mot seul ne permet pas de distinguer ce livre du nom.

Étape 3 : chaque étiquette, sachant l’étiquette précédente

Une rangée de 13 carrés pour les mots qui suivent un pronom dans le corpus, dont 7 colorés pour les verbes. Aucun nom : 0. Sept verbes : 0,538.
Figure 13. Étape 3 de l'exemple détaillé.

La seconde question porte sur ce qui vient d’habitude après l’étiquette précédente, l’information que l’étiquette la plus fréquente n’utilisait jamais. Le mot avant livre est qui, un pronom, et le corpus compte 13 mots après un pronom (Figure 13figure 13).

  • aucun n’est un nom : 0, qui s’écrit P(NOUN | PRON) ;
  • 7 sont des verbes : 0,538, qui s’écrit P(VERB | PRON).

Étape 4 : combiner les deux

Deux rangées. NOUN : 0,313 fois 0 égale 0. VERB : 0,118 fois 0,538 égale 0,063, marqué comme gagnant.
Figure 14. Étape 4 de l'exemple détaillé.

L’étiqueteur a besoin d’un score par étiquette qui tienne compte des deux réponses, et il les multiplie (Figure 14figure 14). Un produit n’est élevé que si les deux nombres le sont, et un zéro dans l’un des deux annule le produit entier : NOUN obtient 0,313 × 0 = 0, et VERB 0,118 × 0,538 = 0,063.

VERB l’emporte. L’étiquette précédente a renversé l’avance que NOUN avait sur le mot seul, et l’étiqueteur étiquette ce livre comme un verbe, alors que livre est le plus souvent un nom.

Un compte nul a décidé ce cas, et dans un corpus d’une centaine de mots, cela arrive tout le temps : une séquence absente du corpus devient impossible, alors qu’elle n’est que rare. Les vrais étiqueteurs corrigent ce problème en donnant à chaque compte un petit minimum, de sorte qu’une séquence jamais vue dans le corpus soit improbable plutôt qu’impossible (Jurafsky & Martin, 2026).

La méthode comme règle

Pour chaque mot d’un texte, un étiqueteur bigramme fait les trois mêmes choses avec des comptes tirés d’un corpus étiqueté :

  1. il fait la liste des étiquettes que le mot peut avoir ;
  2. pour chaque étiquette, il multiplie la part du mot parmi les mots qui portent cette étiquette, P(mot | étiquette), par la part de cette étiquette parmi les mots qui suivent l’étiquette précédente, P(étiquette | étiquette précédente) ;
  3. il garde l’étiquette dont le produit est le plus grand.

Aucune règle ne dit nulle part que livre après qui est un verbe, et la méthode n’utilise jamais ce que livre veut dire : seuls les comptes décident.

L’exercise 1 "the word given the tag, for the noun"exercice 1 « le mot sachant l'étiquette, pour le nom » et les exercices qui le suivent appliquent les quatre mêmes étapes à un autre mot, montre, dans un bracelet de montre, puis à il attend, montre en main, où la règle donne la mauvaise réponse.

Written in English. The French version was automatically generated and I have not revised it. Rédigé en anglais. La version française a été générée automatiquement et je ne l'ai pas révisée. Mise à jour 7 octobre 2026

Sources

  • Jurafsky, D., & Martin, J. H. (2026). Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition with Language Models. Online draft, 3rd edition. https://web.stanford.edu/~jurafsky/slp3/

Sources

  • Jurafsky, D., & Martin, J. H. (2026). Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition with Language Models. Online draft, 3rd edition. https://web.stanford.edu/~jurafsky/slp3/

Spotted an error? Une erreur ?

Language, content, a broken link: e-mail me what you saw and I will fix it. Langue, contenu, lien brisé : écrivez-moi ce que vous avez vu et je corrige.

ayla.rigouts.terryn@umontreal.ca

Please mention the page: Mentionnez la page :