Update README.md
Browse files
README.md
CHANGED
@@ -10,4 +10,70 @@ language:
|
|
10 |
|
11 |
GPT2 model trained on Role Playing datset.
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
GPT2 model trained on Role Playing datset.
|
12 |
|
13 |
+
## Custom Tokens
|
14 |
+
The model containes 4 custom tokens to diffirentiate between Character, Context and Input data.
|
15 |
+
The Expected input to the model is therefore:
|
16 |
+
|
17 |
+
```python
|
18 |
+
"<|CHAR|> Character Info <|CONTEXT|> Dialog or generation context <|INPUT|> User input"
|
19 |
+
```
|
20 |
+
|
21 |
+
The model is trained to include Response token to what we consider responce.
|
22 |
+
Meaning the model output will be:
|
23 |
+
|
24 |
+
```python
|
25 |
+
"<|CHAR|> Character Info <|CONTEXT|> Dialog or generation context <|INPUT|> User input <|RESPONSE|> Model Response"
|
26 |
+
```
|
27 |
+
|
28 |
+
The actual output can be extracted by split function
|
29 |
+
|
30 |
+
```python
|
31 |
+
model_out = "<|CHAR|> Character Info <|CONTEXT|> Dialog or generation context <|INPUT|> User input <|RESPONSE|> Model Response".split('<|RESPONSE|>')[-1]
|
32 |
+
```
|
33 |
+
|
34 |
+
|
35 |
+
## Usage
|
36 |
+
For more easy use, cosider downloading scripts from my repo https://github.com/jinymusim/DialogSystem
|
37 |
+
Then use the included classes as follows.
|
38 |
+
|
39 |
+
|
40 |
+
```python
|
41 |
+
from utils.dialog_model import DialogModel
|
42 |
+
from transformers import AutoTokenizer
|
43 |
+
|
44 |
+
model = DialogModel('jinymusim/RPGPT', resize_now=False)
|
45 |
+
tok = AutoTokenizer.from_pretrained('jinymusim/RPGPT')
|
46 |
+
tok.model_max_length = 1024
|
47 |
+
|
48 |
+
char_name ="James Smith"
|
49 |
+
bio="Age: 30, Gender: Male, Hobies: Training language models"
|
50 |
+
model.set_character(char_name, bio)
|
51 |
+
|
52 |
+
print(model.generate_self(tok)) # For Random generation
|
53 |
+
print(model.generate(tok, input("USER>").strip())) # For user input converasion
|
54 |
+
```
|
55 |
+
|
56 |
+
Other wise use standard huggingface interface
|
57 |
+
|
58 |
+
```python
|
59 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
60 |
+
|
61 |
+
model = AutoModelForCausalLM('jinymusim/RPGPT')
|
62 |
+
tok = AutoTokenizer.from_pretrained('jinymusim/RPGPT')
|
63 |
+
tok.model_max_length = 1024
|
64 |
+
char_name ="James Smith"
|
65 |
+
bio="Age: 30, Gender: Male, Hobies: Training language models"
|
66 |
+
context = []
|
67 |
+
input_ids = tok.encode(f"<|CHAR|> {char_name}, Bio: {bio} <|CONTEXT|> {' '.join(context} <|INPUT|> {input('USER>')}")
|
68 |
+
|
69 |
+
response_out = model.generate(input_ids,
|
70 |
+
max_new_tokens= 150,
|
71 |
+
do_sample=True,
|
72 |
+
top_k=50,
|
73 |
+
early_stopping=True,
|
74 |
+
eos_token_id=tokenizer.eos_token_id,
|
75 |
+
pad_token_id=tokenizer.pad_token_id)
|
76 |
+
|
77 |
+
print(response_out)
|
78 |
+
```
|
79 |
+
|