njvdnbus commited on
Commit
37da7cb
1 Parent(s): b6895c1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -3
README.md CHANGED
@@ -17,6 +17,22 @@ metrics:
17
  > reading, video games, walking
18
 
19
  ### How to use in code
20
- `from transformers import AutoTokenizer, AutoModelForSeq2SeqLM`\
21
- `tokenizer = AutoTokenizer.from_pretrained("njvdnbus/Interest_extraction")`\
22
- `model = AutoModelForSeq2SeqLM.from_pretrained("njvdnbus/Interest_extraction")`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  > reading, video games, walking
18
 
19
  ### How to use in code
20
+ ```{python}
21
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
22
+ tokenizer = AutoTokenizer.from_pretrained("njvdnbus/Interest_extraction")
23
+ model = AutoModelForSeq2SeqLM.from_pretrained("njvdnbus/Interest_extraction")
24
+
25
+ def use_model(text):
26
+ inputs = ["summarize: " + text]
27
+ inputs = tokenizer(inputs, truncation=True, return_tensors="pt")
28
+ output = model.generate(**inputs, num_beams=1, do_sample=True, min_length=1, max_length=64)
29
+ decoded_output = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
30
+ predicted_interests = nltk.sent_tokenize(decoded_output.strip())[0]
31
+ return predicted_interests
32
+
33
+ text= '''What other hobbies do you have?
34
+ When I have time I like to cook for my family. Most often this only happens in the weekends.'''
35
+ print(use_model(text))
36
+ ```
37
+
38
+ > cooking