Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from FiDT5 import FiDT5
|
2 |
+
from transformers import T5Tokenizer
|
3 |
+
model = FiDT5.from_pretrained('Soyoung97/ListT5-base')
|
4 |
+
texts = ["Query: When did Thomas Edison invent the light bulb?, Index: 1, Context: Lightning strike at Seoul National University",
|
5 |
+
"Query: When did Thomas Edison invent the light bulb?, Index: 2, Context: Thomas Edison tried to invent a device for car but failed",
|
6 |
+
"Query: When did Thomas Edison invent the light bulb?, Index: 3, Context: Coffee is good for diet",
|
7 |
+
"Query: When did Thomas Edison invent the light bulb?, Index: 4, Context: KEPCO fixes light problems",
|
8 |
+
"Query: When did Thomas Edison invent the light bulb?, Index: 5, Context: Thomas Edison invented the light bulb in 1879"]
|
9 |
+
tok = T5Tokenizer.from_pretrained('t5-base')
|
10 |
+
raw = tok(texts, return_tensors='pt', padding='max_length', max_length=128, truncation=True)
|
11 |
+
input_tensors = {'input_ids': raw['input_ids'].unsqueeze(0), 'attention_mask': raw['attention_mask'].unsqueeze(0)}
|
12 |
+
output = model.generate(**input_tensors, max_length=128, return_dict_in_generate=True, output_scores=True)
|
13 |
+
output_text = tok.batch_decode(output.sequences, skip_special_tokens=True)
|
14 |
+
output_text
|
15 |
+
>>> [3 1 4 2 5]
|