skhatri commited on
Commit
cff32ca
1 Parent(s): 9b26363

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +32 -0
README.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Code to test this model.
2
+
3
+ ```
4
+ import torch
5
+ import time
6
+
7
+ device_name="cuda" if torch.cuda.is_available() else "cpu"
8
+ device = torch.device(device_name)
9
+
10
+ model_name="skhatri/distilgpt2med"
11
+ from transformers import AutoTokenizer, AutoModelForCausalLM
12
+
13
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
14
+ model = AutoModelForCausalLM.from_pretrained(model_name)
15
+ model.to(device)
16
+
17
+ raw_input = "Headache Cough"
18
+
19
+ import sys
20
+ if len(sys.argv) > 1:
21
+ raw_input = sys.argv[1]
22
+
23
+ start=time.time()
24
+
25
+ input_ids = tokenizer.encode(raw_input, return_tensors='pt').to(device)
26
+ output = model.generate(input_ids)
27
+
28
+ response = tokenizer.decode(output[0], skip_special_tokens=True)
29
+ print(response)
30
+ end=time.time()
31
+ print(f'Time taken: {round(end - start, 2)} seconds')
32
+ ```