Subsection 2.1 From Embeddings to Language Models
An embedding of a word is a useful way to represent the semantics of a word as a series of numbers. But on its own, it does not allow us to answer questions like “what word should come next in this sentence?” or “how would I translate ‘I am a student’ to French?”. To handle tasks like that, we need a language model.
Given some existing text, a language model generates new text by selecting the most likely next word based on the context. This new word then becomes part of the context for making further predictions.

Simple language models often are based on n-grams, or frequency counts of short word sequences. If we have analyzed the frequency of word combinations in a large set of texts (a corpus), we know not just how often “thou” and “shalt” each appear, but also how often they are followed by any other given word. Using these frequencies, the model can predict the next word.
These n-gram models have many limitations. In particular, they cannot generalize to word combinations that were not seen in the training data. Say the model was trained using a corpus that did not include the phrase “the cat sat on the mat”. Even if it had seen many similar phrases, like “the dog sat on the mat”, it would not consider “sat” as a possible next word given “the cat”.
Early neural language models instead looked up embeddings for a fixed number of preceding words, combined them, and predicted the next word. By using embeddings rather than the words directly, these models can produce novel outputs that are not simply a rehash of the training data.

A recurrent neural network model extends this approach by maintaining a value representing a summary of earlier words from one step to the next. A recurrent model would thus know not just that the current context includes “thou shalt”, but also have some representation of the words that came before those. This representation of earlier context is called a hidden state. The hidden state does not contain the earlier words themselves, but instead it summarizes them in an abstract way similar to an embedding.
These language models in theory allow for much handling of long-range dependencies. However, training these models to track long-term dependencies can be challenging and expensive. Because recurrent neural networks need to maintain and update their hidden states at each time step, they necessarily must operate one word at a time. Processing on word \(t + 1\) can’t begin until processing on word \(t\) is complete. This sequential processing makes it difficult to parallelize training by running multiple steps simultaneously.
The boom in modern language models began with the introduction of transformer models that overcome some of the limitations of recurrent models.