top of page

Build a Custom Chatbot Using Large Language Model




Introduction

In this blog post, we will delve into the development of a custom Large Language Model (LLM) chatbot. The chatbot is built using a pre-traned LLM model called flan-t5-base, which was released by Google. This model is pre-trained on a large text dataset without any filtration, making it highly versatile and suitable for fine-tuning to serve as a chatbot. Our objective is to fine-tune this LLM to answer frequently asked questions from our clients and provide appropriate responses.


Approaches

To create a chatbot, there are two main approaches: fine-tuning a pre-trained Large Language Model or using Prompt engineering. Prompt engineering involves crafting specific input prompts to elicit desired responses from the model. However, this method has limitations in terms of the input length, which might restrict the ability to address all potential questions and answers the model needs to learn.


Given these considerations, we have chosen the fine-tuning approach for our chatbot. Fine-tuning allows us to train the LLM on our custom dataset, comprising questions commonly asked by clients and the corresponding responses we have provided in the past. This approach enables the model to learn the intricacies of addressing a wide range of questions, making it more adaptable to our specific needs. Additionally, in the future, if we need to include more information or update the responses, fine-tuning the model again becomes a straightforward process.


Custom Dataset and Preprocessing

To train our chatbot, we prepared a custom dataset consisting of questions and their respective answers that clients typically inquire about. To ensure seamless integration with the model, we followed the preprocessing method outlined in the flan-t5-base model page. The data was tokenized using the tokenizer provided with the model, making it suitable for input to the LLM. In order to provide you more idea of how to make such dataset we have given a photo of some of the rows from our dataset which is stored in the form of .csv file.

Fine-tuning the Model

After preparing the custom dataset and performing the necessary preprocessing, we proceeded to fine-tune the flan-t5-base model. The primary objective of fine-tuning was to overfit the model to our specific question-and-answer pairs. Overfitting the model to this dataset was essential to limit the model's ability to generate random and irrelevant text. As the chatbot would be interacting with potential clients, it was crucial to ensure that the responses provided are relevant and informative.


Fine-tuning the model involved training it for approximately 50 epochs. This process allowed the model to learn and adapt to our custom dataset effectively. By focusing on this relatively small model, we strike a balance between performance and computational requirements. Larger models may indeed perform better in text generation tasks, but they demand significantly more computational resources for both training and live chatbot sessions.


Advantages of flan-t5-base

The flan-t5-base model has been specifically chosen due to its suitability for our chatbot application. While there are more advanced and larger models available that excel in text generation tasks, the flan-t5-base model offers some key advantages for our use case:


  • Lower Computational Requirements: The model is relatively small and can be trained on a GPU with just 3GB of RAM. Additionally, during chatbot sessions, it can run on a CPU, reducing overall deployment costs and complexity.

  • Ease of Deployment: The chatbot application is developed using the Django Framework, which facilitates easy integration with other applications if needed. This modularity and flexibility add to the convenience of deploying and maintaining the chatbot.


Technology Stack

The development of the custom Large Language Model chatbot is primarily based on the Python programming language. We utilize several libraries to streamline the process and enhance the model's performance:

  • Transformer: This library forms the backbone of the chatbot, providing the necessary tools for fine-tuning the flan-t5-base model.

  • Accelerate: Used to accelerate the training process and optimize the performance on compatible hardware.

  • Evaluate: Assists in evaluating the model's performance and making informed decisions during the fine-tuning process.

  • PyTorch: A deep learning framework that enables efficient model training and inference.

  • NumPy: Utilized for numerical computations and data manipulation, supporting various aspects of the chatbot development.

  • Django: Utilized for building the frontend and backend of web application so that we can deploy it.

Samples Images of the Chatbots





Conclusion

The development of a custom Large Language Model chatbot allows us to cater to our clients' needs more effectively. By fine-tuning the flan-t5-base model on a custom dataset, we equip the chatbot to provide accurate and relevant responses to a wide range of inquiries. Leveraging the advantages of this relatively small model, we achieve a balance between performance and computational efficiency. The Python-based implementation and the use of popular libraries simplify the development process and ensure seamless integration with other applications. Overall, this custom chatbot serves as a valuable tool for interacting with clients, delivering timely and informative responses to their queries.

To build such custom chatbots using open source Large Language Model or any other applications using Large Language Models feel free to contact us at contact@codersarts.com




bottom of page