Chammarychammary

The spelled-out intro to language modeling: building makemore

Andrej Karpathy · 1:57:45 · 3 years ago

Building a character-level language model can be achieved by either direct statistical counting or neural network optimization, with both methods yielding identical probabilistic results.

  • Bigram counting — raw occurrences of character pairs are tallied into a 2D torch tensor and normalized to create probability distributions for the next character .

  • Model generation — sampling new names involves using torch.multinomial to randomly select the next character based on the learned probability values .

  • Assessing quality — the model is evaluated using negative log likelihood, where lower values indicate that the model is successfully assigning high probabilities to the correct next character .

  • Neural adaptation — a single linear layer transforms one-hot encoded inputs into log counts, which are then processed via a softmax function to output valid probabilities .

  • Optimization — gradient-based learning improves the model by iteratively adjusting parameters to minimize the negative log likelihood loss .

  • Weight regularization — incentivizing weights to remain near zero acts as a form of smoothing, which prevents the model from becoming overconfident .

  • How do you expand this model to predict more than one character ahead?

  • What is the relationship between raw counts and probability distributions in this context?