Introduction
This article focuses on building a system using the ChatGPT AI-1 with LLM (Large Language Model). It assumes that readers have a basic understanding of Prompt Engineering. To gain insight into the concepts, you can refer to the following article: [Prompt Engineering in Generative AI](https://www.analyticsvidhya.com/blog/2023/08/prompt-engineering-in-generative-ai/). This article follows a step-by-step approach and is divided into three parts. This is the first part, which delves into the development of an LLM-based system.
Learning Objectives
– Getting started with LLM-based system building.
– Understanding how an LLM works.
– Grasping the concepts of tokens and chat format.
– Applying classification, moderation, and chain of thought reasoning to build a system.
This article is published as part of the Data Science Blogathon.
Working Mechanism of LLM
In a text generation process, an LLM is given a prompt and asked to complete it. For example, if the prompt is “Mathematics is ________,” the LLM may fill in the blank with “an interesting subject” or “the mother of all science.” The large language model learns these responses through supervised learning, where it learns the input-output mapping through labeled training data. This process is similar to X-Y mapping in supervised learning, where the model is trained on labeled data. Once trained, the model can be deployed and used for generating responses.
There are two major types of large language models: base LLM and instruction-tuned LLM. To understand these concepts in more detail, you can refer to the article mentioned earlier.
Transforming a Base LLM
To transform a base LLM into an instruction-tuned LLM, the following process is followed:
1. The base LLM is initially trained on a large amount of data, which can take months on a supercomputing system.
2. The model is further fine-tuned on a smaller set of examples.
3. Human ratings are obtained to assess the quality of LLM outputs based on criteria such as helpfulness, honesty, and harmlessness. Reinforcement Learning from Human Feedback (RLHF) is used as a tool to further tune the LLM.
Application of LLM
In the application part, we import necessary libraries and load the OpenAI key. We define a helper function to get completions when prompted. We then prompt the model and obtain the completion.
Tokens and Chat Format
Tokens are symbolic representations of parts of words. In the example of reversing the letters in the word “Hockey,” the LLM initially fails to do it correctly. However, by adding dashes between each letter and tokenizing them individually, the LLM is able to reverse the letters correctly. The tokenizer plays a crucial role in correctly processing the input and generating the desired output. This concept can be applied in word games or scrabble.
Multiple Messages on LLM
By providing multiple messages to the LLM in a chat format, we can prompt it effectively. The system message sets the overall tone, while the user message provides specific instructions. This chat format helps in guiding the LLM’s responses.
Evaluation of Inputs and Classification
To ensure the quality and safety of the system, inputs need to be evaluated. For tasks with different cases, it is important to classify the query type and use appropriate instructions. The OpenAI key loading and helper function remain the same. We classify customer queries into primary and secondary categories using a delimiter. The model provides structured output in JSON format, making it easily readable and usable.
Conclusion
In this article, we explored the process of building an LLM-based system using ChatGPT AI-1. We learned about prompt engineering, the working mechanism of LLM, tokens and chat format, transforming a base LLM, and evaluation of inputs and classification. Understanding these concepts is crucial for developing robust and effective AI systems.
Source link