Update README.md
Browse files
README.md
CHANGED
@@ -13,10 +13,12 @@ It is the main model from the paper (see **"T5-11B w. ANLI + TrueTeacher full"**
|
|
13 |
|
14 |
The input format for the model is: "premise: GROUNDING_DOCUMENT hypothesis: HYPOTHESIS_SUMMARY".
|
15 |
|
|
|
|
|
16 |
The model predicts a binary label ('1' - Factualy Consistent, '0' - Factualy Inconsistent).
|
17 |
|
18 |
|
19 |
-
## Usage example:
|
20 |
```python
|
21 |
from transformers import T5ForConditionalGeneration
|
22 |
from transformers import T5Tokenizer
|
@@ -28,7 +30,11 @@ model = T5ForConditionalGeneration.from_pretrained(model_path)
|
|
28 |
premise = 'the sun is shining'
|
29 |
for hypothesis, expected in [('the sun is out in the sky', '1'),
|
30 |
('the cat is shiny', '0')]:
|
31 |
-
input_ids = tokenizer(
|
|
|
|
|
|
|
|
|
32 |
outputs = model.generate(input_ids)
|
33 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
34 |
print(f'premise: {premise}')
|
@@ -36,6 +42,35 @@ for hypothesis, expected in [('the sun is out in the sky', '1'),
|
|
36 |
print(f'result: {result} (expected: {expected})\n')
|
37 |
```
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
## Citation
|
40 |
|
41 |
If you use this model for a research publication, please cite the TrueTeacher paper (using the bibtex entry below) and the dataset papers mentioned above.
|
|
|
13 |
|
14 |
The input format for the model is: "premise: GROUNDING_DOCUMENT hypothesis: HYPOTHESIS_SUMMARY".
|
15 |
|
16 |
+
To accomodate the input length of common summarization datasets we recommend setting **max_length** to **2048**.
|
17 |
+
|
18 |
The model predicts a binary label ('1' - Factualy Consistent, '0' - Factualy Inconsistent).
|
19 |
|
20 |
|
21 |
+
## Usage example - classifiaction:
|
22 |
```python
|
23 |
from transformers import T5ForConditionalGeneration
|
24 |
from transformers import T5Tokenizer
|
|
|
30 |
premise = 'the sun is shining'
|
31 |
for hypothesis, expected in [('the sun is out in the sky', '1'),
|
32 |
('the cat is shiny', '0')]:
|
33 |
+
input_ids = tokenizer(
|
34 |
+
f'premise: {premise} hypothesis: {hypothesis}',
|
35 |
+
return_tensors='pt',
|
36 |
+
truncation=True,
|
37 |
+
max_length=2048).input_ids
|
38 |
outputs = model.generate(input_ids)
|
39 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
40 |
print(f'premise: {premise}')
|
|
|
42 |
print(f'result: {result} (expected: {expected})\n')
|
43 |
```
|
44 |
|
45 |
+
## Usage example - scoring:
|
46 |
+
```python
|
47 |
+
from transformers import T5ForConditionalGeneration
|
48 |
+
from transformers import T5Tokenizer
|
49 |
+
import torch
|
50 |
+
|
51 |
+
model_path = 'google/t5_11b_trueteacher_and_anli'
|
52 |
+
tokenizer = T5Tokenizer.from_pretrained(model_path)
|
53 |
+
model = T5ForConditionalGeneration.from_pretrained(model_path)
|
54 |
+
|
55 |
+
premise = 'the sun is shining'
|
56 |
+
for hypothesis, expected in [('the sun is out in the sky', '>> 0.5'),
|
57 |
+
('the cat is shiny', '<< 0.5')]:
|
58 |
+
input_ids = tokenizer(
|
59 |
+
f'premise: {premise} hypothesis: {hypothesis}',
|
60 |
+
return_tensors='pt',
|
61 |
+
truncation=True,
|
62 |
+
max_length=2048).input_ids
|
63 |
+
decoder_input_ids = torch.tensor([[tokenizer.pad_token_id]])
|
64 |
+
outputs = model(input_ids=input_ids, decoder_input_ids=decoder_input_ids)
|
65 |
+
logits = outputs.logits
|
66 |
+
probs = torch.softmax(logits[0], dim=-1)
|
67 |
+
one_token_id = tokenizer('1').input_ids[0]
|
68 |
+
entailment_prob = probs[0, one_token_id].item()
|
69 |
+
print(f'premise: {premise}')
|
70 |
+
print(f'hypothesis: {hypothesis}')
|
71 |
+
print(f'score: {entailment_prob:.3f} (expected: {expected})\n')
|
72 |
+
```
|
73 |
+
|
74 |
## Citation
|
75 |
|
76 |
If you use this model for a research publication, please cite the TrueTeacher paper (using the bibtex entry below) and the dataset papers mentioned above.
|