ejjaffe commited on
Commit
a8d9222
·
1 Parent(s): c98b0e0

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +28 -0
README.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Load the Model
2
+ ```python
3
+ from transformers import GPT2Tokenizer, GPT2LMHeadModel
4
+ import torch
5
+
6
+ # start and end tokens for generation
7
+ START_TKN = "<|startoftext|>"
8
+ END_TKN = "<|endoftext|>"
9
+
10
+ # fine tuned on onion dataset w/ distilgpt2
11
+ tokenizer = GPT2Tokenizer.from_pretrained("distilgpt2")
12
+ model = GPT2LMHeadModel.from_pretrained("distilgpt2")
13
+
14
+ # use gpu if available
15
+ device = "cpu"
16
+ if torch.cuda.is_available():
17
+ device = "cuda"
18
+
19
+ model = model.to(device)
20
+
21
+ # get 70th epoch (decent results)
22
+ epoch = 70
23
+ modelpath = f'distilgpt2_onion_{epoch}.pt'
24
+
25
+ # load model
26
+ model.load_state_dict(torch.load(modelpath))
27
+ ```
28
+