Views
No views yet
1# Base GPT-2
2"""
3Epoch 1/5, Batch 1/10000: Loss - 64.9255, Reward - 260.0000, Penalty - 624.0000, BLEU - 0.0000
4Epoch 1/5, Batch 2/10000: Loss - 57.4635, Reward - 303.0000, Penalty - 870.0000, BLEU - 0.0000
5Epoch 1/5, Batch 3/10000: Loss - 67.8061, Reward - 295.0000, Penalty - 908.0000, BLEU - 0.0000
6Epoch 1/5, Batch 4/10000: Loss - 59.6118, Reward - 800.0000, Penalty - 740.0000, BLEU - 0.0000
7Epoch 1/5, Batch 5/10000: Loss - 67.4855, Reward - 402.0000, Penalty - 806.0000, BLEU - 0.0000
8Epoch 1/5, Batch 6/10000: Loss - 29.3718, Reward - 937.0000, Penalty - 760.0000, BLEU - 0.0000
9Epoch 1/5, Batch 7/10000: Loss - 79.0709, Reward - 390.0000, Penalty - 1114.0000, BLEU - 0.0000
10Epoch 1/5, Batch 8/10000: Loss - 61.4583, Reward - 385.0000, Penalty - 760.0000, BLEU - 0.0000
11Epoch 1/5, Batch 9/10000: Loss - 56.3084, Reward - 741.0000, Penalty - 560.0000, BLEU - 3.5500
12Epoch 1/5, Batch 10/10000: Loss - 80.0192, Reward - 838.0000, Penalty - 1424.0000, BLEU - 0.0000
13Epoch 1/5, Batch 11/10000: Loss - 51.8236, Reward - 228.0000, Penalty - 812.0000, BLEU - 0.0001
14Epoch 1/5, Batch 12/10000: Loss - 71.4071, Reward - 541.0000, Penalty - 982.0000, BLEU - 0.0000
15Epoch 1/5, Batch 13/10000: Loss - 33.3624, Reward - 910.0000, Penalty - 1002.0000, BLEU - 0.0027
16Epoch 1/5, Batch 14/10000: Loss - 55.9721, Reward - 808.0000, Penalty - 798.0000, BLEU - 0.0005
17Epoch 1/5, Batch 15/10000: Loss - 67.0336, Reward - 517.0000, Penalty - 764.0000, BLEU - 0.0000
18"""
19# Conversational GPT-2
20"""
21Epoch 1/5, Batch 1/10000: Loss - 6.1980, Reward - 887.0000, Penalty - 1500.0000, BLEU - 0.0648
22Epoch 1/5, Batch 2/10000: Loss - 4.5750, Reward - 245.0000, Penalty - 1618.0000, BLEU - 0.0008
23Epoch 1/5, Batch 3/10000: Loss - 5.1264, Reward - 600.0000, Penalty - 642.0000, BLEU - 5.7981
24Epoch 1/5, Batch 4/10000: Loss - 0.2995, Reward - 1020.0000, Penalty - 74.0000, BLEU - 13.8469
25Epoch 1/5, Batch 5/10000: Loss - 7.9377, Reward - 203.0000, Penalty - 1700.0000, BLEU - 0.3218
26Epoch 1/5, Batch 6/10000: Loss - 5.0522, Reward - 1020.0000, Penalty - 2034.0000, BLEU - 0.1946
27Epoch 1/5, Batch 7/10000: Loss - 2.0585, Reward - 925.0000, Penalty - 526.0000, BLEU - 16.1298
28Epoch 1/5, Batch 8/10000: Loss - 5.9736, Reward - 1009.0000, Penalty - 1844.0000, BLEU - 0.0085
29Epoch 1/5, Batch 9/10000: Loss - 6.0867, Reward - 245.0000, Penalty - 1690.0000, BLEU - 1.9342
30Epoch 1/5, Batch 10/10000: Loss - 7.8497, Reward - 155.0000, Penalty - 1780.0000, BLEU - 0.0115
31Epoch 1/5, Batch 11/10000: Loss - 3.8887, Reward - 1012.0000, Penalty - 2010.0000, BLEU - 0.6957
32Epoch 1/5, Batch 12/10000: Loss - 6.6133, Reward - 216.0000, Penalty - 1638.0000, BLEU - 1.7853
33Epoch 1/5, Batch 13/10000: Loss - 1.3319, Reward - 945.0000, Penalty - 374.0000, BLEU - 0.0075
34Epoch 1/5, Batch 14/10000: Loss - 2.6296, Reward - 956.0000, Penalty - 414.0000, BLEU - 3.2207
35Epoch 1/5, Batch 15/10000: Loss - 6.8827, Reward - 1013.0000, Penalty - 1970.0000, BLEU - 3.7418
36"""1import torch
2from transformers import GPT2Tokenizer, GPT2LMHeadModel
3
4tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
5model = GPT2LMHeadModel.from_pretrained('gpt2')
6tokenizer.add_special_tokens({'pad_token': '[PAD]'})
7tokenizer.add_special_tokens({'eos_token': '<|End|>'})
8special_tokens = {
9 "additional_special_tokens": ["<|USER|>", "<|SYSTEM|>", "<|ASSISTANT|>"]
10}
11tokenizer.add_special_tokens(special_tokens)
12model.resize_token_embeddings(len(tokenizer))
13model.load_state_dict(torch.load("path/to/model"))
14device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
15model.to(device)
16def generate_text(model, tokenizer, prompt, max_length=1024):
17 prompt = f'<|USER|> {prompt} <|ASSISTANT|> '
18 input_ids = tokenizer.encode(prompt, add_special_tokens=True, return_tensors="pt").to(device)
19 attention_mask = torch.ones_like(input_ids).to(device)
20 output = model.generate(input_ids,
21 max_length=max_length,
22 do_sample=True,
23 top_k=35,
24 top_p=0.80,
25 pad_token_id=tokenizer.pad_token_id,
26 eos_token_id=tokenizer.eos_token_id,
27 attention_mask=attention_mask)
28 output_ids = tokenizer.decode(output[0], skip_special_tokens=False)
29 assistant_token_index = output_ids.index('<|ASSISTANT|>') + len('<|ASSISTANT|>')
30 next_token_index = output_ids.find('<|', assistant_token_index)
31 output_ids = output_ids[assistant_token_index:next_token_index]
32 return output_ids
33# Loop to interact with the model
34while True:
35 prompt = input("Enter a prompt (or 'q' to quit): ")
36 if prompt == "q":
37 break
38 output_text = generate_text(model, tokenizer, prompt)
39 print(output_text)"<|USER|> {user prompt} <|ASSISTANT|> {model prediction} <|End|>". For the best performance from the model the input text should be as follows <|USER|> {user prompt} <|ASSISTANT|> and the target/label should be as follows <|USER|> {user prompt} <|ASSISTANT|> {dataset output} <|End|>| Metric | Value |
|---|---|
| Avg. | 25.09 |
| ARC (25-shot) | 21.42 |
| HellaSwag (10-shot) | 27.61 |
| MMLU (5-shot) | 26.51 |
| TruthfulQA (0-shot) | 47.31 |
| Winogrande (5-shot) | 51.14 |
| GSM8K (5-shot) | 0.08 |
| DROP (3-shot) | 1.55 |