Lab1 Installation
Lab1 Installation
PROMPTING
1. About OpenAI :
OpenAI is an AI research and deployment company. Their mission is to ensure that artificial
general intelligence benefits all of humanity.
They have multiple generative AI models, each with different capabilities and price points.
Prices can be viewed in units of either per 1M or 1K tokens. You can think of tokens as
pieces of words, where 1,000 tokens is about 750 words.
Visit this link for the various models and their pricing details:
https://platform.openai.com/docs/models
3. To access any of this/these OpenAI model/models, we need to get the API key to
get our request authenticated.
4. Instructions to set the OpenAI account and get the API key:
1. Sign Up and create an account in OpenAI https://platform.openai.com/signup
using your personal gmail account. This is will enable an usage free of cost for the
first 3 months/based on the token usage.
2. Go to yor profile icon(right end corner) and click “Your Profile” from the drop
down.
3. Select “User API Keys” and create a new secret key
4. Use GPT-3.5 Turbo. Optionally name the key.
5. Be careful, it will only be displayed once. Copy and paste it into a password
manager so it’s stored securely.
6. Do not share your API key with others, or expose it in the browser or other client-
side code.
7. You can track your usage history from your dashboard
8. Follow this link https://platform.openai.com/docs/quickstart
8.1 Set up the Spyder IDE in Python
8.2 Set up the API key in Windows through an environment variable with a
permanent setup
8.3 Alternatively, set up the environment variable with the key only for the
current session as given below
8.4 Try the API without writing any code using the Playground.
8.5 Run few prompts as in
These models are trained with data from thousands of online resources upto 2021.
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
print(completion.choices[0].message)
Designing a prompt is essentially how you "program" a model like GPT-4, usually
by providing instructions or some examples of how to successfully complete a
task.
We are not training the model to complete a given task. We have to guide the
model with clear instructions and context information to complete a given task.
OpenAI uses three different roles to integrate with its API keys : System, User and
Assistant.
1. System Role:
What it does: The System role is used to provide setup information or context that
informs the behavior of the model. This can include instructions or guidelines on
how the conversation should proceed.
When to use it: You use this role to set the stage for the interaction. For example,
if you want the model to maintain a formal tone throughout the conversation or if
you need to specify rules like avoiding certain topics.
Ex: You will be provided with statements and your task is to convert them into
English.
2. User Role:
What it does: This role represents the human user in the conversation. Inputs from the
user guidesthe conversation and prompt responses from the assistant.
When to use it: Whenever the human user is making a statement or asking a question.
This is the most frequent role used in a standard interaction.
3. Assistant Role:
What it does: This is the role of the model itself, responding to user inputs based on
the context set by the system.
When to use it: This role is automatically assumed by the model when it replies to the
user’s queries or follows the system’s instructions.
Models like GPT-4 can be used across a great variety of tasks including content or code
generation, summarization, conversation, creative writing, and more.
All these exercises can be executed either from playground or from the Spyder IDE.
From playground:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": "You will be provided with statements, and your task is to convert
them to standard English."
},
{
"role": "user",
"content": "She no went to the market."
}
],
temperature=0.7,
max_tokens=64,
top_p=1
)
NOTE : Try the following examples Summarize for a second grader, Emoji translation,
Calculate time complexity, Explain code, Modd to color, Emoji chatbot, Tweet classifier, etc
from https://platform.openai.com/docs/examples
About GPT-3:
GPT-3 was introduced by Open AI earlier in May 2020 as a successor to their previous
language model (LM) GPT-2. It is considered to be better and bigger than GPT-2. In fact,
with around 175 Billion trainable parameters.
GPT-3 is a very large language model. Given some input text, it can probabilistically
determine what tokens from a known vocabulary will come next. Before we go ahead and see
what makes GPT-3 so special, lets first understand what is a language model?
Language Model:
Language models are statistical tools to predict the next word(s) in a sequence. In other
words, language models are probability distribution over a sequence of words. Language
models have many applications like:
A popular encoding method used in NLP is Word2Vec which was developed in 2014. The
real boost to language models came in 2019 with the arrival of the “transformer” and
“attention” mechanisms. GPT-3 has 175 B Parameters, 96 attention layers and 3.2 M batch
size. The OpenAI GPT-3 model has been trained about 45 TB text data from multiple sources
which include Wikipedia and books. The multiple datasets used to train the model are shown
below:
Common Crawl corpus contains petabytes of data collected over 8 years of web crawling.
The corpus contains raw web page data, metadata extracts and text extracts with light
filtering.
WebText2 is the text of web pages from all outbound Reddit links from posts with 3+
upvotes.
Wikipedia pages in the English language are also part of the training corpus.
The third column in the table “Weight in training mix” refers to the fraction of examples
during training that are drawn from a given dataset.
The team could not retrain the model due to the high cost associated with the training.
GPT-3 Architecture:
GPT-3 is based on the original transformer architecture, except that it is larger in size.
The GPT-3 is not one single model but a family of models. Each model in the family has a
different number of trainable parameters. The following table shows each model, architecture
and its corresponding parameters:
Energy Usage: