This is an official ODERSA website. Here’s how you know

The official domain

The address of this site ends in odersa.org. Every service the association runs sits on a subdomain of odersa.org and nowhere else. If the address in your browser’s address bar does not end in odersa.org, this site is not ours.

Free, and no account

Everything is open straight away. No sign-up, no account, no password, no subscription, no advertising. Nothing is held back for those who pay, because there is nothing to pay for.

No data collected

This site does not follow you: no tracker, no tracking cookie, no measurement tool built into these pages, and nothing measured on your device. Our host counts requests in aggregate, as any server that answers does: a total, never a profile. You do not have to take our word for it: open your browser’s developer tools, go to the Network tab, and reload the page. You will see the full list of what the site asks for. Everything comes from odersa.org, nothing goes anywhere else.

Free to reuse

The content is published under the CC BY 4.0 licence. You may copy it, translate it, print it and pass it on, for your classes as much as for the people around you, on one condition only: credit ODERSA.

Words in pieces

A model never receives a letter, nor a whole word: it receives pieces, learnt by statistics on a corpus. This chapter makes the algorithm learn before your eyes, then applies the result to one and the same sentence in several languages.

Information

Everything is calculated in your browser, from a text embedded in the page. The corpus, the learning of the merges and the cutting up of a sentence all stay on this device. Open your browser’s Network tab while you use the tool: no request goes out.

The learning corpus

The algorithm in this chapter learns on one text, and nothing else. Here it is, in full: the first fifteen paragraphs of the novel Around the World in Eighty Days, in the original French. No other sentence is used for the learning below: what you read here is exactly what the cutting up was learnt on.

This corpus runs to fifteen paragraphs.

En l’année 1872, la maison portant le numéro 7 de Saville-row, Burlington Gardens maison dans laquelle Sheridan mourut en 1814, était habitée par Phileas Fogg, esq., l’un des membres les plus singuliers et les plus remarqués du Reform-Club de Londres, bien qu’il semblât prendre à tâche de ne rien faire qui pût attirer l’attention.

À l’un des plus grands orateurs qui honorent l’Angleterre, succédait donc ce Phileas Fogg, personnage énigmatique, dont on ne savait rien, sinon que c’était un fort galant homme et l’un des plus beaux gentlemen de la haute société anglaise.

On disait qu’il ressemblait à Byron par la tête, car il était irréprochable quant aux pieds, mais un Byron à moustaches et à favoris, un Byron impassible, qui aurait vécu mille ans sans vieillir.

Anglais, à coup sûr, Phileas Fogg n’était peut-être pas Londonner. On ne l’avait jamais vu ni à la Bourse, ni à la Banque, ni dans aucun des comptoirs de la Cité. Ni les bassins ni les docks de Londres n’avaient jamais reçu un navire ayant pour armateur Phileas Fogg. Ce gentleman ne figurait dans aucun comité d’administration. Son nom n’avait jamais retenti dans un collège d’avocats, ni au Temple, ni à Lincoln’s-inn, ni à Gray’s-inn. Jamais il ne plaida ni à la Cour du chancelier, ni au Banc de la Reine, ni à l’Échiquier, ni en Cour ecclésiastique. Il n’était ni industriel, ni négociant, ni marchand, ni agriculteur. Il ne faisait partie ni de l’Institution royale de la Grande-Bretagne, ni de l’Institution de Londres, ni de l’Institution des Artisans, ni de l’Institution Russell, ni de l’Institution littéraire de l’Ouest, ni de l’Institution du Droit, ni de cette Institution des Arts et des Sciences réunis, qui est placée sous le patronage direct de Sa Gracieuse Majesté. Il n’appartenait enfin à aucune des nombreuses sociétés qui pullulent dans la capitale de l’Angleterre, depuis la Société de l’Armonica jusqu’à la Société entomologique, fondée principalement dans le but de détruire les insectes nuisibles.

Phileas Fogg était membre du Reform-Club, et voilà tout.

À qui s’étonnerait de ce qu’un gentleman aussi mystérieux comptât parmi les membres de cette honorable association, on répondra qu’il passa sur la recommandation de MM. Baring frères, chez lesquels il avait un crédit ouvert. De là une certaine surface, due à ce que ses chèques étaient régulièrement payés à vue par le débit de son compte courant invariablement créditeur.

Ce Phileas Fogg était-il riche ? Incontestablement. Mais comment il avait fait fortune, c’est ce que les mieux informés ne pouvaient dire, et Mr. Fogg était le dernier auquel il convînt de s’adresser pour l’apprendre. En tout cas, il n’était prodigue de rien, mais non avare, car partout où il manquait un appoint pour une chose noble, utile ou généreuse, il l’apportait silencieusement et même anonymement.

En somme, rien de moins communicatif que ce gentleman. Il parlait aussi peu que possible, et semblait d’autant plus mystérieux qu’il était silencieux. Cependant sa vie était à jour, mais ce qu’il faisait était si mathématiquement toujours la même chose, que l’imagination, mécontente, cherchait au-delà.

Avait-il voyagé ? C’était probable, car personne ne possédait mieux que lui la carte du monde. Il n’était endroit si reculé dont il ne parût avoir une connaissance spéciale. Quelquefois, mais en peu de mots, brefs et clairs, il redressait les mille propos qui circulaient dans le club au sujet des voyageurs perdus ou égarés ; il indiquait les vraies probabilités, et ses paroles s’étaient trouvées souvent comme inspirées par une seconde vue, tant l’événement finissait toujours par les justifier. C’était un homme qui avait dû voyager partout, en esprit, tout au moins.

Ce qui était certain toutefois, c’est que, depuis de longues années, Phileas Fogg n’avait pas quitté Londres. Ceux qui avaient l’honneur de le connaître un peu plus que les autres attestaient que si ce n’est sur ce chemin direct qu’il parcourait chaque jour pour venir de sa maison au club personne ne pouvait prétendre l’avoir jamais vu ailleurs. Son seul passe-temps était de lire les journaux et de jouer au whist. À ce jeu du silence, si bien approprié à sa nature, il gagnait souvent, mais ses gains n’entraient jamais dans sa bourse et figuraient pour une somme importante à son budget de charité. D’ailleurs, il faut le remarquer, Mr. Fogg jouait évidemment pour jouer, non pour gagner. Le jeu était pour lui un combat, une lutte contre une difficulté, mais une lutte sans mouvement, sans déplacement, sans fatigue, et cela allait à son caractère.

On ne connaissait à Phileas Fogg ni femme ni enfants, ce qui peut arriver aux gens les plus honnêtes, ni parents ni amis, ce qui est plus rare en vérité. Phileas Fogg vivait seul dans sa maison de Saville-row, où personne ne pénétrait. De son intérieur, jamais il n’était question. Un seul domestique suffisait à le servir. Déjeunant, dînant au club à des heures chronométriquement déterminées, dans la même salle, à la même table, ne traitant point ses collègues, n’invitant aucun étranger, il ne rentrait chez lui que pour se coucher, à minuit précis, sans jamais user de ces chambres confortables que le Reform-Club tient à la disposition des membres du cercle. Sur vingt-quatre heures, il en passait dix à son domicile, soit qu’il dormît, soit qu’il s’occupât de sa toilette. S’il se promenait, c’était invariablement, d’un pas égal, dans la salle d’entrée parquetée en marqueterie, ou sur la galerie circulaire, au-dessus de laquelle s’arrondit un dôme à vitraux bleus, que supportent vingt colonnes ioniques en porphyre rouge. S’il dînait ou déjeunait, c’étaient les cuisines, le garde-manger, l’office, la poissonnerie, la laiterie du club, qui fournissaient à sa table leurs succulentes réserves ; c’étaient les domestiques du club, graves personnages en habit noir, chaussés de souliers à semelles de molleton, qui le servaient dans une porcelaine spéciale et sur un admirable linge en toile de Saxe ; c’étaient les cristaux à moule perdu du club qui contenaient son sherry, son porto ou son claret mélangé de cannelle, de capillaire et de cinnamome ; c’était enfin la glace du club glace venue à grands frais des lacs d’Amérique qui entretenait ses boissons dans un satisfaisant état de fraîcheur.

Si vivre dans ces conditions, c’est être un excentrique, il faut convenir que l’excentricité a du bon !

La maison de Saville-row, sans être somptueuse, se recommandait par un extrême confort. D’ailleurs, avec les habitudes invariables du locataire, le service s’y réduisait à peu. Toutefois, Phileas Fogg exigeait de son unique domestique une ponctualité, une régularité extraordinaires. Ce jour-là même, 2 octobre, Phileas Fogg avait donné son congé à James Forster ce garçon s’étant rendu coupable de lui avoir apporté pour sa barbe de l’eau à quatre-vingt-quatre degrés Fahrenheit au lieu de quatre-vingt-six, et il attendait son successeur, qui devait se présenter entre onze heures et onze heures et demie.

Phileas Fogg, carrément assis dans son fauteuil, les deux pieds rapprochés comme ceux d’un soldat à la parade, les mains appuyées sur les genoux, le corps droit, la tête haute, regardait marcher l’aiguille de la pendule, appareil compliqué qui indiquait les heures, les minutes, les secondes, les jours, les quantièmes et l’année. À onze heures et demie sonnant, Mr. Fogg devait, suivant sa quotidienne habitude, quitter la maison et se rendre au Reform-Club.

Text: Jules Verne, Le Tour du monde en quatre-vingts jours, 1873, public domain. The transcription has been edited for reading: apostrophes made typographic, dashes and quotation marks of the transcription removed, italic marks removed, chapter titles and table of contents set aside, paragraphs of fewer than forty characters set aside.

The merges, in the order the algorithm learns them

Every merge is a choice: the most frequent pair of symbols in the corpus above becomes a new symbol. Choose how many merges the algorithm is allowed to make, and watch the table fill up, one line per merge, in the order it was learnt.

60
At zero, no merge at all: every character stays on its own. The maximum on this slider is set at three hundred; a real model learns several tens of thousands.

The table of merges appears here, in the order the algorithm learns them.

Cutting up a sentence

Here is what those merges do to a new sentence: they apply in the order they were learnt, the oldest first, until none applies any more.

The cutting up is recalculated with the number of merges chosen above. The example is in French, like the corpus; any sentence can be typed in its place.

The cutting up of your sentence appears here, in units.

The same sentence, 7 languages

Here is the point this chapter holds on to. The same cutter, set to the number of merges chosen above and learnt on French alone, now segments a sentence of identical meaning in 7 languages. The number of units it produces varies enormously from one language to another, and that gap has one single cause: this cutter has never read anything but French.

The comparison between languages appears here, one bar per language.

Source sentence: the ODERSA trust banner, the canonical text of the house, published under the CC BY 4.0 licence. This cutter is a toy learnt on a text from eighteen seventy-three: its unit counts are not those of a product, but the mechanism that produces them is the same.

The method

The algorithm is called BPE, for Byte Pair Encoding. It was designed in 1994 as a general method of data compression, with no connection to natural language (Gage, 1994). It was applied in 2016 to the cutting of text into sub-words, to let a machine translation model handle rare or unknown words by breaking them down into smaller units already known (Sennrich, Haddow and Birch, 2016). It is that second version, applied to text, that the demonstration above has just run before your eyes.

  1. Start from the characters. Every word of the corpus becomes the string of its characters, one symbol per character. The word « enseignant » starts out as ten symbols: e, n, s, e, i, g, n, a, n, t.
  2. Count every pair of neighbouring symbols. For each word of the corpus, for each pair of symbols that touch, add up its number of occurrences, multiplied by the number of times that word appears in the corpus.
  3. Keep the most frequent pair. When counts are equal, the rule always keeps the one met first when reading the corpus from left to right, word after word: two people counting by hand land on the same pair.
  4. Merge that pair into a new symbol, everywhere it appears in the corpus. The vocabulary gains one symbol.
  5. Repeat steps two to four as many times as there are merges wanted. Every merge builds on the state left by the previous one: a rank is never recalculated without having gone through the one before.
  6. Stop. Either at the number of merges fixed in advance, or when no pair repeats any more: every word of the corpus has then become a single symbol.
  7. Cut up a new text with the merges learnt. You start again from its characters, and apply the merges in the order they were learnt, the oldest first, as long as a pair from the list is still there. A word that shares no character with the learning corpus meets no merge at all: it stays broken down into characters, one by one.

A whole example, by hand, on a corpus of two words: « enseignant », counted four times, and « grand », counted three times. The pair a followed by n comes up seven times in all, four times in « enseignant » and three times in « grand »: no other pair reaches that count, so it merges first. All the following merges are then tied at four occurrences: the rule keeps the first one met when reading « enseignant » from left to right.

The first six merges of the example « enseignant », « grand »
RankPair mergedSymbol obtainedOccurrences
1a + nan7
2e + nen4
3en + sens4
4ens + eense4
5ense + iensei4
6ensei + genseig4

After those six merges, « enseignant » is written enseig, n, an, t and « grand » is written g, r, an, d: four symbols each, and one shared symbol, an, learnt thanks to both words at once. That is exactly the mechanism the table in the previous section applies to the whole novel.

A unit is not a word

A unit, or token, is a symbol kept by the merges: sometimes a whole word, sometimes a fragment, sometimes a single character. Nothing in the algorithm knows the syllable, the root or the ending of a word: all that counts is the frequency of the pairs in the learning corpus.

The table above shows it at a later rank: the name “Fogg” becomes a single symbol, simply because it comes up very often in these fifteen paragraphs. Another corpus, without that character, would never have learnt that symbol. The vocabulary of a model is therefore not a list of words chosen for their meaning: it is the statistical imprint of the text it was built on.

Why a model never sees a letter

Once the cutting up is done, the text exists for the model only in the form of those units, converted into numbers. The model calculates on those numbers: it has no operation that says the third letter of this unit, because the unit is not kept as a string of letters once it has become a symbol.

When a unit matches a single character, access to the letter exists by accident. As soon as a unit groups several characters together, as the cutting up of the word « lettres » above shows, that access disappears: the model reasons on the whole symbol, never on its letters one by one.

What this mechanism explains badly

Three very ordinary tasks call for direct access to the letter. Cutting text into units makes them, by construction, unreliable.

Counting the letters of a word
If the whole word fits into a single unit, or if a unit groups several identical letters together, counting amounts to counting units that match no particular letter. The answer may come out right, by accident as much as by calculation.
Judging whether two words rhyme
A rhyme is judged on the last sounds, and so on the last letters. If the boundary of a unit falls somewhere other than on that end of the word, what ought to be compared letter by letter is compared between units that do not overlap.
Writing a word backwards, letter by letter
Reversing a word means having each of its letters, in order. A model that receives the word already grouped into two or three units first has to rebuild letters it has never handled separately.

The cost by language

The comparison above shows it live: a cutter learnt on one corpus produces few units for a text close to that corpus, and many more for a text far from it. A published measurement establishes that same gap on real production cutters: the same content, translated into different languages, can require up to fifteen times more tokens depending on the language, which makes some languages structurally more expensive and slower to process (Petrov, La Malfa, Torr and Bibi, 2023).

The AI Manual serves this course in 7 languages. That gap is therefore no curiosity: a page that costs few tokens in one language can cost many more in a language with a different script, which weighs on the speed of the answer and on the share of context left available for the rest of the conversation.

Going further

Once the text is in units, the model predicts the next unit: that mechanism is the subject of the chapter the next word. Other mechanisms can be handled the same way on the demonstrations page. The full contents of the course are on the understand page.

Sources