Language Model
Also Neural Language Model
A language model computes, for a sequence of previous tokens, a probability distribution over the vocabulary for the next token; it is count-based (n-gram model) or neural.
Properties#
Tokens. One text can be tokenized in different ways; a token may include spaces and punctuation. For “To be, or not to be”:
- words:
Tobeornottobe - subwords:
Tobe,ornottobe(modern language models) - characters:
Tobe,… (the lecture’s n-gram models)
Variants.
| Count-based (N-Gram Model) | Neural language model | |
|---|---|---|
| How is computed | normalized counts of token sequences in a training text | forward pass through a neural network |
| Context size | small ; n-grams make large infeasible | very large, up to tokens |
| Unseen contexts | no distribution; smoothing (random next token) | the network computes a distribution for every prompt |
A neural language model with a very large network is a large language model (LLM). All of these, including LLMs, are “the same kind of model”, only trained and computed differently.
- Long prompts: if the prompt has more than tokens, only the last are considered, or a subset of the text is selected via Retrieval-Augmented Generation.
- Generating text: repeatedly pick a next token from the distribution (e.g. via cumulative counts, N-Gram Model > Formula), append it to the prompt, repeat. LLM services return the next tokens at once.
- Base vs. instruct models, system prompt, temperature and the API: see Large Language Model.
Example#
Sources#
- Slides 12, p. 4 (tokens), Slides 12, p. 9 (limits of n-gram models), Slides 12, p. 10 (neural language models), Slides 12, p. 12 (context size, prompt)
- DBIS_VL12 > Tokens, DBIS_VL12 > Neural and large language models, DBIS_VL12 > Terminology
- Exam: DBIS Exam WS2324-2 (not published) Task 5.2 (simplistic next-word model as one linear layer over embeddings), Task 5.3 (top- sampling)