Ateeqq commited on
Commit
03c638b
1 Parent(s): bc38ab3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +37 -1
README.md CHANGED
@@ -24,4 +24,40 @@ widget:
24
  example_title: Example 3
25
  ---
26
 
27
- # Generate Title using Keywords
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  example_title: Example 3
25
  ---
26
 
27
+ # Generate Title using Keywords
28
+
29
+ ## How to use
30
+
31
+ ```python
32
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
33
+
34
+ device = "cuda"
35
+ tokenizer = AutoTokenizer.from_pretrained("Ateeqq/keywords-title-generator", token='your_token')
36
+ model = AutoModelForSeq2SeqLM.from_pretrained("Ateeqq/keywords-title-generator", token='your_token').to(device)
37
+
38
+ def generate_title(question):
39
+ input_ids = tokenizer(f'generate title: {question}', return_tensors="pt", padding="longest", truncation=True, max_length=24).input_ids.to(device)
40
+ outputs = model.generate(
41
+ input_ids,
42
+ num_beams=5,
43
+ num_beam_groups=5,
44
+ num_return_sequences=5,
45
+ repetition_penalty=10.0,
46
+ diversity_penalty=3.0,
47
+ no_repeat_ngram_size=2,
48
+ temperature=0.7,
49
+ max_length=24
50
+ )
51
+ return tokenizer.batch_decode(outputs, skip_special_tokens=True)
52
+
53
+ text = 'book, history, kids'
54
+ generate_title(text)
55
+ ```
56
+ ### Output:
57
+ ```
58
+ ['How to Write a Book About History for Kids',
59
+ 'The book that taught me how to write history for kids',
60
+ 'Why I wrote this book about history for kids',
61
+ 'A Book About History That Will Help Your Kids Understand',
62
+ 'This is a Book About History that I recommend to my kids']
63
+ ```