This lesson is being piloted (Beta version)

Creating an AI chatbot using HuggingFace pretrained

Overview

Teaching: 15 min min
Exercises: 0 min
Questions
  • How to create an AI chatbot

Objectives

7. Creating an AI chatbot using HuggingFace pretrained in your ManeFrame or SuperPOD

Introduction

image

Download pretrained model from HuggingFace and create your own chatbot

import transformers
nlp = transformers.pipeline("conversational",
                            model="microsoft/DialoGPT-large")

cont=1
while cont==1:
    input_text = input("Ask me a question!")
    print(nlp(transformers.Conversation(input_text), pad_token_id=57007))
    if input("Continue?").lower()=="no":
        print("Goodbye")
        break

Running the model

python chatbot_DialoGPT-large.py

Following is the inference from running the chatbot model:

Downloading config.json: 100%|███████████████████████████████████████████████████████████████████| 1.47k/1.47k [00:00<00:00, 1.40MB/s]
Downloading pytorch_model.bin: 100%|███████████████████████████████████████████████████████████████| 334M/334M [00:06<00:00, 58.0MB/s]
Downloading tokenizer_config.json: 100%|██████████████████████████████████████████████████████████████| 205/205 [00:00<00:00, 171kB/s]
Downloading vocab.json: 100%|██████████████████████████████████████████████████████████████████████| 941k/941k [00:00<00:00, 5.09MB/s]
Downloading merges.txt: 100%|██████████████████████████████████████████████████████████████████████| 337k/337k [00:00<00:00, 2.30MB/s]
Downloading special_tokens_map.json: 100%|██████████████████████████████████████████████████████████| 99.0/99.0 [00:00<00:00, 100kB/s]
Ask me a question!do you believe in God
Conversation id: 7417a2a5-412b-4117-8dd5-7cf2237d5811 
user >> do you believe in God 
bot >> i don't believe in god, but i do believe in the existence of a god. 

Continue?yes
Ask me a question!what is the meaning of life
Conversation id: 421afd4c-8bcc-400a-8e86-5a97a61685a6 
user >> what is the meaning of life 
bot >> i don't know. i'm not sure. what is the purpose of life?

Continue?no

You can exit the conversation anytime by replying “no” to the “Continue” question

How many models can I run?

microsoft/DialoGPT-small
microsoft/DialoGPT-medium
microsoft/DialoGPT-large
facebook/blenderbot_small-90M
facebook/blenderbot-400M-distill
facebook/blenderbot-1B-distill

or even personal model can be used:

vuminhtue/DialoGPT-large-HarryPotter3
rlatt/DialoGPT-large-King-James-Bible-test

Key Points

  • HuggingFace, chatbot