liveBook · Manning

Language model

As explained in Deep Learning with R, Third Edition

A large language model is a machine-learning model trained on large text corpora to understand and generate natural-language text.

How can a model generate text when the number of possible sentences is enormous? Classifying every complete sentence as a separate output is impractical: a vocabulary of 20,000 words already allows 160 quadrillion four-word sequences. section 15.1

A language model takes a more manageable approach: given the tokens seen so far, it predicts a probability distribution over the token that comes next. With a 20,000-word vocabulary, that means choosing among 20,000 possible next-token outputs, not every possible sentence. Repeating the prediction lets the model generate a longer sequence. section 15.1

Start with characters

A small language model can predict the next character from preceding characters. Repeating that step provides a way to generate Shakespeare-like text. section 15.1

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines the next-token probability distribution and explains the scale problem; introduces a character-level build without detailing its implementation here.
Examples
Uses a 20,000-word vocabulary calculation and a next-character model for Shakespeare-like text.
What you can do after
Build it from scratch as a small next-character model for generating Shakespeare-like text.
How it connects
Connects next-token prediction with probability distributions, sequence classification, and text generation.

Also explained in

Compare how 67 books explain language model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.