Representing language / 4 of 7
Language modeling
What you’ll learn
- Explain the main idea of “Language modeling” in your own words.
- Trace a concrete example and identify the assumptions behind it.
- Apply the principle in a practice problem and recognize a common failure.
The idea, intuitively
A language model assigns probabilities to sequences. Autoregressive models predict the next token from earlier tokens; masked models reconstruct hidden tokens from surrounding context. Their training objectives shape how they are used.
Language varies by speaker, setting, and purpose. A text representation is useful only in relation to a task. Keep the original source when possible so you can inspect what preprocessing discarded. English performance does not establish Indonesian performance, especially for slang, dialect, or mixed-language inputs.
Under the hood
Cross-entropy penalizes low probability assigned to the observed target token. Perplexity exponentiates average negative log-likelihood, but values are only comparable under compatible tokenization and evaluation data.
Lower perplexity does not guarantee better task-specific reasoning or safety.
A worked example
After “The sky is”, a model may assign probabilities to “blue”, “clear”, and other continuations rather than returning one certain fact.
How to use this way of thinking
Trace text through normalization, tokenization, representation, and prediction. Include language variation in evaluation and inspect examples that share words but differ in meaning. For generated language, assess faithfulness and task success separately from grammatical fluency.
Try it yourself
If the correct token has probability 0.5, compute its negative natural log loss.
Key takeaways
- Higher assigned probability
- Lower perplexity does not guarantee better task-specific reasoning or safety.
- Check the assumptions with a small example before applying this idea to a larger system.
Check your understanding
Use feedback to learn. Quiz scores and lesson completion are tracked separately.
Go to lesson completionFurther reading
Original papers and reference material for this school. External resources may be in English and require internet access.
Hugging Face NLP course (opens a new tab)Attention Is All You Need (opens a new tab)Finish this lesson
Mark this lesson complete when you’re ready to continue.