BlenderBot in conversation with another BlenderBot

Code for Human Conversation with BlenderBot

========================================

! pip install transformers

from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration

tokenizer1 = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-400M-distill")
model1 = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-400M-distill")

import re
msg = "null"
inputs = tokenizer1(msg, return_tensors="pt")
res = model1.generate(**inputs)
print(re.sub(re.compile('<.*?>'), '', tokenizer1.decode(res[0]))) 

 

Code for BlenderBot Conversation with BlenderBot

========================================

! pip install transformers

from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration

tokenizer1 = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-400M-distill")
model1 = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-400M-distill")
tokenizer2 = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-400M-distill")
model2 = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-400M-distill")

msg = "whats your name?"
import re
while True:
    inputs = tokenizer1(msg, return_tensors="pt")
    res = model1.generate(**inputs)
    msg = re.sub(re.compile('<.*?>'), '', tokenizer1.decode(res[0]))
    print("Bot 1  :", msg)
    
    inputs = tokenizer2(msg, return_tensors="pt")
    res = model2.generate(**inputs)
    msg = re.sub(re.compile('<.*?>'), '', tokenizer2.decode(res[0]))
    print("Bot 2  :", msg)

Post a Comment

0 Comments