Transformers
PyTorch
TensorFlow
JAX
English
blenderbot
text2text-generation
convAI
conversational
facebook
Instructions to use facebook/blenderbot-400M-distill with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use facebook/blenderbot-400M-distill with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot-400M-distill") model = AutoModelForSeq2SeqLM.from_pretrained("facebook/blenderbot-400M-distill", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Deprecations and outdated usage - FIX
#24
by NikeZoldyck - opened
BlenderBot is seq2seq, so use text2text-generation not text-generation or conversational, without chat templates as it expects raw text, not message dicts.
chatbot = pipeline(task="text2text-generation",
model="facebook/blenderbot-400M-distill")
user_message = "What are some fun activities I can do in the winter?"
result = chatbot(user_message, max_new_tokens=128)
print(result[0]["generated_text"])
HF removed/deprecated the Conversation class since most modern models use chat templates directly. For me, I found the simplest approach to be manual conversation tracking with string concatenation.
class SimpleConversation:
"""Lightweight conversation tracker for seq2seq models."""
def __init__(self):
self.history: list[dict[str, str]] = []
def add_user_message(self, message: str) -> None:
self.history.append({"role": "user", "content": message})
def add_bot_response(self, response: str) -> None:
self.history.append({"role": "assistant", "content": response})
def get_context(self, max_turns: int = 3) -> str:
"""Concatenate recent turns into a single string for the model."""
recent = self.history[-(max_turns * 2):] # last N exchanges
return " ".join(turn["content"] for turn in recent)
def __repr__(self) -> str:
return "\n".join(f"{t['role']}: {t['content']}" for t in self.history)
Usage:
convo = SimpleConversation()
First turn
convo.add_user_message("What are some fun activities I can do in the winter?")
response = chatbot(convo.get_context(), max_new_tokens=128)[0]["generated_text"]
convo.add_bot_response(response)
print(convo)
Continue conversation:
convo.add_user_message("What else do you recommend?")
response = chatbot(convo.get_context(), max_new_tokens=128)[0]["generated_text"]
convo.add_bot_response(response)
print(convo)