模型:

gorkemgoknar/gpt2chatbotenglish

英文

GPT2电影角色个性化聊天机器人

用于 { https://www.metayazar.com/chatbot } 的模型

GPT2 Small模型是基于电影剧本进行训练的(尤其是科幻片)

通常的HF API不可用,请查看HF Spaces以了解演示用法 { https://huggingface.co/spaces/gorkemgoknar/moviechatbot }

这个工作是基于Hugging Face团队最初开发的个性化聊天机器人({ https://medium.com/huggingface/how-to-build-a-state-of-the-art-conversational-ai-with-transfer-learning-2d818ac26313 })

我还提供了一个清理电影剧本的代码 { https://github.com/gorkemgoknar/moviescriptcleaner }

示例个性化设置方法: { https://gist.github.com/gorkemgoknar/ae29bf9d14fa814e6a64d0e57a4a4ed7 }

由于明显的LM头部标准,Hugging Face接口无法正常工作。但是如果遵循HuggingFace的教程,应该是一样的。除了每个个性化被编码为"My name is XXXX"

在一个类中使用模型、tokenizer和参数,并在下面的函数中调用以触发模型。一些可用的个性化人物如下:

| Macleod | Moran | Brenda | Ramirez | Peter Parker | Quentin Beck | Andy | Red | Norton | Willard | Chief | Chef | Kilgore | Kurtz | Westley | Buttercup | Vizzini | Fezzik | Inigo | Man In Black | Taylor | Zira | Zaius | Cornelius | Bud | Lindsey | Hippy | Erin | Ed | George | Donna | Trinity | Agent Smith | Morpheus | Neo | Tank | Meryl | Truman | Marlon | Christof | Stromboli | Bumstead | Schreber | Walker | Korben | Cornelius | Loc Rhod | Anakin | Obi-Wan | Palpatine | Padme | Superman | Luthor | Dude | Walter | Donny | Maude | General | Starkiller | Indiana | Willie | Short Round | John | Sarah | Terminator | Miller | Sarge | Reiben | Jackson | Upham | Chuckie | Will | Lambeau | Sean | Skylar | Saavik | Spock | Kirk | Bones | Khan | Kirk | Spock | Sybok | Scotty | Bourne | Pamela | Abbott

    def get_answer(self, input_text, personality, history, params=None):
        
        ##Check length of history (to save 1 computation!)
        if len(history)>0:
            #mostly it will be empty list so need a length check for performance
            #would do string check also but just assume it is list of list of strings, as not public
            
            new_hist = [] 
            for ele in history:
                new_hist.append( self.tokenizer.encode(ele) )
            history = new_hist.copy()

        history.append(self.tokenizer.encode(input_text))

        with torch.no_grad():
            out_ids = self.sample_sequence(personality, history, self.tokenizer, self.model, params=params)
        history.append(out_ids)
        history = history[-(2*self.parameters['max_history']+1):]
        out_text = self.tokenizer.decode(out_ids, skip_special_tokens=True)
        #print(out_text)


        history_decoded = []
        for ele in history:
            history_decoded.append(self.tokenizer.decode(ele))

        return out_text, history_decoded, self.parameters