← CS50: Introduction to Computer Science

Week 6.5: Artificial Intelligence

A short detour into what CS50 now teaches about large language models: how they predict text, why they hallucinate, and how to use one honestly.

5 topics · 17 questions

Each topic is a path, not a menu: work down it in order and every question builds on the one above. Click any of them to watch the answer draw itself.

How LLMs Predict the Next Word

  1. How it worksHow does a large language model turn text into a probability distribution over the next likely word?
  2. Worked exampleWalk me through how the phrase 'the cat sat on the' pushes probability toward words like mat over words like sky.
  3. Common mistakeWhy isn't a language model looking anything up in a database when it answers a question?
Your turn1 of 2
A language model assigns probability 0.309 to the word 'mat' and probability 0.212 to the word 'sky' as its next word. What is the combined probability of the model producing one of those two words?

Prompting an AI Effectively

  1. Worked exampleWalk me through rewriting the vague prompt fix my code into a specific prompt naming the language, error, and goal.
  2. Common mistakeWhy isn't a longer, more detailed prompt always a better prompt?
  3. Going furtherWhat happens to an AI's answer quality when you give it a worked example of the exact format you want back?
Your turn1 of 2
A prompt is rewritten to include 5 additional specific details (the language, the exact error, the goal) in place of 2 vague, unhelpful ones that got removed. How many more specific details does the revised prompt have than the original?

Why AI Hallucinates

  1. How it worksHow does a model trained to always produce the most probable next word end up generating plausible-sounding fiction?
  2. Common mistakeWhy isn't a hallucinating model just 'lying' the way a person who knows the truth would be?
  3. Worked exampleWalk me through why a model asked for a source it never saw during training still generates one that looks real.
  4. Going furtherWhat happens to hallucination rates when a model is asked a question far outside what it was trained on?
Your turn1 of 2
Out of 145 model responses reviewed, 10 were later confirmed to be hallucinated fabrications. What fraction of responses were hallucinations, as a decimal?

Using AI Responsibly While Coding

  1. How it worksHow does asking an AI to explain a bug instead of asking it to fix a bug keep you in the driver's seat?
  2. Worked exampleWalk me through using an AI as a rubber duck: describing a segmentation fault out loud until the bug becomes obvious.
  3. Going furtherWhat happens to your ability to debug independently the more you outsource every fix to an AI?
Your turn1 of 2
A student spends 22 minutes describing a bug out loud to an AI like a rubber duck, and the bug becomes obvious after 3 minutes of that description. How many of the 22 minutes were spent describing the bug AFTER it had already become clear?

AI and Academic Honesty in CS50

  1. How it worksHow does CS50's policy draw a line between using AI to understand an idea and using it to skip understanding entirely?
  2. Common mistakeWhy isn't asking an AI to explain a concept the same thing as asking it to write your solution for you?
  3. Worked exampleWalk me through the difference between asking an AI why is my loop off by one and asking it to write the function outright.
  4. Going furtherWhat happens to a student's later problem sets if an early one was solved by copying an AI's code untouched?
Your turn1 of 2
A problem set has 9 functions to implement, and a student asks an AI to write 2 of them outright instead of just explaining the relevant concepts. How many of the functions did the student write themselves?