gorkemgoknar
commited on
Commit
•
7d2ef09
1
Parent(s):
371869c
Update README.md
Browse files
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 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
```
|