Member-only story
Intro to Chatbots with HuggingFace
See how to work with open-source LLMs and Chatbots with HuggingFace
In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s start by installing the transformers library:
pip install transformers
Once we install the library, we can move on. We will work with the ‘blenderbot-400M-distill’ model from Meta. This is a small open-source model (700 MB) that performs relatively well. Let’s start with the pipeline.
from transformers import pipeline
chatbot = pipeline(task="conversational",
model="./models/facebook/blenderbot-400M-distill")
At this point, I will initiate the conversation by passing the following message:
My name is George and I’m from Greece. Have you ever been to my country?
user_message = """
My name is George and I'm from Greece. Have you ever been to my country?
"""
from transformers import Conversation
conversation = Conversation(user_message)
print(conversation)
Output:
Conversation id: b1f14acb-7d8c-47c8-9fd4-4c587acbd6ad
user:
My name is George and I am from Greece. Have you ever been to my country?