gorkemgoknar commited on
Commit
7d2ef09
1 Parent(s): 371869c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +61 -27
README.md CHANGED
@@ -6,11 +6,6 @@ tags:
6
  - gpt2
7
  - conversational
8
  license: apache-2.0
9
- datasets:
10
- - wikipedia-turkish
11
- metrics:
12
- - perplexity
13
- - accuracy
14
  widget:
15
  - text: Bu yazıyı bir bilgisayar yazdı. Yazarken
16
  context: ''
@@ -32,28 +27,67 @@ For obvious reasons I cannot share raw personafile but you can check above gist
32
  A working "full" demo can be seen in https://www.metayazar.com/chatbot
33
  For Turkish version (with limited training) https://www.metayazar.com/chatbot_tr
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  ```python
37
- tokenizer = AutoTokenizer.from_pretrained('microsoft/DialoGPT-small')
38
- model = AutoModelWithLMHead.from_pretrained('output-small')
39
- # Let's chat for 5 lines
40
- for step in range(100):
41
- # encode the new user input, add the eos_token and return a tensor in Pytorch
42
- new_user_input_ids = tokenizer.encode(input(">> User:") + tokenizer.eos_token, return_tensors='pt')
43
- # print(new_user_input_ids)
44
- # append the new user input tokens to the chat history
45
- bot_input_ids = torch.cat([chat_history_ids, new_user_input_ids], dim=-1) if step > 0 else new_user_input_ids
46
- # generated a response while limiting the total chat history to 1000 tokens,
47
- chat_history_ids = model.generate(
48
- bot_input_ids, max_length=500,
49
- pad_token_id=tokenizer.eos_token_id,
50
- no_repeat_ngram_size=3,
51
- do_sample=True,
52
- top_k=100,
53
- top_p=0.7,
54
- temperature = 0.8
55
- )
56
-
57
- # pretty print last ouput tokens from bot
58
- print("AI: {}".format(tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  ```
 
6
  - gpt2
7
  - conversational
8
  license: apache-2.0
 
 
 
 
 
9
  widget:
10
  - text: Bu yazıyı bir bilgisayar yazdı. Yazarken
11
  context: ''
 
27
  A working "full" demo can be seen in https://www.metayazar.com/chatbot
28
  For Turkish version (with limited training) https://www.metayazar.com/chatbot_tr
29
 
30
+ Due to double LM head standart hugging face interface will not work. But if you follow huggingface tutorial should be same.
31
+ Except each persona is encoded as "My name is XXXX"
32
+
33
+ Use model, tokenizer and parameters within a class and call in below functions to trigger model.
34
+ Some of the available personas:
35
+
36
+ '''
37
+ | Macleod | Moran | Brenda | Ramirez | Peter Parker | Quentin Beck | Andy
38
+ | Red | Norton | Willard | Chief | Chef | Kilgore | Kurtz | Westley | Buttercup
39
+ | Vizzini | Fezzik | Inigo | Man In Black | Taylor | Zira | Zaius | Cornelius
40
+ | Bud | Lindsey | Hippy | Erin | Ed | George | Donna | Trinity | Agent Smith
41
+ | Morpheus | Neo | Tank | Meryl | Truman | Marlon | Christof | Stromboli | Bumstead
42
+ | Schreber | Walker | Korben | Cornelius | Loc Rhod | Anakin | Obi-Wan | Palpatine
43
+ | Padme | Superman | Luthor | Dude | Walter | Donny | Maude | General | Starkiller
44
+ | Indiana | Willie | Short Round | John | Sarah | Terminator | Miller | Sarge | Reiben
45
+ | Jackson | Upham | Chuckie | Will | Lambeau | Sean | Skylar | Saavik | Spock
46
+ | Kirk | Bones | Khan | Kirk | Spock | Sybok | Scotty | Bourne | Pamela | Abbott
47
+
48
+ '''
49
+
50
 
51
  ```python
52
+ def get_answer(self, input_text, personality, history, params=None):
53
+
54
+ ##Check length of history (to save 1 computation!)
55
+ if len(history)>0:
56
+ #mostly it will be empty list so need a length check for performance
57
+ #would do string check also but just assume it is list of list of strings, as not public
58
+
59
+ new_hist = []
60
+ for ele in history:
61
+ new_hist.append( self.tokenizer.encode(ele) )
62
+ history = new_hist.copy()
63
+
64
+ history.append(self.tokenizer.encode(input_text))
65
+
66
+ with torch.no_grad():
67
+ out_ids = self.sample_sequence(personality, history, self.tokenizer, self.model, params=params)
68
+ history.append(out_ids)
69
+ history = history[-(2*self.parameters['max_history']+1):]
70
+ out_text = self.tokenizer.decode(out_ids, skip_special_tokens=True)
71
+ #print(out_text)
72
+
73
+
74
+ history_decoded = []
75
+ for ele in history:
76
+ history_decoded.append(self.tokenizer.decode(ele))
77
+
78
+ return out_text, history_decoded, self.parameters
79
+
80
+
81
+
82
+ def predict(self, question, parameter_dict):
83
+ try:
84
+ answer = self.generate_text(question, model=self.model,
85
+ tokenizer=self.tokenizer,
86
+ parameter_dict=parameter_dict,
87
+ )
88
+ return answer
89
+ except Exception as e:
90
+ raise Exception(
91
+ "Runtime error see cloudwatch logs : {}".format(repr(e)))
92
+
93
  ```