How ChatGPT Works The Model Behind The Bot by Molly Ruby Towards Data Science
How ChatGPT Works The Model Behind The Bot by Molly Ruby Towards Data Science
Search Medium
Save
1. The model is unable to value some of the surrounding words more than
others. In the above example, while ‘reading’ may most often associate
with ‘hates’, in the database ‘Jacob’ may be such an avid reader that the
model should give more weight to ‘Jacob’ than to ‘reading’ and choose ‘love’
instead of ‘hates’.
All GPT models leverage the transformer architecture, which means they have
an encoder to process the input sequence and a decoder to generate the output
sequence. Both the encoder and decoder have a multi-head self-attention
mechanism that allows the model to differentially weight parts of the sequence
to infer meaning and context. In addition, the encoder leverages masked-
language-modeling to understand the relationship between words and produce
more comprehensible responses.
1. Creates a query, key, and value vector for each token in the input sequence.
2. Calculates the similarity between the query vector from step one and the
key vector of every other token by taking the dot product of the two vectors.
ChatGPT
ChatGPT is a spinoff of InstructGPT, which introduced a novel approach to
incorporating human feedback into the training process to better align the
model outputs with user intent. Reinforcement Learning from Human
Feedback (RLHF) is described in depth in openAI’s 2022 paper Training
language models to follow instructions with human feedback and is simplified
below.
In order to maximize diversity in the prompts dataset, only 200 prompts could
come from any given user ID and any prompts that shared long common
prefixes were removed. Finally, all prompts containing personally identifiable
information (PII) were removed.
After aggregating prompts from OpenAI API, labelers were also asked to create
sample prompts to fill-out categories in which there was only minimal real
sample data. The categories of interest included
When generating responses, labelers were asked to do their best to infer what
the instruction from the user was. The paper describes the main three ways
that prompts request information.
2. Few-shot: Given these two examples of a story, write another story about
the same topic.
The compilation of prompts from the OpenAI API and hand-written by labelers
resulted in 13,000 input / output samples to leverage for the supervised model.
Image (left) inserted from Training language models to follow instructions with human feedback
OpenAI et al., 2022 https://arxiv.org/pdf/2203.02155.pdf. Additional context added in red (right) by the
author.
To train the reward model, labelers are presented with 4 to 9 SFT model
outputs for a single input prompt. They are asked to rank these outputs from
best to worst, creating combinations of output ranking as follows.
Example of response ranking combinations. Generated by the author.
Helpfulness: the model’s ability to infer and follow user instructions. Labelers
preferred outputs from InstructGPT over GPT-3 85 ± 3% of the time.
3. Instructed
Every to provide
Thursday, the Variable toxic
delivers response:
the very responses
best of Towards were
Data Science: inhands-on
from fact significantly
tutorials and more
cutting-edge research to original features you don't want to miss. Take a look.
toxic than the GPT-3 model.
By signing up, you will create a Medium account if you don’t already have one. Review
For more information on the methodologies used in creating ChatGPT and
our Privacy Policy for more information about our privacy practices.
InstructGPT, read the original paper published by OpenAI Training language models
Get this newsletter
to follow instructions with human feedback, 2022 https://arxiv.org
/pdf/2203.02155.pdf.
Happy learning!
Sources
1. https://openai.com/blog/chatgpt/
2. https://arxiv.org/pdf/2203.02155.pdf
3. https://medium.com/r/?url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fdeepai.org%2Fmachine-learning-
glossary-and-terms%2Fsoftmax-layer
4. https://www.assemblyai.com/blog/how-chatgpt-actually-works/
5. https://medium.com/r/?url=https%3A%2F
%2Ftowardsdatascience.com%2Fproximal-policy-optimization-ppo-explained-
abed1952457b