Image Source: https://blenderbot.ai

Creating A Telegram Chatbot Using BlenderBot From Meta AI

This is a follow-up on a recent article I wrote on BlenderBot 3 where I take a fresh look at BlenderBot 3 post the recent media uproar. Also in this article I present the simplest way to create your own instances of BlenderBot with a basic example on using the BlenderBot API with Telegram Messenger.

The TL;DR

  • There are various avenues to interact with different versions of BlenderBot.
  • The easiest is to go to the BlenderBot website (https://blenderbot.ai). However, currently access is restricted to the US.
  • You can also interact with a number of versions for BlenderBot via 🤗HuggingFace model cards.
  • A next step is to access BlenderBot via a 🤗HuggingFace inference API in a Notebook environment.
  • And lastly I look at creating a basic Telegram bot using the Telegram API which is polled from within a Notebook environment.

An Overview Of BlenderBot

There has been significant media publicity on BlenderBot 3 and some of the publicity is overhyped and taken out of context.

Firstly, Meta AI states clearly that BlenderBot 3 is capable of searching the internet to chat about virtually any topic, hence there is a high probability that BlenderBot 3 might say something unkind of technology leaders, etc.

Secondly, blenderBot is an experiment in blending various elements of a conversational agent into one.

Thirdly, current established technology often started out as a rudimentary experiment. And that is how BlenderBot should be seen, an experiment of blending different conversational elements into one.

There is this balancing act in Conversational AI between control and flexibility. The more granular the control and fine-tuning are, then invariably the flexibility will diminish.

On the other hand, as in the case of BlenderBot, there is immense flexibility. But the control and fine-tuning is absent and the question is often raised, how will a technology like BlenderBot be harnessed for a domain specific implementation, apart from BlenderBot becoming a general/broad domain digital assistant?

BlenderBot is also not one monolith of a technology, there have been three iterations of BlenderBot, and there are numerous versions of BlenderBot trained on different parameters. And if the bot makes use of internet search to glean information, there is an additional dimension of variability.

The unpredictability of web searches can be negated by a concept Meta AI refers to as KI-NLP. Meta AI open-sourced Sphere and describes it as a web-scale corpus for enabling knowledge-intensive NLP (KI-NLP).

🤗HuggingFace

With HuggingFace inference API’s, you can integrate applications to more than 20,000 pre-trained models or your own private models. This can be done via a simple HTTP request which is fast and scales automatically.

Below is the model card on the 🤗HuggingFace website pointing to the inference API. There are different versions of BlenderBot trained on varying parameters.

The hosted inference API can be queried graphically via the Model Card view, as seen below.

And here is the most basic code example to run BlenderBot in a Notebook. You can see how easy it is to swop out the tokenizer or model.

!pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio===0.9.1 -f https://download.pytorch.org/whl/torch_stable.html!pip install transformersfrom transformers import BlenderbotTokenizer, BlenderbotForConditionalGenerationtokenizer = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-400M-distill")model = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-400M-distill")inputs = tokenizer("I like to write about Conversational AI", return_tensors="pt")inputsres = model.generate(**inputs)restokenizer.decode(res[0])tokenizer.decode(inputs['input_ids'][0])

Next the inference API is combined with a simple two dialog turn routine integrated to the Telegram Messenger API.

Lastly, BlenderBot can be accessed from Telegram and a response is received.

In Conclusion

I have a great appreciation for what Meta AI is attempting to achieve with BlenderBot. Chatbot Development Frameworks are segmented into different elements like messaging, dialog management, NLU, search, Knowledge Bases, etc.

And BlenderBot is trying to fuse or blend these elements, and mimic a human to human interaction as close as possible.

https://www.linkedin.com/in/cobusgreyling
https://www.linkedin.com/in/cobusgreyling

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cobus Greyling

Chief Evangelist @ HumanFirst. I explore and write about all things at the intersection of AI and language; NLP/NLU/LLM, Chat/Voicebots, CCAI. www.humanfirst.ai