Ch 7 · Now You Try! · AI & LLM Literacy

Topic 7 of 7 in AI & LLMs — How They Actually Work — 3 lessons.

Your Turn at the Controls

You now know the real machinery: LLMs predict the next token, your tutor wraps your lesson + code + question into a prompt, the context window limits what it sees, it can hallucinate, and similarity is measured with vectors. Time to play with it yourself.

Project: A Tiny Text Generator

Time to build the heart of a language model in miniature. The program reads a short piece of text and counts, for every word, which words followed it. To generate, it starts with one word, looks up the most common follower, adds it to the sentence and repeats. Run it and look closely at the output: after "like" the word "milk" wins because it appeared twice, and before long the sentence goes round in a circle. Always picking the top choice is predictable, so the same start word always gives the same result. Many real models add a controlled amount of randomness when they choose, which is one reason the same question can get different replies.

Project: Fit a Chat Into the Window

A model can only read a limited number of tokens at once, so a chat program has to choose which messages fit. This project uses a simple rule: start from the newest message, keep adding older ones while there is room in the token budget, and stop as soon as the next one would not fit. Run it with a budget of 20 tokens. The two newest messages cost 13 tokens together, but adding the one before them would take the total to 22, so the greeting and the first reply are left out. The model would never see that the chat was about loops. Our tokenizer is a toy that counts words and punctuation; real tokenizers split words into smaller pieces, so their counts differ.

All topics in AI & LLM Literacy Beginner

  1. What Is an AI Language Model?
  2. Tokens — How AI Reads Text
  3. How the CodeArc AI Tutor Works
  4. What Is a Prompt?
  5. Why AI Gets Things Wrong
  6. Similarity — How AI Finds "Related" Things
  7. Now You Try!