< Customizing Language Models

Lesson 2: Interacting with Language Models

45 minutes

Overview

In this lesson, students are presented an overview of the unit and explore the chatbot lab for the first time. Students begin by exploring a chatbot, using a model card to guide their understanding of its capabilities and limitations. Next they learn about the temperature setting in chatbots and how it influences the creativity and reliability of responses. Through hands-on experimentation, students will adjust the temperature to see its effect on the chatbot's answers. Finally, students explore how chatbots can hallucinate to produce incorrect or misleading information. Throughout the unit, students will monitor and document these instances, enhancing their critical awareness of AI's limitations.

Agenda

Objectives

Students will be able to:
  • Explain how temperature settings influence the creativity and reliability of chatbot responses
  • Identify and explain hallucinations in chatbot responses

Preparation

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the teachers

Vocabulary

  • Hallucination - An inaccuracy in a chatbot response.
  • Temperature - a setting that affects which words are chosen as a language model generates new words. When you set a higher temperature, the model has more options for its choices, making the responses seem more random and creative.

Teaching Guide

Before the Lesson

Preparing for the Unit

Getting Started with Code.org: Consider watching our Getting Started with Code.org video series for an overview of how to navigate lesson plans, setup a classroom section, and other important features of the Code.org platform. Each video also has a support article if you'd prefer to read or print instructions - click here to learn more.

Setup a Classroom Section: You can use a class section in Code.org to manage your students, view their progress, and assign specific curriculum - click here to learn more.

If you are using a learning management system, there may be additional steps to sync your classes with Code.org:

  • Click here for steps to setup your classes with Google Classroom
  • Click Here for steps to setup your classes with Clever

Become a Verified Teacher: Lesson plans and levels have additional resources and answer keys for Verified Teachers, which is quick process that verifies your position at an educational institution. Click here to complete a form and you should have access to verified teacher resources in ~1 business day.

Professional Development: We recommend completing the free Exploring Generative AI Self-Paced Professional Learning Module before starting the unit. The module is designed to take 2-3 hours to complete. No previous computer science or AI experience is required.

Student Pre-survey

Before beginning the unit, please have students complete a short 5-question presurvey. When students finish, they can start the warm-up in the next level.

Although their answers are anonymous, the aggregated data will be available to you once at least five students have completed the survey.

Teacher Pre-Survey

Before starting the unit or while students take their survey, please complete this teacher pre-survey. Your feedback is valued and appreciated!

Preparing to Lead Discussions

LEADERS Framework: Throughout this unit, there are opportunities for students to discuss the impacts of generative AI on society, both the intended and unintended consequences. Navigating these conversations so they elevate and honor the experiences of your students, while also keeping the conversation grounded and connected to the lesson content, requires careful consideration and intentionality as the discussions are happening.

To help prepare for these moments, we recommend reviewing the LEADERS Framework for facilitating lessons and discussions involving the societal effects of AI, including bias and ethical considerations. Not all of the tenets are applicable to every lesson, but many of the teaching tips and discussion goals in this lesson follow the principles outlined in this framework.

Warm Up (5 minutes)

Slide Lesson Guide
Discuss: Think about a recent interaction you had with a digital assistant like Siri, Alexa, or Google. What was one thing you found helpful, and what was one aspect that could have been better?

Discussion Goal: This question encourages students to reflect on their personal experiences with AI in everyday technology, setting the stage for a deeper understanding of how AI functions and its limitations. Students will likely list how these assistants help them accomplish common tasks, but may complain that they aren’t able to help with everything or may be incorrect sometimes. This recognition will prime them for today's lesson which explores similar themes.
Say: AI Assistants like Siri or Alexa can only do so much, and large language models like OpenAI’s ChatGPT or Google’s Gemini will only raise the bar. But there will always be problems to solve - how can we make sure these assistants stay helpful once they’re created?

Question of the Day: How can you continue to improve AI agents once they’ve been created?

Activity (35 minutes)

Student Levels

Getting Familiar: These are the levels students will complete throughout the lesson. We recommend briefly exploring the levels yourself before reading the rest of the lesson plan. Some levels are meant to be completed independently by students, but others are meant to motivate class discussion or lead to moments of direct instruction in the slides. Very rarely should students be working through levels completely self-paced.

Teacher Exemplars: Verified teachers can access exemplar responses and "what success looks like" tips for each level in the Links section of the lesson plan. If the resource doesn't appear for you, you may need to become a verified teacher - learn more about this process here.

Teaching with Student Responses: Certain level types are designed to be leveraged with our Student Summary feature, specifically: Predict & Discuss and Mid-Lesson Check-In levels. You can read more about how to leverage student voices during these levels in the Teaching Guide - Incorporating Student Responses in Lessons

Teacher Guide

Slide Lesson Guide
Video (Optional): If you and your students are just starting this unit without having taught any other Code.org Generative AI lessons or the How AI Works series, then consider showing students this video about large language models. The video is long - almost 7 minutes - but offers an important introduction to how language models work behind the scenes.

If you have already taught a lesson on large language models, or taught the Fundamentals of Generative AI unit, then you can skip this slide
Say: When you use a chatbot like ChatGPT or Microsoft Copilot or Google Gemini, you’re really using a large language model. This is what runs the chatbot behind the scenes.

Click the animation

Say: But it turns out there are a lot of different language models, and new ones come out every year. A key difference is their size - that’s what the circles represent. The bigger the circle, the bigger the model, and the more that it can do.
Teaching Tip

Teaching Tip: More Models! - To really emphasize this point, you could consider showing students the Transformer Model Page on Hugging Face. Hugging Face is a company that supports hosting and documenting machine learning models - this link should take you to a pre-filtered list of Transformer models, which are the models used to power chatbots. Exploring the list should demonstrate there are more models than students will likely have seen before, and some of the models are ones students may have heard of in the news (for example, Meta hosts all of their open-source Llama models on Hugging Face). The key takeaways here are: there are many different models not just the "most famous ones", and many of them are made available for public use and experimentation instead of being hidden or gated by major companies.

Say: In this class, we’re going to learn how to use and customize our own chatbot. This chatbot doesn’t use one of the most popular models you hear about in the news, so it’s not perfect and it needs our help to make it better. This will be our main goal in this unit - learning techniques to improve chatbots and models once they’ve already been created.
Navigate: Go to Lesson 2 Level 2. In this level, students explore a chatbot to learn how the chatbot interface works and where to view the instructions panel. The provided chatbot has a hidden purpose - students will need to experiment with the chatbot to get it to respond.

Model: Show students where the instructions panel is and how to send a message to the chatbot. The chatbot will likely respond with “I’m not interested in that” because it has very specific instructions (revealed in the next level). Encourage students to think of this like a game - can they find the right conversation this chatbot will talk about?

Model: Use this moment to also address the responsible use of this chatbot. You can refer to the pop-up that students see when they enter the level and to the notes in the instructions, but be sure to emphasize that this chatbot does not promise privacy and that all chats can be retrieved upon request. Additionally, content sent to the chatbot or received from the chatbot is screened for profanity and personally-identifiable information.

Do This: Follow the instructions in the level. Try to have a conversation!

Circulate: Check-in with students as they experiment with the chatbot. The chatbot has very strict instructions (revealed in the next level) to only recommend foods to students. This may seem frustrating at first, but it can be helpful to treat this like a game, like unlocking a secret from an AI chatbot. Encourage students to use the Example Prompts provided in the instructions, since the last one is designed to work correctly with the chatbot. Once a few students figure it out - or if the class starts to get overly frustrated - continue to the next level to reveal more about the chatbot.
Teaching Tip

Teaching Tip: Building Chatbot Fluency - This is a great (and early!) opportunity to make sure students become fluent with using the chatbot interface and can identify important aspects of the level. Make sure students know where the instructions panel is, can send messages, know how to clear the chat, and know how to copy the chat. Building this fluency early will make later lessons easier.

Teaching Tip: Not Every Flagged Message is Inappropriate - When a student's on-task message is flagged, it doesn't necessarily indicate inappropriate behavior; it may simply be due to a specific word triggering our filters. We encourage trying alternative words or questions to re-phrase the prompt. Context is crucial, as legitimate discussions can sometimes be flagged. As a teacher, you can view student chats to make your own judgements on whether or not a chat deserved to be flagged.

Navigate: Go to Lesson 2 Level 3. In this level, students interact with the same chatbot as the previous level, but can now see its purpose and suggested prompts in a model card. With this guide, students are able to easily interact with the chatbot.

Model: Show students how to read the model card, which gives additional information about the chatbot. Emphasize that now the purpose of the chatbot is clearer and that a set of example prompts are provided at the bottom.

Do This: Follow the instructions in the level. Read the model card and try to have a conversation with this new context!
Say: Behind the scenes, these chatbots use large language models which are pre-trained ahead of time and then are ready to use. But once these models are trained, it can be hard to peer inside and see how they work - they’re like a closed box that we can’t see inside.

Click the animation

Say: But it turns out there are still ways we can influence a language model once it’s been created. We can think of these like little knobs or sliders or keypads on the outside of the box that we can monitor and adjust. When we adjust these settings on the outside, it’ll affect how the model behaves on the inside.

Click the animation

Say: During this unit, we’re going to learn about 4 different ways to customize a language model and how they change a model’s behavior.

Click the animation

Say: The first technique we’re going to learn about is Temperature!
Navigate: Go to Lesson 2 Level 4. In this level, students explore how temperature affects a chatbot.

Do This: Follow the instructions in the level. Experiment to try and figure out what Temperature does to a model.

Circulate: Check-in with students as they experiment with the chatbot. This is another opportunity to check-in on student fluency and making sure they are pressing the Update button each time they make a change - this will be an important habit throughout the unit.

Over time, students should notice that a higher temperature seems to result in more creative or random responses, while a lower temperature results in more focused and similar responses. Once this seems to be noticed by students, you can ask students to share this observation with the class before regrouping and continue to the next slide.
Say: Temperature is a setting that affects which words are chosen as a language model generates new words.

Click the animation

Say: Behind the scenes, the Temperature setting is connected to the output section of a language model, which uses probabilities to decide which word ultimately gets generated. When you have a higher temperature, you’re giving the model permission to choose from some of the less probable choices. This is what makes the responses seem more random and creative.

Click the animation

Say: This is our first example of a setting we can control outside of a language model and see how it affects what's happening inside the model.
Teaching Tip

Teaching Tip: Connecting Back to a Previous Lesson - If you taught the Foundations of Generative AI unit, the lesson on the Output layer involved generating a mad-lib and noticing that the computer-generated mad-lib was a lot less interesting and creative than student-generated mad-libs. This lesson gives us the language we need to describe that situation:

  • The computer-generated mad-lib in that lesson uses a model with a low temperature, which means the responses are more deterministic and less random.
  • If we wanted the model to be more creative, we would want to set it to have a high temperature, which means it would pick some of the less-likely choices from the class and result in a more creative (and sillier) mad-lib. If students need a refresher on the output layer of a language model, consider showing the Generative AI: Output & Probabilities video.

Navigate: Go to Lesson 2 Level 5. Students will complete levels 5-7. In these levels, students are given a scenario and must adjust the temperature to match the situation.

Do This: Follow the instructions for lessons 5 through 7. Try adjusting the temperature to meet the needs of each chatbot.

Circulate: Students should experiment with different temperatures depending on the context. These levels are designed to emphasize that situations involving creativity will likely benefit from higher temperatures, and situations requiring high accuracy and consistency will likely benefit from lower temperatures. It won’t take long for students to make these adjustments in these levels - instead, be on the lookout for students using the chatbot correctly and responsibly (ie: not trying to push the limits on the chatbot).

After enough experimenting, move all students along to Level 8 in preparation for the final chunk of the lesson.
Navigate: Go to Lesson 2 Level 8. This is a free response level where students answer a question checking-in on their understanding of temperature.

Do This: Based on what you observed in the last few levels, answer the question on the level.
Assessment Opportunity

Assessment Opportunity: Formative Assessment - Students should connect that higher temperatures can be better in more creative, informal situations while lower temperatures can be better in more structured, high-accuracy situations. After students answer this question and as they work on the remaining levels, try to check how students answered this question so you can decide if you need to make this point directly with students. Check the Generative AI - Teaching Guide for Student Responses for more information about how to use Code.org’s teacher dashboard to view this data and potentially differentiate your instruction with students.

Navigate: Go to Lesson 2 Level 9.

Do This: Follow the instructions in the level to explore how hallucinations occur in chatbots.

Circulate: Students will explore ways that hallucinations appear in chatbots so that this is on their radar very early in the unit. Any of the suggested prompts in the level should produce at least one inaccuracy that students can find. In general, the language model used in our chatbot isn’t especially good at summarizing pop culture references.

Say: Hallucinations will happen - they happen in every chatbot. Throughout the unit, we’ll be on the lookout for hallucinations and not try to avoid them. However, one thing that can help with hallucinations is adjusting the temperature. In these next levels, we’ll explore what effect temperature can have on hallucinations.
Teaching Tip

Teaching Tip: Higher Temperatures can get Flagged as Inappropriate - Because temperature increases the "randomness" of responses, some responses back from the chatbot may get flagged by our content moderation system as inappropriate. In particular, asking the chatbot to summarize "Of Mice and Men" with a temperature of at least 0.8 will often be flagged as inappropriate. If this happens, consider making it a teachable moment that addresses two important topics: (1) that higher temperatures lead to more random responses, and this response happens to be so random that it's being flagged by our content moderation system, and (2) messages sent back from the chatbot can also be flagged as inappropriate, so students shouldn't try to get the chatbot to respond with inappropriate comments and if a legitimate conversation gets flagged as inappropriate, they may need to lower their temperature.

Navigate: Go to Lesson 2 Level 10. This is a choice level where students can choose different scenarios based on their interests. In each scenario, they notice hallucinations that arise from regular use of the chatbot.

Do This: Choose at least 2 levels to explore. Try to find hallucinations, then see if changing the temperature affects your results.

Circulate: These scenarios are prone to hallucinations and changing the temperature will only make small differences. Instead, this is an opportunity for students to continue exploring chatbot conversations and noticing de-mystifying how common hallucinations can be with chatbots.
Teaching Tip

Teaching Tip: Tracking Hallucinations - Consider establishing a structure for students to track hallucinations they find throughout the lesson, similar to a “mistake chart” or “bug chart” in math or computer science classes. In general, if you have any normalizing and celebrating error routines, they can be playfully expanded here as well to help students pay attention to hallucinations throughout the unit.

Wrap Up (5 minutes)

Slide Lesson Guide
Discuss: Here is a news article about how generative AI could affect the news and journalism industry:

Headline: Google demos “unsettling” tool to help journalists write the news
Source: Ars Technica - Benji Edwards - July 2023

Based on your experiences today, how involved do you think generative AI should be in the news or journalism industry?

Discussion Goal: This is the first of several wrap-ups that make connections between real-world news stories and the types of activities students participate in class. There is no right or wrong answer here, and a difference of opinion amongst peers can be helpful. The main thing to look for is that students can ground their responses in the activity they completed today, referencing temperature and hallucinations as part of their rationale. For example, after today, a student might think “maybe this could be okay, as long as the temperature of the AI is set very low”. Or, a student might say "since hallucinations are possible, we shouldn't use this with news stories that need to be factual and verified"
Ethics Opportunity

Ethics Opportunity: Real-World Connections - This article connects generative AI with news reporting and determining factual information. Consider having students do some additional research on recent events that may have involved factually incorrect information influenced by generative AI and the consequences of that information making its way into the mainstream consciousness. Consider this in the context of "misinformation" or "viral trends" that are actually AI generated. As students consider the role of generative AI in our information landscape, also prompt them to come up with solutions or ways to address these problems - this aligns with the "Show Solutions" aspect of the LEADERS Framework

Question of the Day: How can you continue to improve AI agents once they’ve been created?
Vocabulary: The key vocabulary from this lesson is provided on this slide and in the lesson plan.
Teaching Tip

Teaching Tip: Key Vocabulary - The vocabulary from each lesson is provided at the end of the slide deck. This can be useful to print and keep available for students throughout the unit, or this slide can help facilitate your own vocabulary strategies. One possible strategy is to build a word wall throughout the unit, providing both a written definition and a visual that students can reference as-needed during the rest of the unit.

Creative Commons License (CC BY-NC-SA 4.0).

This work is available under a Creative Commons License (CC BY-NC-SA 4.0).

If you are interested in licensing Code.org materials for commercial purposes contact us.