Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- squad_v2
|
5 |
+
language:
|
6 |
+
- en
|
7 |
+
library_name: transformers
|
8 |
+
pipeline_tag: text-classification
|
9 |
+
inference: false
|
10 |
+
---
|
11 |
+
# longformer-large-4096 fine-tuned to SQuAD2.0 for answerability score
|
12 |
+
This model determines whether the question is answerable (or unanswerable) given the context.
|
13 |
+
The output is a probability where values close to 0.0 indicate that the question is unanswerable and values close to 1.0 means answerable.
|
14 |
+
|
15 |
+
- Input: `question` and `context`
|
16 |
+
- Output: `probability` (i.e. logit -> sigmoid)
|
17 |
+
|
18 |
+
## Model Details
|
19 |
+
|
20 |
+
longformer-large-4096 model is fine-tuned to the SQuAD2.0 dataset where the input is a concatenation of ```question + context```.
|
21 |
+
Due to class imbalance in SQuAD2.0, we resample such that the model is trained on a 50/50 split between answerable and unanswerable samples in SQuAD2.0.
|
22 |
+
|
23 |
+
## How to Use the Model
|
24 |
+
|
25 |
+
Use the code below to get started with the model.
|
26 |
+
|
27 |
+
```python
|
28 |
+
>>> import torch
|
29 |
+
>>> from transformers import LongformerTokenizer, LongformerForSequenceClassification
|
30 |
+
|
31 |
+
>>> tokenizer = LongformerTokenizer.from_pretrained("potsawee/longformer-large-4096-answerable-squad2")
|
32 |
+
>>> model = LongformerForSequenceClassification.from_pretrained("potsawee/longformer-large-4096-answerable-squad2")
|
33 |
+
|
34 |
+
>>> context = """
|
35 |
+
British government ministers have been banned from using Chinese-owned social media app TikTok on their work phones and devices on security grounds.
|
36 |
+
The government fears sensitive data held on official phones could be accessed by the Chinese government.
|
37 |
+
Cabinet Minister Oliver Dowden said the ban was a "precautionary" move but would come into effect immediately.
|
38 |
+
""".replace("\n", " ").strip()
|
39 |
+
|
40 |
+
>>> question1 = "Which application have been banned by the British government?"
|
41 |
+
>>> input_text1 = question1 + ' ' + tokenizer.sep_token + ' ' + context
|
42 |
+
>>> inputs1 = tokenizer(input_text1, max_length=4096, truncation=True, return_tensors="pt")
|
43 |
+
>>> prob1 = torch.sigmoid(model(**inputs1).logits.squeeze(-1))
|
44 |
+
>>> print("P(answerable|question1, context) = {:.2f}%".format(prob1.item()*100))
|
45 |
+
P(answerable|question1, context) = 99.21% # highly answerable
|
46 |
+
|
47 |
+
>>> question2 = "Is Facebook popular among young students in America?"
|
48 |
+
>>> input_text2 = question2 + ' ' + tokenizer.sep_token + ' ' + context
|
49 |
+
>>> inputs2 = tokenizer(input_text2, max_length=4096, truncation=True, return_tensors="pt")
|
50 |
+
>>> prob2 = torch.sigmoid(model(**inputs2).logits.squeeze(-1))
|
51 |
+
>>> print("P(answerable|question2, context) = {:.2f}%".format(prob2.item()*100))
|
52 |
+
P(answerable|question2, context) = 2.53% # highly unanswerable
|
53 |
+
```
|
54 |
+
|
55 |
+
## Citation
|
56 |
+
|
57 |
+
```bibtex
|
58 |
+
@misc{manakul2023selfcheckgpt,
|
59 |
+
title={SelfCheckGPT: Zero-Resource Black-Box Hallucination Detection for Generative Large Language Models},
|
60 |
+
author={Potsawee Manakul and Adian Liusie and Mark J. F. Gales},
|
61 |
+
year={2023},
|
62 |
+
eprint={2303.08896},
|
63 |
+
archivePrefix={arXiv},
|
64 |
+
primaryClass={cs.CL}
|
65 |
+
}
|
66 |
+
```
|