Neural language models
Overview
Mohit Iyyer introduces neural language models as trainable alternatives to n-gram models, which assign zero probability to unseen sequences and cannot naturally share information between related words. He explains the pipeline from token embeddings through a fixed-size prefix representation to vocabulary-wide logits and softmax probabilities, with the whole model trained by gradient descent to reduce negative log likelihood and generalize to test data.
Key takeaways
- N-gram models give unseen sequences zero probability unless smoothed, while neural language models learn parameters with gradient descent to reduce negative log likelihood.
- Generalization requires evaluating on held-out text: low training perplexity alone can indicate memorization rather than robust language modeling.
- Dense embeddings let a model share information across words that occur in similar contexts, unlike orthogonal one-hot vectors for “movie” and “film.”
- A neural language model maps input tokens through embeddings and a composition function to a fixed-size prefix vector, then projects it to vocabulary-wide logits.
- Softmax converts logits into nonnegative next-token probabilities that sum to one; training adjusts model parameters to increase the probability of the observed token.
- The input embedding matrix E and output matrix W may be tied or separate, and both can be learned through next-token prediction.
Chapters
- Project proposals are due in roughly three weeks, so groups should research ideas outside class and use office hours to test feasibility.
- Projects are not expected to invent new techniques or train large models from scratch; adapting existing open-weight models is a more realistic scope.
- Mohit Iyyer names paid Google Colab and Kaggle as common resources and says he will seek Tinker credits from Thinking Machines.
- A common project adapts models such as Qwen or Llama to a task through fine-tuning or reinforcement learning, then evaluates results and analyzes errors.
- Agent projects can use frontier or large open-weight models, including multi-agent systems and collaborating agent swarms.
- Comparative projects can evaluate fine-tuning, reinforcement learning, or agent-coordination methods on the same task; any project involving AI and text must engage with neural language models.
- The lecture shifts from n-gram models, which estimate next-word probabilities from phrase and prefix counts, to models trained through optimization.
- Negative log likelihood (NLL) sums the negative log probabilities assigned to the tokens in a sequence and can be normalized by token count.
- NLL is the training objective for neural language models: lower NLL means the model assigns higher probability to the observed text.
- A model with low training NLL but high test NLL is overfitting or memorizing rather than modeling patterns that generalize.
- Evaluation measures NLL on held-out test data that was not used to train the model.
- Perplexity is exponentiated NLL; it can be interpreted as the model's average number of effectively plausible next-token choices.
- N-gram models minimize training NLL by counting and dividing, but an unseen n-gram receives zero probability without smoothing.
- Smoothing methods distribute probability to unseen sequences, but the lecture notes that they lack a well-grounded way to estimate those probabilities.
- Neural language models also aim to minimize training NLL, but have no closed-form count-based solution and require gradient descent.
- The input tokens are converted into a sequence of learned, low-dimensional real-valued embeddings.
- A composition function, such as a recurrent neural network, transformer, or simple vector sum, combines the sequence into one prefix representation.
- An output layer turns the prefix representation into a probability distribution over the vocabulary for the next token.
- In an n-gram model, each vocabulary item can be represented by a one-hot vector with one active position and zeros elsewhere.
- The one-hot vectors for “movie” and “film” have a dot product of zero, just like “movie” and “zebra,” so they encode no semantic similarity.
- A useful embedding space should give words, phrases, and documents with similar meanings similar representations.
- Neural models replace sparse vocabulary-sized one-hot vectors with dense, real-valued vectors in a much smaller dimension.
- Iyyer illustrates three-dimensional vectors for “movie,” “film,” and “zebra” to show how similarity can be reflected in vector relationships.
- Embeddings are learned from next-word prediction rather than assigned fixed meanings; their values can differ across runs because training starts from random initialization.
- Words such as “movie” and “film” can acquire related representations because they appear in similar contexts, such as “I went to see a ___.”
- Training updates the same embeddings as the model sees more data, using loss and gradients rather than manually selecting new vector values.
- Pretrained embeddings can initialize a model, including embeddings learned by Word2Vec or extracted from an open-weight language model.
- The output must be a vocabulary-sized probability distribution: every value is nonnegative and all values sum to one.
- The prefix vector has a fixed dimension chosen as a model hyperparameter, independent of the input sequence length.
- The composition step creates that fixed-size vector; the lecture focuses next on how the output layer maps it to token probabilities.
- A learned weight matrix W projects a d-dimensional prefix vector into a vocabulary-sized vector.
- In Iyyer’s example, a 4-by-3 matrix multiplies a three-dimensional prefix vector to produce four scores for a four-token vocabulary.
- Each row of W corresponds to an output token, and its values determine how the prefix features contribute to that token’s score.
- An input embedding matrix E stores one word vector per vocabulary item; the model retrieves the rows for the input tokens before composition.
- The output matrix W acts like a set of output embeddings, and some language models tie it to the input embeddings while others keep the matrices separate.
- The product W x produces logits, unnormalized scores for each possible next token, rather than probabilities.
- Softmax exponentiates each logit and divides by the sum of exponentiated logits, producing positive values that sum to one.
- In the example “My favorite LLM is,” the model assigns most probability to Gemini instead of the observed target Claude, illustrating a prediction error.
- Training should adjust model parameters so that subsequent predictions assign more probability to the correct next token.
- Every embedding and weight-matrix value is a parameter; gradient-based training automatically updates parameters according to their contribution to the prediction error.
- Position information enters through the composition architecture or additional position embeddings, topics reserved for later classes.
- The next lecture will cover composition functions, backpropagation, gradient descent, and text generation; fine-tuning methods such as LoRA apply to adapting an already pretrained model.
Transcript excerpt
0:03 Okay, let's get started everyone. So, today we've got a lot of stuff to cover. Um first we'll talk um briefly about the final project and um very highlevel um categories of ideas that you might want to consider pursuing um based on what people did last year and what kind of resources you have available. Then we will get started with our multi- lecture unit on um neural language models. So today we will cover um like the overall modules in building a neural language model and start talking about um embeddings and um how to predict a word
0:53 given um the embeddings. Uh next class we will talk about uh forward propagation and we'll start talking about back propagation and actual like gradient descent training one of these models and then we will um increase the complexity of our architectures start talking about recurrent neural language models and transformers and uh beyond. So that's kind of where we're going. Um the class will start to uh pick up in pace after we start um this um kind of set of topics and um we'll kind of try and get to the state-ofthe-art as quickly as possible. Okay. So before we talk about all of
1:41 that, let's talk about um project topics. So many of you are wondering about this. Um we obviously want you to submit your project proposals um you know in uh three weeks or something like that. So you don't have that much time and um you're not going to have like learned a lot of stuff in this class before we ask you to propose a topic. So, we do expect that you will take the time uh outside of class to research yourself uh potential topics for the uh project. Um discuss it among
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Mohit Iyyer.