Decoding ChatGPT: Understanding the Mechanics of the Bot

Narendra Cherlopalli
3 min readJun 16, 2023

--

Introduction

Machine learning models have transformed the field of Natural Language Processing (NLP) with their ability to understand and generate human-like text. In this article, we will explore the powerful machine learning models that drive ChatGPT, a state-of-the-art language model developed by OpenAI. We’ll delve into the concept of Large Language Models (LLMs), the revolutionary self-attention mechanism, and the innovative technique known as Reinforcement Learning From Human Feedback. Prepare to be amazed by the advancements in NLP!

Large Language Models

Large Language Models (LLMs) form the foundation of ChatGPT. These models have evolved over the years, capitalizing on advancements in computational power. LLMs are trained to analyze vast amounts of text data and understand the relationships between words. As the input dataset and parameter space of LLMs increase, their capabilities grow exponentially.

Training language models typically involves predicting the next word in a sequence, commonly known as next-token prediction or masked-language modeling. However, this sequential modeling approach has its limitations. It fails to assign varying importance to different words in the context and processes data individually rather than holistically.

GPT and Self-Attention

Enter Generative Pre-training Transformer (GPT), the transformative model introduced by OpenAI. GPT models, including GPT-3 and its successors like InstructGPT and ChatGPT, leverage the powerful transformer architecture. Unlike traditional sequential models like LSTM, transformers can process all input data simultaneously.

The key to the success of GPT lies in its self-attention mechanism. Through self-attention, the model assigns different weights to various parts of the input data, allowing it to understand meaning and context. Additionally, GPT employs masked-language modeling to enhance its understanding of word relationships and generate coherent responses.

The self-attention mechanism in GPT works by converting text tokens into vectors that represent their importance within the input sequence. These vectors are generated through a series of steps involving query, key, and value vectors. By iterating this multi-head attention mechanism, GPT captures complex relationships and sub-meanings within the input data.

The Birth of ChatGPT

While GPT-3 brought remarkable advancements to NLP, it had limitations in aligning with user intentions. OpenAI addressed these limitations through the development of ChatGPT, a spinoff of InstructGPT. ChatGPT introduced the innovative technique of Reinforcement Learning from Human Feedback (RLHF) to bridge the gap between model outputs and user intent.

Step 1: Supervised Fine Tuning (SFT) Model

To create ChatGPT, OpenAI fine-tuned the GPT-3 model using a supervised training dataset. Human labelers, hired by OpenAI, provided appropriate responses for user prompts collected from the Open API. This dataset was used to train the SFT model, enhancing its ability to align with user instructions.

To ensure diversity, prompts were carefully selected, and personally identifiable information (PII) was removed. Labelers also created sample prompts to enrich the dataset, covering plain prompts, few-shot prompts, and user-based prompts.

Step 2: Reward Model

After training the SFT model, the next step involved training a reward model. Labelers ranked the model’s outputs for each prompt, creating combinations of output rankings. These rankings were used to train the reward model, which provides a scalar reward value based on the prompt-response pair.

Step 3: Reinforcement Learning Model

In the final stage, the model utilizes the learned policy from the reward model to generate responses. The responses are evaluated based on their reward value, which is then used to further evolve the policy. Proximal Policy

--

--