Let’s Make Your Own Chat Model: Understanding Completion and Instruction with simple example (4/18)
Table of Contents
1. Introduction
Chat models like ChatGPT provide accurate and detailed automate responses which is suitable for user needs in a conversational manner. It can offer quick, scalable, and cost-effective solutions for business members and customers. Amazingly, we can train our own chatbot with our data and can tailor it to our needs.
In this paper we want to look at how we can treat conversational dataset to train chat model. Then we will simply check how to use trained chat model with conversational way.
Shall we look up??

2. Training a Chat Model
Training a chat model involves customizing it to understand question and generate responses that are appropriate for specific conversational contexts. Here are some strategies for train.
2.1. Using Completions with Dictionary Inputs
Training using completions often involves defining explicit conversation scenarios. A dictionary structure can be helpful to categorize and manage different dialogue intents such as user question and system response.
# Example of training data preparation
training_data = [
{"user": "How do I reset my password?", "agent": "You can reset your password by clicking on 'Forgot password?' link on the login page."},
{"user": "What is your refund policy?",
"agent": "Our refund policy includes a 30-day money-back guarantee from the date of purchase."}
]
2.2 Training with Instruction Token
Another advanced technique involves using instruction tokens such as [INST][/INST] to discriminate parts of the dialogue. These tokens can help the model learn different segments of a conversation with easy way.
# Example of using instruction tokens for training
train_data =
"[INST] Customer request [/INST] I need help with my account [INST] Support response [/INST] Sure, I can help you with that."
# This data would then be fed into a training routine customized for the model.
3. Generating Dialogue with a Trained Model
Once trained, applying the chat model to generate dialogue responses allows.
3.1. Dialogue Generation
Here’s how you can use a trained chat model to respond to user inputs.
# Example of generating a response using a trained model
def generate_response(model, tokenizer, user_input):
input_ids = tokenizer.encode(user_input, add_special_tokens=True, return_tensors='pt')
output_ids = model.generate(input_ids, max_length=50)
return tokenizer.decode(output_ids[0], skip_special_tokens=True)
# Mock user input user_input = "Can I change my flight date?"
# Assuming 'model' and 'tokenizer' are already loaded
response = generate_response(model, tokenizer, user_input)
print("Response from chatbot:", response)

4. Conclusion
The development and application of chat models like ChatGPT are fundamental in today’s tech-driven society. Today, we explored the potentially confusing concepts of completion and instruction methods in the training process. This guide should help anyone interested in developing and deploying chat-based models to better understand the process and the potential of these technologies.

Do you need dataset for train chat model with safe way??
We can offer you conversation dataset with the topic you need.
Do you have data unable to train because of privacy and security concerns?
We can make that dataset available with privacy method: Differential Privacy.
If you have interest, please visit us or take a look about differential privacy. Thank you!