Views
No views yet
emotional-gpt2-medium is a GPT-2 Medium
causal language model fine-tuned for emotion-conditioned dialogue generation
with DailyDialog-derived data.Mario-RC/emotional-gptgpt2-mediumGPT2LMHeadModel| Model | Base model | Parameters | Evaluation perplexity |
|---|---|---|---|
| Emotional DistilGPT2 | distilgpt2 | 81.9M | 15.3322 |
| Emotional GPT-2 | gpt2 | 124.4M | 12.9404 |
| Emotional GPT-2 Medium | gpt2-medium | 354.8M | 10.0080 |
| Emotional GPT-2 Large | gpt2-large | 774.0M | 7.4115 |
| Emotional DialoGPT Small | microsoft/DialoGPT-small | 124.4M | 13.0488 |
| Emotional DialoGPT Medium | microsoft/DialoGPT-medium | 354.8M | 10.5130 |
| Emotional DialoGPT Large | microsoft/DialoGPT-large | 774.0M | 8.6719 |
data/gpt-dialogues/train.txt; evaluation data: data/gpt-dialogues/dev.txt, built from DailyDialog CSV resources1e-51.042<bos><source_emotion>source utterance<sep><target_emotion>target utterance<|endoftext|><bos><source_emotion>source utterance<sep><target_emotion><bos> marks the beginning of one formatted dialogue example.<source_emotion> is a placeholder for one emotion label describing the input/source utterance, for example <fear>.source utterance is the user/input text.<sep> separates the source side from the response side.<target_emotion> is a placeholder for the emotion you want the generated response to follow, for example <happiness>.target utterance is the response text generated by the model.<|endoftext|> marks the end of one example. GPT-2 uses this as its native end-of-text/eos token, and generation can stop when this token is produced.<source_emotion> and <target_emotion> in the
template with one of the model's literal emotion tokens in each position.<no emotion><anger><disgust><fear><happiness><sadness><surprise><bos><fear>I just started a new job and I am a bit nervous.<sep><happiness>fear, and the requested response
should be conditioned toward happiness.1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3repo_id = "mario-rc/emotional-gpt2-medium"
4
5tokenizer = AutoTokenizer.from_pretrained(repo_id)
6model = AutoModelForCausalLM.from_pretrained(repo_id)
7model.config.pad_token_id = tokenizer.pad_token_id
8
9prompt = "<bos><fear>I just started a new job and I am a bit nervous.<sep><happiness>"
10inputs = tokenizer(prompt, return_tensors="pt")
11
12outputs = model.generate(
13 **inputs,
14 do_sample=True,
15 max_new_tokens=80,
16 temperature=0.8,
17 top_p=0.95,
18 pad_token_id=tokenizer.pad_token_id,
19 eos_token_id=tokenizer.eos_token_id,
20)
21
22generated = outputs[0][inputs["input_ids"].shape[-1]:]
23response = tokenizer.decode(generated, skip_special_tokens=False)
24response = response.split(tokenizer.eos_token, 1)[0].strip()
25
26emotion_labels = [
27 "<no emotion>",
28 "<anger>",
29 "<disgust>",
30 "<fear>",
31 "<happiness>",
32 "<sadness>",
33 "<surprise>",
34]
35
36for label in emotion_labels:
37 if response.startswith(label):
38 response = response[len(label):].strip()
39 break
40
41print(response)