Beispiel #1
0
    def __init__(self):
        # model_name = 'facebook/blenderbot_small-90M'
        model_name = 'facebook/blenderbot-400M-distill'
        # model_name = 'facebook/blenderbot-1B-distill'
        # model_name = 'facebook/blenderbot-3B'
        
        print("Creating model")
        self.model = BlenderbotForConditionalGeneration.from_pretrained(model_name)

        print("Creating tokenizer")
        self.tokenizer = BlenderbotTokenizer.from_pretrained(model_name)

        self.history = []
Beispiel #2
0
    def test_generation_from_short_input_same_as_parlai_3B(self):
        FASTER_GEN_KWARGS = dict(num_beams=1, early_stopping=True, min_length=15, max_length=25)
        TOK_DECODE_KW = dict(skip_special_tokens=True, clean_up_tokenization_spaces=True)

        model = FlaxBlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-3B", from_pt=True)
        tokenizer = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-3B")

        src_text = ["Sam"]
        model_inputs = tokenizer(src_text, return_tensors="jax")

        generated_utterances = model.generate(**model_inputs, **FASTER_GEN_KWARGS)
        tgt_text = 'Sam is a great name. It means "sun" in Gaelic.'

        generated_txt = tokenizer.batch_decode(generated_utterances, **TOK_DECODE_KW)
        assert generated_txt[0].strip() == tgt_text
Beispiel #3
0
    def __init__(self, size, env, device, max_context_length):
        """
        The Blender chatbot model was proposed in Recipes for building an open-domain chatbot Stephen Roller,
        Emily Dinan, Naman Goyal, Da Ju, Mary Williamson, Yinhan Liu, Jing Xu, Myle Ott, Kurt Shuster, Eric M. Smith,
        Y-Lan Boureau, Jason Weston on 30 Apr 2020.

        Args:
            size (str): model size
            env (BaseEnv): dialogue environment
            device (str): device (one of ['CPU', 'CUDA', 'CUDA:N']
            max_context_length (int): max history context length
                (it means that length of input context tokens)
        """

        assert size in ['small', 'medium', 'large', 'xlarge'], \
            "model size must be one of ['small', 'medium', 'large', 'xlarge']"

        if size == "small":
            super().__init__("facebook/blenderbot_small-90M", env)
            self.model = BlenderbotSmallForConditionalGeneration.from_pretrained(
                self.name).to(device)
            self.tokenizer = BlenderbotSmallTokenizer.from_pretrained(
                self.name)
        else:
            if size == "medium":
                super().__init__("facebook/blenderbot-400M-distill", env)
            elif size == "large":
                super().__init__("facebook/blenderbot-1B-distill", env)
            elif size == "xlarge":
                super().__init__("facebook/blenderbot-3B", env)

            self.model = BlenderbotForConditionalGeneration.from_pretrained(
                self.name).to(device)
            self.tokenizer = BlenderbotTokenizer.from_pretrained(self.name)

        self.size = size
        self.device = device.lower()
        self.max_context_length = max_context_length
        self.eos = "</s> <s>"

        print('Done!')
Beispiel #4
0
 def tokenizer_3b(self):
     return BlenderbotTokenizer.from_pretrained("facebook/blenderbot-3B")
Beispiel #5
0
 def tokenizer(self):
     return BlenderbotTokenizer.from_pretrained(self.ckpt)
Beispiel #6
0
 def tokenizer(self):
     return BlenderbotTokenizer.from_pretrained(self.model_name)
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration

mname = 'facebook/blenderbot-400M-distill'
# mname = 'facebook/blenderbot-3B' # Too big to run on laptop

model = BlenderbotForConditionalGeneration.from_pretrained(mname)
tokenizer = BlenderbotTokenizer.from_pretrained(mname)

UTTERANCE = "My friends are cool but they eat too many carbs."
inputs = tokenizer([UTTERANCE], return_tensors='pt')
reply_ids = model.generate(**inputs)

print(tokenizer.batch_decode(reply_ids))
Beispiel #8
0
    tokenizer = GPT2Tokenizer.from_pretrained("microsoft/DialoGPT-small")
    #------dialogpt medium------#
    model = GPT2LMHeadModel.from_pretrained("microsoft/DialoGPT-medium")
    tokenizer = GPT2Tokenizer.from_pretrained("microsoft/DialoGPT-medium")

    print("dialogpt is done!")

elif download_type == 'gptneo':
    #------gptneo small------#
    model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-125M")
    tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-125M")
    #------gptneo large------#
    #model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-1.3B")
    #tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B")

    print("gptneo is done!")

elif download_type == 'blender':
    #------blender small------#
    model = BlenderbotSmallForConditionalGeneration.from_pretrained(
        "facebook/blenderbot_small-90M")
    tokenizer = BlenderbotSmallTokenizer.from_pretrained(
        "facebook/blenderbot_small-90M")
    #------blender medium------#
    model = BlenderbotForConditionalGeneration.from_pretrained(
        "facebook/blenderbot-400M-distill")
    tokenizer = BlenderbotTokenizer.from_pretrained(
        "facebook/blenderbot-400M-distill")

    print("blender is done!")
Beispiel #9
0
def load_Blenderbot(Bbot_PATH):
    BbotModel = BlenderbotForConditionalGeneration.from_pretrained(Bbot_PATH)
    BbotTokenizer = BlenderbotTokenizer.from_pretrained(Bbot_PATH)
    return BbotModel, BbotTokenizer