Skip to content
CBT Nuggets
DemoBook a Demo

Explore AI Language Models and OpenAI's ChatGPT

This skill, part of the Programming for Data Science course, delves into the exploration of AI language models with a focus on OpenAI's ChatGPT. It covers the basics of artificial intelligence, machine learning, and deep learning, and explains how language models like GPT-3 work. Learners will also get hands-on experience interacting with ChatGPT programmatically using Google Colab and the OpenAI API, culminating in the creation of an AI-powered app using Streamlit.

Full skill from Programming for Data Science. Preview the training IT teams trust.

Updated

44m

Skill 24 of 26 in Programming for Data Science

What you'll learn

  • Explain what AI is as machine performance of tasks normally done by humans, such as recognizing speech, making decisions, and solving problems
  • Compare the OpenAI GPT-3 models from text-ada-001 to davinci-003 and choose the right model for a production task
  • Describe how ChatGPT predicts the next token from probabilities at the character, word, and token level
  • Explain how a prompt produces a completion and apply instructions, examples, or both when designing a prompt
  • Identify ChatGPT limitations, including predictions that must be tested for accuracy and why sensitive information should never be shared

Free 44-minute video lesson with a full transcript and knowledge checks. No account needed to watch.

Introduction

Welcome to the next skill of the Programming for Data Science course, Explore AI Language Models and OpenAI's ChatGPT! In this first video, we'll review everything we're going to learn in this skill, see you there!

What is AI?

From Wikipedia, "Artificial intelligence (AI) is intelligence—perceiving, synthesizing, and inferring information—demonstrated by machines, as opposed to intelligence displayed by non-human animals and humans. Example tasks in which this is done include speech recognition, computer vision, translation between (natural) languages, as well as other mappings of inputs."

In this video, we'll break AI down into smaller subsets and lay the foundation for working with each technology. See you there!

OpenAI GPT-3 Language Models

From Wikipedia, "A language model is a probability distribution over sequences of words. Given any sequence of words of length m, a language model assigns a probability to the whole sequence. Language models generate probabilities by training on text corpora in one or many languages. Given that languages can be used to express an infinite variety of valid sentences (the property of digital infinity), language modeling faces the problem of assigning non-zero probabilities to linguistically valid sequences that may never be encountered in the training data. Several modelling approaches have been designed to surmount this problem, such as applying the Markov assumption or using neural architectures such as recurrent neural networks or transformers."

What is ChatGPT and How Does it Work Under the Hood?

In this video, we'll use Seaborn to visualize a probability distribution of as language model to further explore the concept. I particularly like using other Data Science libraries to keep one foot in Data Science and the other in AI. See you there!

import seaborn as sns
import matplotlib.pyplot as plt

# Generate mock data for visualization
prompt = "The cat"
predicted_words = ["sat", "jumped", "ran", "slept"]
probabilities = [0.8, 0.1, 0.05, 0.05]

# Plot the data using Seaborn
sns.set(rc={"figure.figsize":(10,5)})
sns.barplot(x=predicted_words, y=probabilities)
plt.title("Prediction for next word given prompt: '{}'".format(prompt), fontsize=20)
plt.xlabel("Predicted word", fontsize=16)
plt.ylabel("Probability", fontsize=16)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
plt.show()

Prompts and Completions

In this video, you get to finally interact with ChatGPT and this time, programmatically using Google's Colab. I've included both the Google colab, an example text file for your key you'll need to modify and upload to Colab, and the code in case you want to use an IDE.

That being said, be sure to create your own api key in the OpenAI dashboard and modify the example my_key.txt file or create your own. All that needs to be in the file is the key, that's all.

!pip install openai
!pip install prettytable

import os
import openai
import time
from google.colab import drive
import prettytable

drive.mount('/content/drive')

with open('/content/my_key.txt', 'r') as file:
    api_key = file.read().strip()

# Store the API key in an environment variable
os.environ["OPENAI_API_KEY"] = api_key

# Use the API key to authenticate
openai.api_key = api_key

# Define the list of available models
models = ['text-babbage-001', 'text-curie-001', 'text-davinci-002', 'text-davinci-003']


# Define the rate limit (e.g., 10 requests per minute)
rate_limit = 10
rate_limit_interval = 60

# Initialize a counter for the rate limit
request_count = 0

# Timestamp for the start of the rate limit interval
interval_start = time.time()

# Continuously prompt the user for questions
while True:
    # Ask the user to enter a question
    question = input("Enter a question (type EXIT in all caps to exit): ")

    # Check if the user wants to exit
    if question.upper() == "EXIT":
        break

    # Check if the rate limit has been exceeded
    if request_count >= rate_limit:
        time_elapsed = time.time() - interval_start
        if time_elapsed < rate_limit_interval:
            time_remaining = rate_limit_interval - time_elapsed
            print(f"Rate limit exceeded. Please wait {time_remaining:.2f} seconds.")
            continue
        else:
            # Reset the rate limit counter and interval start time
            request_count = 0
            interval_start = time.time()

    # Ask the user to select a model
    print("Select a model:")
    for i, model in enumerate(models):
        print(f"{i + 1}. {model}")
    try:
        selected_model = int(input("Enter the number of the model you want to use: ")) - 1
        if selected_model < 0 or selected_model >= len(models):
            raise ValueError("Invalid model number")
    except ValueError as error:
        print(f"Error: {error}")
        continue

    # Generate text
    try:
        response = openai.Completion.create(
            engine=models[selected_model],
            prompt=question,
            max_tokens=2000
        )
    except openai.OpenAIException as error:
        print(f"Error: {error}")
        continue

    # Print the generated text using prettytable
    table = prettytable.PrettyTable(["Model", "Response"])
    table.add_row([models[selected_model], response["choices"][0]["text"]])
    table.max_width = 100
    print(table)

    # Increment the rate limit counter
    request_count += 1

Fun Examples to Try on Your Own!

Here are my favorite three examples for anyone getting started with the OpenAI API. Enjoy! 🪐

1. Corrects sentences into standard English without a subscription!

import os
import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.Completion.create(
  model="text-davinci-003",
  prompt="Correct this to standard English:\n\nShe no went to the market.",
  temperature=0,
  max_tokens=60,
  top_p=1.0,
  frequency_penalty=0.0,
  presence_penalty=0.0
)

2. Explain Complicated Code! In the code below, you are leveraging temperature and top_p which we'll cover in the next skill. Until then, have fun with this code co-pilot example!

import os
import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.Completion.create(
  model="code-davinci-002",
  prompt="class Log:\n    def __init__(self, path):\n        dirname = os.path.dirname(path)\n        os.makedirs(dirname, exist_ok=True)\n        f = open(path, \"a+\")\n\n        # Check that the file is newline-terminated\n        size = os.path.getsize(path)\n        if size > 0:\n            f.seek(size - 1)\n            end = f.read(1)\n            if end != \"\\n\":\n                f.write(\"\\n\")\n        self.f = f\n        self.path = path\n\n    def log(self, event):\n        event[\"_event_id\"] = str(uuid.uuid4())\n        json.dump(event, self.f)\n        self.f.write(\"\\n\")\n\n    def state(self):\n        state = {\"complete\": set(), \"last\": None}\n        for line in open(self.path):\n            event = json.loads(line)\n            if event[\"type\"] == \"submit\" and event[\"success\"]:\n                state[\"complete\"].add(event[\"id\"])\n                state[\"last\"] = event\n        return state\n\n\"\"\"\nHere's what the above class is doing:\n1.",
  temperature=0,
  max_tokens=64,
  top_p=1.0,
  frequency_penalty=0.0,
  presence_penalty=0.0,
  stop=["\"\"\""]
)

3. Last but not least, convert movie titles into emoji 🎥🎬🖖

Back to the Future: 👨👴🚗🕒

Batman: 🤵🦇

Transformers: 🚗🤖

import os
import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.Completion.create(
  model="text-davinci-003",
  prompt="Convert movie titles into emoji.\n\nBack to the Future: 👨👴🚗🕒 \nBatman: 🤵🦇 \nTransformers: 🚗🤖 \nStar Wars:",
  temperature=0.8,
  max_tokens=60,
  top_p=1.0,
  frequency_penalty=0.0,
  presence_penalty=0.0,
  stop=["\n"]
)

Challenge

It's time to check your knowledge of everything you have learned so far. Answer the questions below and if you get any of them wrong, feel free to review the corresponding video above. You got this! 🎉

Knowledge Check

True/False: Deep learning models are based on artificial neural networks

Knowledge Check

True/False: A language model is a probability distribution over sequences of words.

Knowledge Check

What unit does ChatGPT use to make predictions?

Knowledge Check

True/False: When interacting with ChatGPT, it doesn't matter how you write a prompt, you'll generally get accurate, human-like output regardless.

View Transcript

Introduction

0:06Hello, and welcome. In this skill, we're gonna get a chance to explore language models and OpenAI's ChatGPT, and what's really exciting about all of this is that this is gonna set us up for understanding machine learning, which is the next part of Programming for Data Science, Where we are in the course, so this is a skill so that you could take this skill and just learn about language models and ChatGPT, but this is also part of a course called Programming for Data Science, and what's cool about that is that we've learned Python and all the libraries for data science, and now we're gonna get a chance to sort of apply the programming to AI, right, and check out language models because it's super popular right now.

0:51So ChatGPT was released, and basically, everyone's talking about it. It's super exciting. AI is kind of like now everybody knows about it. Data scientists have been using AI in various capacities, computer scientists and so on. However, now it's kind of like out, right? Everybody knows about it. So let's take a look at everything that we're gonna learn in this skill. So first we'll check out what is AI and define that, and that's really important when we're talking about language models.

1:23And so this would be AI. And what we're gonna do in this first video is really talk about the other parts of AI. So this is a subcategory and another subcategory of AI. And this is just gonna us a basic understanding of what AI is, and that's what ChatGPT is. So we'll dive into what ChatGPT is in the context of AI, right? And then we'll dive a little bit deeper into language models and check out OpenAI's GPT-3 language models. And so what is this? Well, we have many models that are available to us through OpenAI, and we'll explore all of these.

1:59And each one of these models will have a different sort of specialty, right? So the first one is the most basic, and by the time that you get to the fourth one, it's the most advanced. And then we'll talk about how does it work under the hood, and that's really cool because you would think that it's really just super smart when, in fact, that's not what's actually happening. And we'll talk about that because it's making predictions, right? It's like you could think of it as like a letter. So C-H-A, and then what is the probability of this one being T, right?

2:32So that would depend on what happened before. And these are all predictions. So I wouldn't say ChatGPT is smart, but I would say it's kind of clairvoyant. Like, it can make some predictions, but it doesn't know anything else. It's just like, "There's is a very strong probability that the next word is cat." Like, that's kind of what's happening. And when you have CPU and GPUs allowing you to do this very, very quickly, then you can get these, like, amazing results from a chatbot. But when you break it down, it's pretty surprising, and that's what we're gonna talk about in that section.

3:07And then finally, how do we interact with ChatGPT? And that would be through prompts. And so what are prompts? Well, that's exactly what we're gonna talk about. And then finally, we have this challenge, and this challenge is just to make sure that you understand all of the concepts in the video. And if you don't, this is a great time to review those because everything is going to sort of build off of everything else. If there's some holes that you have in what AI is or what a language model is, by the time that we get to use it, there's gonna be some things that might not make sense.

3:38So just be sure to review those so that you get, like, the most bang for your buck. But at this stage, it should be pretty straightforward. All right, and so that's about it for this video, and I'll see you in the next video, What is AI? So until then, I hope this has been informative, and I'd like to thank you for viewing.

What is AI?

0:06Before we jump into ChatGPT and OpenAI, and all that good stuff, which is like a lot of fun. Probably already checked it out if you're curious about it, but if not, what we're gonna do is just unpack what is AI so that we can get the most outta this, right. And in the next two skills, we're gonna build off of all of this knowledge. So let me just break down what we're gonna do in these three skills, and how they all work together. Normally we just go skill by skill, and we don't really connect them. And this is true in this case, you don't need to connect these three skills, but just wanted to give you a heads up in case you wanted to build something, and here's what it is.

0:42So this first skill, we're gonna talk about what is AI, and check out ChatGPT, and really get into like prompts, and how does ChatGPT make these predictions, right. They use something called tokens. So we'll dive a little bit deeper into that. And the next skill, we're gonna take ChatGPT, and Google Colab and then work with the API. So we can work programmatically with ChatGPT, and the different models, right. And then you start to wonder, "Wow, I can actually mix Python with ChatGPT, and things start to get really amazing.

1:16The power is really at that point just starts to just exponentially take off, and here's why. ChatGPT is making predictions, but when you pair it with a programming language like Python, then you can get them to work together, and then it's pretty amazing. So what we can do is in the third skill, we're gonna build an app using something called Streamlit. So you're gonna build an AI app, and launch it in that third skill. So there's a lot going on in these three skills, right. So this is programming for data science, but I'm giving you a little heads up, and showing you how you can build a data science app, and publish it to the web using AI.

1:54And so we'll talk about what is AI in this video. So when we're thinking about this, let's talk about it in the big picture, right? So AI generally is something that normally would be a task that a human would do, but now we can use, this is my attempt at a robot, right. So this is a machine. So normally AI is something that would normally be done by a human that is now, sort of done by machine.

2:24And that's the high level overview, right. So we're thinking about things like recognizing speech, making decisions, solving problems, right. AI has the potential to automate all of these tasks, but they're currently performed by humans. But robots are gonna be more efficient, and that's how it is, but it's not terrible, and here's why. It's the same thing with the calculator or first car when cars replaced horses, and things like that. The only difference is that, we just don't know what the future's gonna be. So it's, it's kind of exciting and sort of terrifying for everybody.

2:56But I'm sure it was the same thing with the calculator or any like technological breakthrough. So we're not talking about like the "Terminator" side, like the Hollywood version of AI. What we're talking about is the big picture. So AI is gonna help us automate tasks. And then so what do humans do? Well, humans can do things that humans are better for at, right. Humans aren't so great at repetitive tasks over and over and over like a robot. So it kind of makes sense. So let's dive deeper into this. Okay. So here we have artificial intelligence. So this is that main concept that we've been talking about.

3:29And AI would be like things like reasoning, act, adapt sense, so like human tasks. All right. Fair enough. So what is machine learning, and what is deep learning? So this is machine learning right here. So machine learning is a subset of AI, and these are the algorithms whose performance improves when you add more data over time, right. So it learns from data, without being explicitly told to do that. So this is very cool, and we'll talk a little bit about this.

4:01And when we're talking about machine learning, we have tests, training, and test data, right. And then we'll talk more about that. And then finally we have deep learning, right. So deep learning is a subset of machine learning. As it gets deeper, there are all subsets of each other using slightly different technology. For example, deep learning uses neural networks. Many, many neural networks and big data modeled on the human brain, and this is especially useful for when we're processing unstructured data, and other things.

4:33We'll talk about that in a more detail. Again, we're just trying to stay at the high level. So we know what AI is, it's the general term. Machine learning sort of uses test, and training data to learn. And deep learning uses these recurrent neural networks, these mini networks to refine, and get these products like deep fake videos, right. Which is pretty amazing, right. So AI we know is the larger domain, and machine learning and deep learning are both subsets of AI. And these tasks are usually done by humans.

5:05And one of the earlier types of AI is expert systems. And this was really cool because it was actually very early AI, but the problem was that it was very time consuming, and very complicated to build because you would get about a million instructions right or more. And imagine doing that by hand. So this was very, very time consuming, and complicated. The complexity was just very, very large.

5:35And what deep learning does, interestingly enough, it sort of automates that process. So there's a huge breakthrough, and that's why deep learning, and deep fake videos that you're seeing are just exploding and coming out because it makes that process of expert systems, and basically using neural networks. Many of them to sort of refine the output. And so we take AI and you have machine learning, and then you have deep learning, and you see how they all sort of kind of work together to produce these amazing results. And then machine learning, we talked about how it's an algorithm that helps us make decisions by using that training and test dataset.

6:12And then finally, the sub last subset of ML in this case is deep learning. There are other subsets, but these are the main ones. And it uses deep neural networks to learn patterns in complex data, right. So like deep fakes and even language models. All right. So that's about it for this video, and I'll see you in the next one when we talk about OpenAI GPT-3 Language Models. I hope this has been informative, and I'd like to thank you for viewing.

OpenAI GPT-3 Language Models

0:06Welcome back. So in this video, we're gonna talk about language models, and if you're probably wondering what a language model is, think of it as a probability distribution of words and which is the most probable to come next in a sequence of words. And in this video, we're gonna take a look at OpenAi's GPT-3 models. But first, let's check out a definition from Wikipedia on a language model. Okay, so the definition, and we're just gonna look at this first one here, is, "A language model is a probability distribution over sequences of words."

0:41So basically what we just discussed. So, "Given any sequence of words, length m, a language model assigns a probability," right? So word one all the way through word m for the whole sequence, right? So, "Language models generate probabilities by training the text corpora in one or many languages. Given that the languages can be used to express an infinity variety of valid sentences, language modeling faces the same problem of assigning non-zero probabilities to linguistically valid sequences that may never be encountered in the training data."

1:14In summation, several modeling approaches have been designed to deal with this problem, such as applying Markov assumption or using neural architectures such as recurrent neural networks or transformers. Now, this might be like, okay, what is, (laughs) what is a language model again? And while some of this makes sense, some of it may not. It's gonna be a lot easier because we're talking about it in the scope of ChatGPT. All right, so without further ado, let's jump into OpenAI GPT-3 language models so that we can better understand what is a language model and what's happening with this probability distribution.

1:54All right, so what is ChatGPT? We said that, well, it's a language model developed by OpenAI. All right, so that's good, but what does GPT mean? So GPT is generative pretrained transformer, right? Which is a type of language model that's developed by OpenAI, and again, it uses deep learning techniques, so we talked about that, to generate human-like text. And how does it do that?

2:24In short, you have a massive amount of data, like big data, a lot of complexity. And so the GPT, these models are trained on this huge amount of data with a goal of generating coherent text that just shoots out. And it does this pretty much most of the time. And, again, we're talking about a clairvoyant, but not necessarily rational fortune teller, I guess, right? Word fortune teller. So we'll dive into this. But what are the models? So we've said, okay, we know what ChatGPT is.

2:55It's this language model. We don't know what a language model is totally, so let's talk about these different models. So there's more than one. For example, we have the first one. So text-ada-001, and this is Ada Lovelace. If you don't know Ada, big part of computer science. So in short, this model is the smallest and most basic model, and it's designed for simple language generation tasks, right? So if you're first starting out using GPT models, this is a good one, okay?

3:26So this is the starter and also the smallest. Then we have text-babbage. And this one is, and this one's named after Charles Babbage. Also, both mathematicians that work closely together and definitely research more about them. And this is just a more advanced version of this model right here. And what you're gonna get here is more sophisticated responses. And that's good, if you need more advanced capabilities compared to ada-001, so this would be a good choice.

3:58And then number three, we have curie, okay? Then we have text-curie-001 named after physicist, Marie Curie. And again, this is gonna be a more advanced version, more sophisticated with more computing power compared to text-babbage-001. It's good for like writing articles, composing poetry, and even coding, right? We'll talk a little bit more about that. And the next one, which is, actually, let me just clean this screen up and then start again. And then number four, we have, and this one's named after Leonardo da Vinci, and it handles the most demanding tasks like writing entire books, composing complex software programs, great for demanding language generation tasks, and also for those who need more advanced power capabilities.

4:46Again, we went from the other two models, one through three, and then finally, we have this one, and this is just gonna be the most powerful. And the takeaway here is that, well, you have a choice. If you need something that's very, very basic, well, then you would use the first one, right, text-ada-001. Then you might sort of jump down based on what your needs are, and you think of it as a production application. So if you have a production application, you don't wanna use davinci-003 if you're just doing something very, very basic. You wanna match that.

5:17And this is kind of like thinking about algorithm complexity, right? You don't wanna use something that's gonna be, that's gonna have terrible time and space complexity because it's gonna be more expensive and not very efficient. So in a sort of abstracted way, same thing here. So use the right model for the task, right, based on these. And we're gonna jump into these models in a lot more depth, but I just kind of at least wanted to talk about them before we started to like, check out the documentation and actually interacting with ChatGPT.

5:47All right, so that's about it for this video. I hope this has been informative, and I'd like to thank you for viewing.

What is ChatGPT and How Does it Work Under the Hood?

0:07So we've talked about all of these models, but we still haven't really... Welcome back. So far we've talked about all of these instrument. Welcome back. So far, we've talked about all of these interesting language models, right? Going from the first one, which is the most simple and basic, all the way to DaVinci 003, which is the most advanced, but still, we don't know how ChatGPT works under the hood. So let's check it out.

0:39All right, so when we're trying to understand ChatGPT, we're really thinking about probabilities, right? So we have this word cat, and let's say that we're trying to predict the next word. So what could it be? So we talked earlier about predictions, right? So we're predicting characters, like if you said cat, what is the probability of that happening, right? So this would be at the character level. And we can do this at the word level, right?

1:10So like, what would be the next word in this sentence? Let's say that it's something to do with a cat. So what's the probability that it could be cat sat or cat jumped, or cat ran or cat slept, right? So what is the probability? I'm thinking cat sat because it seems like the most, it rhymes the most, it seems like the most probable in my mind, right? So like if we're pretending to be ChatGPT, I would choose that one.

1:42So this is the character level, and then there is the word level, cat sat. And then what ChatGPT uses is something called a token, which is kind of like a word chunk, right? So the the different levels that you can have for these predictions, and this is what ChatGPT uses is this token. And so what I did is used the seaborn to visualize this and here we have that. So I'll add this code above this video so that you can actually check it out and run it yourself if you'd like.

2:14But it's not the logic, it's just basically showing you the prediction. So the probability for sat is like almost one, right? So from zero to one, so one is like 100% and zero would be not. So all of these are less than 10% or less, right? So you can clearly see that, so cat sat and that this is what it's gonna do. Sometimes the other words will not be so far apart. So you might have these two words. So you can actually choose the first, second, or third option based on the probabilities, right?

2:47So in essence, that's what's actually happening, right? Words that the language model thinks that might come next, given a certain prompt. Okay, I said prompt and that's how we talk to ChatGPT. So now that we have an understanding of these prompts and character level, word level, and token level, which is like a word chunk, that's how it's predicting. It's predicting word chunk by word chunk, or token by token, based on these prompts. And that's what we're gonna talk about next, like how to use prompts to interact with ChatGPT.

3:23And until then, I hope this has been informative, I'd like thank you for viewing.

Prompts and Completions

0:06Congratulations on making it to the final video in this skill. And so far we've covered a lot about ChatGPT, the different language models that we have available to us, and which one we should use based on different tasks, thinking about time and space complexity abstracted. And so now we're talking about prompts, right? This is the exciting part. So let's check out OpenAI. Register for an account, and then we'll start prompting ChatGPT. And I'll also share a Colab notebook with you so that you can actually interface programmatically using the API, and I'll show you how to do all of this.

0:44And again, we're not gonna dive super deep into this in this video because we just unpacked language models and ChatGPT, and what does it do? And that's exactly what we're gonna do, we're gonna build off of everything that we've done in this skill and use Colab to programmatically interact with the OpenAI API, so we can interact with ChatGPT models that way. All right, enough said, let's jump right into this. Okay, so here is Google. And I've searched for OpenAI's ChatGPT.

1:17and just make sure that you're logged in here so that you can copy this Colab notebook that I'm gonna share with you. But first let's go ahead and go to ChatGPT, here it is. "Optimizing language models for dialogue." So definitely a language model. So let's click on that. And what we wanna do here is you can just click on "Try ChatGPT," but you might need, I think I might be logged in, but if not, what you can do is just click on API and then log in.

1:48And at this point, if you don't have an account, then you can just sign up. And basically you would either use your email address, or you can use an associated Google account, which is what I'm gonna do. But I'm gonna go to Log In, 'cause I've already created an account. So here is "Continue with Google." And I'm gonna choose this other one here. It's my test account. All right, so now we're signed up. And sometimes you might not be able to access the site because it's super popular. So just keep in mind that it might say something like, "Network is very busy," or something like that.

2:25Try again later. So just keep in mind that's pretty normal. But if you keep trying later you should be able to get into it. All right, so here is the API. And so here's some tutorials and some examples. And we'll dive into all of this in the next skill, but for right now, I just wanted to show you that like, for example, Text Completion, if we click on this, it'll take us through this whole, basically a completion is what you get back after you give ChatGPT a prompt.

2:55So you get this completion, the output, right? And this talks all about this, the prompt design, and basically here are the three main steps. All right, so this is what we wanna look at right here. And so let's say the first one, okay, so what is it saying here? So, "You can either use instructions or examples or a combination of the two. So if you want a model to rank a list of items in alphabetical order, or to classify a paragraph by sentiment, show it that's what you want," okay? So show and tell.

3:26And then here's this other one, is provide quality data. "If you're trying to build a classifier or get a model to follow a pattern, make sure that there are enough examples. In short, the model is usually smart enough to see through basic spelling mistakes and then still give you that response, but it also might assume this is intentional," and also give you a weird output. And finally check your settings. And we'll talk about this in the next skill when we talk about temperature and top_p settings, and these are how to control how deterministic the model is in generating this completion, right?

4:00So we'll do that in the next one, but I just wanted to show you that there's a lot of information, and the documentation's pretty good documentation. All right, so how do we get started with ChatGPT? Let's go back, click on this logo. And I'm gonna go back to OpenAI.com and then just click on this "Introducing ChatGPT," "Try." Okay, so this is great. So this is exactly what I was trying to show you earlier, and now we can see that we have, that we're not able to check out ChatGPT.

4:34So here I am, I'm gonna make sure that I'm logged in, and then I'm just going to reload this. Log in. Normally, I don't have to do this kind of jumping around. Okay cool, it worked. So, "This is a free research preview." Let me make this a little bit bigger. "Our goal is to get external feedback in order to improve our systems and make them safer." And, "While we have safeguards in place," for example, if you start to like ask things like, how do you make meth, or something that's illegal and basically like questionable, ChatGPT is not gonna let you do that and you might get your account canceled.

5:19So even when you're testing it, keep in mind that it can lock you out if you start to ask some weird stuff. So that's what that's about. "How do we collect data? Conversations may be reviewed by our AI trainers to improve our systems." So what that means is watch out with what you type, 'cause somebody else might see it. "Don't share any sensitive information." That should be pretty clear, but definitely don't do that. And, "We'd love your feedback!" So this is important. "Our system is optimized for dialogue.

5:51So let us know if a particular response was good or unhelpful." And share your feedback here in the Discord server. So this is definitely encouraged, 'cause you will help make ChatGPT even better. Okay, so now we have these prompts. So here's some example prompts, and the capabilities and some limitations, right? And one of those major limitations is right here. So it has a, "Limited knowledge of the world and events after 2021." Okay, fair enough. And so it, "May occasionally produce harmful instructions or biased content."

6:26And this is also important: "May occasionally generate incorrect information." So definitely keep that in mind. So let's try some things. So, "Tell me how to write a good prompt." All right, so here's our first prompt. "Tell me how to write a good prompt." Here we go. "Be clear and specific, be concise, be interesting, and provide context."

7:02So this is basically what we just talked about. "Use active language, avoid leading questions, consider your audience." That's pretty cool. This is very detailed. So this is a lot more information than we were looking at here. A lot more information than here, when we were looking at text completion, right? Here it was like telling us like three steps, you know, basic guidelines for creating a prompt, and here's eight, and they seem to be pretty useful and very easy to understand.

7:36Okay, the accuracy of these things, again, you have to test them yourself, because it's making predictions, as we talked about earlier, right? So how do we use the API? So this is pretty cool, but I can't really use different models, we only can just chat to it. So what are the other models that we can use? Let's go to Examples. There's a lot of really cool stuff here. These are really cool examples. So definitely check this out.

8:06Python Bug Fixer, nice. Okay, so I don't want to get lost here because it's like a kid in a candy store. This is like amazing stuff. So what I'd like to do is talk about the API. So in order to do that we need to go to the API. So I'm gonna click on my profile here, and go to "View API keys," right? So I've already created my key, you can't see that, but this is what you'd have to do. Once you create this key, you wanna copy that key and you won't be able to see it after you create that key.

8:38So just keep that in mind. However, you can delete it and then start again, right? So that's one option, right? So I already have mine and I have it loaded up in a notebook and I'm gonna show you how that works. All right, so I'm gonna copy and paste code, but I'm definitely gonna leave this for you. And what we're gonna do first is we have to install these, so PrettyTable and OpenAI. These are the two things that are not part of Colab. So we're gonna install them. We're using the exclamation mark to do this in the command line, so in the shell.

9:09So this is doing this in the back end. And once this is done, then we'll start to, I'm basically doing copy and paste, because I don't wanna spend too much time typing code. The reason for that is that's what we're gonna do in the next video, we're gonna actually like work with the API a bunch. But for right now, I'm just showing you this so that you can actually work with the other models because you can't do that with ChatGPT, but you can with Colab. And in the next couple of skills we'll get really deep into this. But for right now, we're just gonna create a playground.

9:40Okay, cool, that looks like it was installed. And so let me show you what I'm gonna do here. So first what I'm gonna do is, so we already have OS, OpenAI, time, and drive. We're gonna connect to drive in PrettyTable. And so this is gonna allow us to connect to that drive. But first what I'm gonna do is I'm gonna upload this text file, which contains my key, right? And it will be deleted when this runtime is terminated. So I'm doing this because you don't wanna just put your key right here, right?

10:15And expose it to everybody. So this is the best practice. And in the next two videos we're gonna talk more about this. Using drive to host your key is not the safest way to do that. But this is one way, if you're doing a teaching screencast, like I am, and just showing this. In case you wanna share your notebook but you don't wanna share your key, you could do it like this. However, if you're in a production environment, you definitely want to use environment variables. And we'll talk more about that when we launch our AI app into production, right?

10:45And we'll use Streamlit to do all of that. But for now, I'm just gonna show you one other way to do this. And so here is my key, let's continue. I'm gonna click on Copy Path. And I'm gonna put that path right here, okay? And then I'm gonna execute this block of code, and I'm gonna give it permission. And this is where I actually have that file. And let's talk about what's happening while it's loading.

11:15So I connected to, mounted to drive, and I said, hey, this is the file that I want you to read, and that is my API key. And now it's connected to Open API, and we can use that key, right? And that key is what we have here. So this is the API key that we're using. And you can always go to settings or usage, and you can see like the usage. So you can see that this is what I'm doing here. The first time I used it, I guess just right now when I connected, it cost a penny.

11:46I think that's what happened. So let's try it again. So now what do we wanna do? So as I said before, I'm gonna give you some models to play with, and let's just add those here. So these are the four models that we discussed earlier. So what we're doing is just saving those models as a list, right? Let's go ahead and run that. And there's gonna be a lot of code here that I'm not gonna talk about. I'll just briefly go over it. But, again, we're gonna do this in the next skill. So what is all this that I just pasted here?

12:16Well, the models we know. So here this is rate limiting, we'll talk more about this later. And I'm just gonna skip to what's more important. So here it's gonna keep asking you a question, and if you type "EXIT," then it's going to allow you to break, right? So that's how you get out of the program. And this is the rate limiting. So you don't wanna exceed that. So this is what's checking for that. And then here it's asking the user to select a model. And so we have that model, and we already talked about that up here. Let me just show you, there, it's our models.

12:51And that's what we're doing. So where's the models? Right here. You select that model and then you get your response, right? And this is the max amount of tokens that we've selected. And again, we're gonna dive much deeper into all of this good stuff in the next skill when we're actually programmatically working with ChatGPT and the OpenAI API. All right, so let's go ahead and run this. All right, so let's go ahead and type a prompt. So, "Once upon a time" is a good one because it'll want to complete it, right?

13:23So this is kind of an easy prompt. And so let's type "enter." And now it asks us what we want to use, like which model. So I'm gonna say one, so we can see the difference between one and four, right? Because we talked about this one being the slowest and most basic, and this is being the most advanced, okay? So, "Once upon a time." Here we go. "Once upon a time there was a kingdom in progress. A kingdom was growing and developing and people were prospering and enjoying life."

13:54Hey, this sounds great. So, you know, there's nothing about terminators. Perfect, I'm happy. So let's do this again. And this is what I said, "Once upon a time." We'll do the same thing, and it just keeps asking us what we want to type, right? I guess it's in that loop. So we're gonna say "DaVinci," so that's gonna be number four, which is not telling me the number here. So one, two, three, and four. Anyway, I know that it's four, so I'm gonna just hit Enter.

14:24And here it's thinking now. And this could be because of network traffic, right? Like it could be just because of that. All right, so let's stop, start it again. Okay, so now I'm gonna say the same thing, "Once upon a time." And we're gonna use number four 'cause it crashed last time. So, "Once upon a time, there was a princess who lived in a castle. She had long, beautiful golden hair." Okay, so this is clearly much more of a story, right?

14:55The other one was kind of weird about a kingdom. This one's like, okay, once upon a time there was a princess, there's golden hair. And like this is gonna be like more advanced, clearly more advanced, but definitely play with this. And so this is what I wanted to leave you with because I didn't wanna just leave you with this, right? And not have any options to use any other models. If I reload this, we're still at a penny. So you can do a lot of stuff and it's not gonna be very expensive. But definitely do protect your keys. And then I'm gonna just say "EXIT" to end this.

15:28And there we go, we've ended our connection, and so we're not gonna be using that API once you hit EXIT. All right, I hope you enjoyed this skill, I know I did. This has been something that it's been very exciting to talk about because now it's super popular, everyone's like, "Oh, I know about ChatGPT!" And what I always like to say is like, "Do you know about the other models, and about Google Colab?" So I'm finally able to share this with you, and I'm really excited about that. So all we have left is the challenge, which I'm sure it's not gonna be a problem, but if it is, definitely just review the videos to make sure that you understand the concepts, because in the next two skills we're gonna get deeper into Colab, and then we're gonna finish things up in that third skill by building an AI-powered app using Streamlit.

16:16All right, until then, I hope this has been informative. I'd like to thank you for viewing.

Frequently asked questions

What does the Explore AI Language Models and OpenAI's ChatGPT lesson cover?

The lesson explains AI as machines performing tasks normally done by humans, such as recognizing speech, making decisions, and solving problems. It then compares the OpenAI GPT-3 models, shows how ChatGPT predicts the next token, walks through prompts and completions, and closes with ChatGPT limitations and a challenge to check understanding.

How long is this ChatGPT lesson and how does it fit into the Programming for Data Science course?

The lesson runs 44 minutes and is the first of three connected skills that build toward an AI web app created with Streamlit and published to the web. Each of the three skills can also be taken on its own, so a Team Lead can assign this one as a standalone introduction to language models.

How do you choose between text-ada-001 and davinci-003 for a production application?

The trainer recommends matching the model to the task: text-ada-001 for very basic needs and davinci-003 for demanding work such as complex language generation. As with algorithm complexity, using a more powerful model than a production task requires is more expensive and less efficient.

How does ChatGPT generate its answers under the hood?

ChatGPT works from probabilities, predicting what is most likely to come next given a prompt. The lesson shows this prediction at the character, word, and token level, where a token is a word chunk, and explains that the model predicts token by token.

What are the main ChatGPT limitations a data team should know before using it at work?

ChatGPT output is a prediction, so its accuracy must be tested rather than assumed. The lesson also points out that conversations may be reviewed by OpenAI's AI trainers, which is why team members should never share sensitive information in prompts.

How can a Training Manager roll this lesson out and track it across a data team?

Training Managers can assign the course through Playlists for structured assignment and use Team Reporting to see per-learner progress and completion, cohort and group views, and completion exports for audit evidence. This lets the team share a common baseline on language models and prompt design before moving on to API and Streamlit work.

What's next?

Ready to keep going?

For your team

Bring this training to your team

See how CBT Nuggets helps IT teams close skills gaps, hit compliance targets, and prove training ROI.

Book a Demo
Just need Programming for Data Science?

Learning on your own? Browse individual plans ($49/month, billed annually) →

Not ready to buy?
with no purchase required. Already have an account?
Book a Demo