ArticleslgStudy

mathematics

Word n-gram language model

Word n-gram language model is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Word n-gram language model rather than just read about it. In short: A word n-gram language model is a statistical model of language which calculates the probability of the next word in a sequence from a fixed size window of previous words. If one previous word is considered, it is a bigram model; if two words, a trigram model; if n − 1 words, an n-gram model.

Word n-gram language model — main illustration
Word n-gram language model — illustration

Key takeaways

  • Word n-gram language model belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Word n-gram language model to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Word n-gram language model from memory before moving on to harder problems.

Reference excerpt

A word n-gram language model is a statistical model of language which calculates the probability of the next word in a sequence from a fixed size window of previous words. If one previous word is considered, it is a bigram model; if two words, a trigram model; if n − 1 words, an n-gram model. Special tokens are introduced to denote the start and end of a sentence ⟨ s ⟩ {\displaystyle \langle s\rangle } and ⟨ / s ⟩ {\displaystyle \langle /s\rangle } . To prevent a zero probability being assigned to unseen words, the probability of each seen word is slightly lowered to make room for the unseen words in a given corpus. To achieve this, various smoothing methods are used, from simple "add-one" smoothing (assigning a count of 1 to unseen n-grams, as an uninformative prior) to more sophisticated techniques, such as Good–Turing discounting or back-off models. Word n-gram models have largely been superseded by recurrent neural network–based models, which in turn have been superseded by Transformer-based models often referred to as large language models.

Unigram model

A special case, where n = 1, is called a unigram model. Probability of each word in a sequence is independent from probabilities of other word in the sequence. Each word's probability in the sequence is equal to the word's probability in an entire document.

P uni ( t 1 t 2 t 3 ) = P ( t 1 ) P ( t 2 ) P ( t 3 ) . {\displaystyle P_{\text{uni}}(t_{1}t_{2}t_{3})=P(t_{1})P(t_{2})P(t_{3}).}

The model consists of units, each treated as one-state finite automata. Words with their probabilities in a document can be illustrated as follows.

Total mass of word probabilities distributed across the document's vocabulary, is 1.

∑ word in doc P ( word ) = 1 {\displaystyle \sum _{\text{word in doc}}P({\text{word}})=1}

The probability generated for a specific query is calculated as

P ( query ) = ∏ word in query P ( word ) {\displaystyle P({\text{query}})=\prod _{\text{word in query}}P({\text{word}})}

Unigram models of different documents have different probabilities of words in it. The probability distributions from different documents are used to generate hit probabilities for each query. Documents can be ranked for a query according to the probabilities. Example of unigram models of two documents:

Bigram model In a bigram word (n = 2) language model, the probability of the sentence I saw the red house is approximated as

P ( I, saw, the, red, house ) ≈ P ( I ∣ ⟨ s ⟩ ) P ( saw ∣ I ) P ( the ∣ saw ) P ( red ∣ the ) P ( house ∣ red ) P ( ⟨ / s ⟩ ∣ house ) {\displaystyle P({\text{I, saw, the, red, house}})\approx P({\text{I}}\mid \langle s\rangle )P({\text{saw}}\mid {\text{I}})P({\text{the}}\mid {\text{saw}})P({\text{red}}\mid {\text{the}})P({\text{house}}\mid {\text{red}})P(\langle /s\rangle \mid {\text{house}})}

Trigram model In a trigram (n = 3) language model, the approximation is

P ( I, saw, the, red, house ) ≈ P ( I ∣ ⟨ s ⟩ , ⟨ s ⟩ ) P ( saw ∣ ⟨ s ⟩ , I ) P ( the ∣ I, saw ) P ( red ∣ saw, the ) P ( house ∣ the, red ) P ( ⟨ / s ⟩ ∣ red, house ) {\displaystyle P({\text{I, saw, the, red, house}})\approx P({\text{I}}\mid \langle s\rangle ,\langle s\rangle )P({\text{saw}}\mid \langle s\rangle ,I)P({\text{the}}\mid {\text{I, saw}})P({\text{red}}\mid {\text{saw, the}})P({\text{house}}\mid {\text{the, red}})P(\langle /s\rangle \mid {\text{red, house}})}

Note that the context of the first n – 1 n-grams is filled with start-of-sentence markers, typically denoted <s>. Additionally, without an end-of-sentence marker, the probability of an ungrammatical sequence *I saw the would always be higher than that of the longer sentence I saw the red house.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Word n-gram language model

Start with the simplest possible case. Write down what Word n-gram language model claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Word n-gram language model before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Word n-gram language model ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Word n-gram language model

In research
Word n-gram language model appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Word n-gram language model in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Word n-gram language model is common in secondary-school and first-year university syllabi. It links to neighbouring topics Language modeling, Markov models, Statistical natural language processing, so understanding it makes those chapters shorter.
In everyday life
Look for Word n-gram language model outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Word n-gram language model” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Word n-gram language model in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Word n-gram language model means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Word n-gram language model out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Word n-gram language model in simple terms?

A word n-gram language model is a statistical model of language which calculates the probability of the next word in a sequence from a fixed size window of previous words. If one previous word is considered, it is a bigram model; if two words, a trigram model; if n − 1 words, an n-gram model.

Why does Word n-gram language model matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Word n-gram language model?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Word n-gram language model.

Tags

  • Language modeling
  • Markov models
  • Statistical natural language processing

Keep exploring