{"id":369,"date":"2024-04-19T00:24:29","date_gmt":"2024-04-19T00:24:29","guid":{"rendered":"https:\/\/azoo.ai\/blogs\/?p=369"},"modified":"2026-03-18T05:14:25","modified_gmt":"2026-03-18T05:14:25","slug":"lets-make-your-own-chat-model-understanding-completion-and-instruction-with-simple-example-4-18","status":"publish","type":"post","link":"https:\/\/cubig.ai\/blogs\/lets-make-your-own-chat-model-understanding-completion-and-instruction-with-simple-example-4-18","title":{"rendered":"Let&#8217;s Make Your Own Chat Model: Understanding Completion and Instruction with simple example (4\/18)"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#1-introduction\">1. Introduction<\/a><\/li><li><a href=\"#2-training-a-chat-model\">2. Training a Chat Model<\/a><ul><li><a href=\"#2-1-using-completions-with-dictionary-inputs\">2.1. Using Completions with Dictionary Inputs<\/a><\/li><li><a href=\"#2-2-training-with-instruction-token\">2.2 Training with Instruction Token<\/a><\/li><\/ul><\/li><li><a href=\"#3-generating-dialogue-with-a-trained-model\">3. Generating Dialogue with a Trained Model<\/a><ul><li><a href=\"#3-1-dialogue-generation\">3.1. Dialogue Generation<\/a><\/li><\/ul><\/li><li><a href=\"#4-conclusion\">4. Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-introduction\">1. Introduction<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<br>Shall we look up??<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"720\" src=\"https:\/\/azoo.ai\/blogs\/wp-content\/uploads\/2024\/04\/jv12681999_youtube.jpg\" alt=\"\" class=\"wp-image-372\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-training-a-chat-model\">2. Training a Chat Model<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-1-using-completions-with-dictionary-inputs\">2.1. Using Completions with Dictionary Inputs<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-to-vivid-purple-gradient-background has-background\"><code><code># Example of training data preparation&nbsp;<\/code>\n<code>training_data = <span style=\"font-family: inherit; font-size: inherit; background-color: rgba(255, 255, 255, 0.2);\">&#91;<\/span><\/code>\n<code><span style=\"font-family: inherit; font-size: inherit; background-color: rgba(255, 255, 255, 0.2);\"> {\"user\":&nbsp;\"How do I reset my password?\",&nbsp;\"agent\":&nbsp;\"You can reset your password by clicking on 'Forgot password?' link on the login page.\"}, <\/span><\/code>\n<code>{\"user\":&nbsp;\"What is your refund policy?\",<\/code>\n<code>&nbsp;\"agent\":&nbsp;\"Our refund policy includes a 30-day money-back guarantee from the date of purchase.\"} <\/code>\n<code>]&nbsp;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-2-training-with-instruction-token\">2.2 Training with Instruction Token<\/h3>\n\n\n\n<p>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. <\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-vivid-cyan-blue-to-vivid-purple-gradient-background has-text-color has-background has-link-color wp-elements-286d36e6c99f85d24eff73c0430d35d9\"><code># Example of using instruction tokens for training \n\ntrain_data = \n\n\"&#91;INST] Customer request &#91;\/INST] I need help with my account &#91;INST] Support response &#91;\/INST] Sure, I can help you with that.\" \n\n# This data would then be fed into a training routine customized for the model.\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-generating-dialogue-with-a-trained-model\">3. Generating Dialogue with a Trained Model<\/h2>\n\n\n\n<p>Once trained, applying the chat model to generate dialogue responses allows.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-1-dialogue-generation\">3.1. Dialogue Generation<\/h3>\n\n\n\n<p>Here\u2019s how you can use a trained chat model to respond to user inputs.<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-vivid-cyan-blue-to-vivid-purple-gradient-background has-text-color has-background has-link-color wp-elements-db513a40e14c26130dc15b8780d9bdf4\"><code><code># Example of generating a response using a trained model\u00a0<\/code>\n<code>def\u00a0generate_response(model, tokenizer, user_input):  <\/code>\n<code>  input_ids = tokenizer.encode(user_input, add_special_tokens=True, return_tensors='pt') <\/code>\n  <span style=\"font-family: inherit; font-size: inherit; background-color: rgba(0, 0, 0, 0.2);\">output_ids = model.generate(input_ids, max_length=50)<\/span>\n  <span style=\"font-family: inherit; font-size: inherit; background-color: rgba(0, 0, 0, 0.2);\">return tokenizer.decode(output_ids&#91;0], skip_special_tokens=True)\u00a0<\/span>\n\n\n<code># Mock user input\u00a0user_input =\u00a0\"Can I change my flight date?\"\u00a0<\/code>\n<code># Assuming 'model' and 'tokenizer' are already <span style=\"font-family: inherit; font-size: inherit; background-color: rgba(0, 0, 0, 0.2);\">loaded<\/span><\/code>\n<code><span style=\"font-family: inherit; font-size: inherit; background-color: rgba(0, 0, 0, 0.2);\">response = generate_response(model, tokenizer, user_input)\u00a0<\/span><\/code>\n<code><span style=\"font-family: inherit; font-size: inherit; background-color: rgba(0, 0, 0, 0.2);\">print(\"Response from chatbot:\", response)<\/span><\/code><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"526\" height=\"670\" src=\"https:\/\/azoo.ai\/blogs\/wp-content\/uploads\/2024\/04\/GettyImages-jv13135267.jpg\" alt=\"\" class=\"wp-image-373\" style=\"width:246px;height:auto\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-conclusion\">4. Conclusion<\/h2>\n\n\n\n<p>The development and application of chat models like ChatGPT are fundamental in today&#8217;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. <\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/azoo.ai\/blogs\/wp-content\/uploads\/2024\/03\/CUBIG-05-1-300x225-1.png\" alt=\"cubig\" class=\"wp-image-71\" style=\"width:472px;height:auto\"\/><\/figure>\n\n\n\n<p>Do you need dataset for train chat model with safe way??<br>We can offer you conversation dataset with the topic you need.<br>Do you have data unable to train because of privacy and security concerns?<br>We can make that dataset available with privacy method: Differential Privacy.<\/p>\n\n\n\n<p>If you have interest, please visit us or take a look about differential privacy. Thank you!<\/p>\n\n\n\n<p><a href=\"https:\/\/azoo.ai\/blogs\" target=\"_blank\" rel=\"noopener\">https:\/\/azoo.ai\/blogs<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/privacytools.seas.harvard.edu\/differential-privacy\" target=\"_blank\" rel=\"noopener\">https:\/\/privacytools.seas.harvard.edu\/differential-privacy<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":370,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"","rank_math_description":"","rank_math_focus_keyword":"Chat model","rank_math_canonical_url":"","rank_math_facebook_title":"","rank_math_facebook_description":"","rank_math_facebook_image":"","rank_math_twitter_use_facebook":"","rank_math_schema_Article":"","rank_math_robots":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[412,1],"tags":[],"class_list":["post-369","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-strategy","category-category"],"jetpack_featured_media_url":"https:\/\/cubig.ai\/blogs\/wp-content\/uploads\/2024\/04\/GettyImages-jv12699937.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cubig.ai\/blogs\/wp-json\/wp\/v2\/posts\/369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cubig.ai\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cubig.ai\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cubig.ai\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cubig.ai\/blogs\/wp-json\/wp\/v2\/comments?post=369"}],"version-history":[{"count":6,"href":"https:\/\/cubig.ai\/blogs\/wp-json\/wp\/v2\/posts\/369\/revisions"}],"predecessor-version":[{"id":382,"href":"https:\/\/cubig.ai\/blogs\/wp-json\/wp\/v2\/posts\/369\/revisions\/382"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cubig.ai\/blogs\/wp-json\/wp\/v2\/media\/370"}],"wp:attachment":[{"href":"https:\/\/cubig.ai\/blogs\/wp-json\/wp\/v2\/media?parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cubig.ai\/blogs\/wp-json\/wp\/v2\/categories?post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cubig.ai\/blogs\/wp-json\/wp\/v2\/tags?post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}