svjack commited on
Commit
a897382
·
1 Parent(s): 07ed21f

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +54 -0
README.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ pipeline_tag: text2text-generation
5
+ ---
6
+
7
+ ```python
8
+ from transformers import T5ForConditionalGeneration
9
+ from transformers import T5TokenizerFast as T5Tokenizer
10
+ import pandas as pd
11
+ model = "svjack/comet-atomic-en"
12
+ device = "cpu"
13
+ #device = "cuda:0"
14
+ tokenizer = T5Tokenizer.from_pretrained(model)
15
+ model = T5ForConditionalGeneration.from_pretrained(model).to(device).eval()
16
+
17
+ NEED_PREFIX = 'What are the necessary preconditions for the next event?'
18
+ EFFECT_PREFIX = 'What could happen after the next event?'
19
+ INTENT_PREFIX = 'What is the motivation for the next event?'
20
+ REACT_PREFIX = 'What are your feelings after the following event?'
21
+
22
+
23
+ event = "X had a big meal."
24
+ for prefix in [NEED_PREFIX, EFFECT_PREFIX, INTENT_PREFIX, REACT_PREFIX]:
25
+ prompt = "{}{}".format(prefix, event)
26
+ encode = tokenizer(prompt, return_tensors='pt').to(device)
27
+ answer = model.generate(encode.input_ids,
28
+ max_length = 128,
29
+ num_beams=2,
30
+ top_p = 0.95,
31
+ top_k = 50,
32
+ repetition_penalty = 2.5,
33
+ length_penalty=1.0,
34
+ early_stopping=True,
35
+ )[0]
36
+ decoded = tokenizer.decode(answer, skip_special_tokens=True)
37
+ print(prompt, "\n---Answer:", decoded, "----\n")
38
+ ```
39
+
40
+ </br>
41
+
42
+ ```json
43
+ What are the necessary preconditions for the next event?X had a big meal.
44
+ ---Answer: X goes shopping at the supermarket ----
45
+
46
+ What could happen after the next event?X had a big meal.
47
+ ---Answer: X gets fat ----
48
+
49
+ What is the motivation for the next event?X had a big meal.
50
+ ---Answer: X wants to eat ----
51
+
52
+ What are your feelings after the following event?X had a big meal.
53
+ ---Answer: X tastes good ----
54
+ ```