Text Classification
Transformers
Safetensors
English
roberta
distractor-evaluation
multiple-choice-questions
reading-comprehension
education
regression
text-embeddings-inference
Instructions to use bilalghanem/DISTO with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use bilalghanem/DISTO with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="bilalghanem/DISTO")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("bilalghanem/DISTO") model = AutoModelForSequenceClassification.from_pretrained("bilalghanem/DISTO", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add DISTO model, tokenizer, model card and paper
Browse files- .gitattributes +1 -0
- DISTO_EDM2024.pdf +3 -0
- README.md +121 -0
- config.json +34 -0
- model.safetensors +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +17 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
DISTO_EDM2024.pdf filter=lfs diff=lfs merge=lfs -text
|
DISTO_EDM2024.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a84b07935788fd3a5da01fbf46368bf7d5a6c851b36aa2acc8412096e3f9ba0e
|
| 3 |
+
size 559816
|
README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
library_name: transformers
|
| 5 |
+
pipeline_tag: text-classification
|
| 6 |
+
base_model: distilroberta-base
|
| 7 |
+
tags:
|
| 8 |
+
- distractor-evaluation
|
| 9 |
+
- multiple-choice-questions
|
| 10 |
+
- reading-comprehension
|
| 11 |
+
- education
|
| 12 |
+
- regression
|
| 13 |
+
datasets:
|
| 14 |
+
- cosmos_qa
|
| 15 |
+
- dream
|
| 16 |
+
- race
|
| 17 |
+
- sciq
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# DISTO
|
| 21 |
+
|
| 22 |
+
DISTO is a learned metric for the quality of **distractors** in multiple-choice reading comprehension
|
| 23 |
+
questions. Given an article, a question, the correct answer and up to three distractors, it returns a score
|
| 24 |
+
in `[0, 1]`: higher means the distractors are more plausible in context. It needs no reference distractors.
|
| 25 |
+
|
| 26 |
+
- **Paper:** [DISTO: Textual Distractors for Multiple Choice Reading Comprehension Questions Using Negative Sampling](DISTO_EDM2024.pdf) (EDM 2024)
|
| 27 |
+
- **Code:** https://github.com/bilalghanem/DISTO
|
| 28 |
+
|
| 29 |
+
## How to run
|
| 30 |
+
|
| 31 |
+
### Option 1: the `disto` package (recommended)
|
| 32 |
+
|
| 33 |
+
```bash
|
| 34 |
+
pip install git+https://github.com/bilalghanem/DISTO.git
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
from disto import DistoScorer
|
| 39 |
+
|
| 40 |
+
scorer = DistoScorer("bilalghanem/DISTO") # downloads the model from the Hub
|
| 41 |
+
|
| 42 |
+
article = "The Nile is the longest river in Africa. It flows north through Egypt into the Mediterranean Sea."
|
| 43 |
+
question = "Where does the Nile flow into?"
|
| 44 |
+
answer = "The Mediterranean Sea"
|
| 45 |
+
|
| 46 |
+
# Score the whole set of up to three distractors in one pass
|
| 47 |
+
print(scorer.score(article, question, answer, ["The Red Sea", "The Atlantic Ocean", "Lake Victoria"])) # ~0.99
|
| 48 |
+
|
| 49 |
+
# A distractor that copies the answer or is unrelated scores low
|
| 50 |
+
print(scorer.score(article, question, answer, ["The Mediterranean Sea", "A bowl of soup", "Tuesday"])) # ~0.01
|
| 51 |
+
|
| 52 |
+
# Score each distractor on its own and average, as in the paper
|
| 53 |
+
scores = scorer.score_each(article, question, answer, ["The Red Sea", "The Atlantic Ocean", "Lake Victoria"])
|
| 54 |
+
print(sum(scores) / len(scores))
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
### Option 2: plain `transformers`
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
import torch
|
| 61 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 62 |
+
|
| 63 |
+
tokenizer = AutoTokenizer.from_pretrained("bilalghanem/DISTO")
|
| 64 |
+
model = AutoModelForSequenceClassification.from_pretrained("bilalghanem/DISTO").eval()
|
| 65 |
+
|
| 66 |
+
text = (
|
| 67 |
+
"[QUES] Where does the Nile flow into? "
|
| 68 |
+
"[ANS] The Mediterranean Sea "
|
| 69 |
+
"[DIS1] The Red Sea [DIS2] The Atlantic Ocean [DIS3] Lake Victoria "
|
| 70 |
+
"[ART] The Nile is the longest river in Africa. It flows north through Egypt into the Mediterranean Sea."
|
| 71 |
+
)
|
| 72 |
+
inputs = tokenizer(text, truncation=True, max_length=512, return_tensors="pt")
|
| 73 |
+
with torch.no_grad():
|
| 74 |
+
score = torch.sigmoid(model(**inputs).logits).item() # the sigmoid is not part of the model
|
| 75 |
+
print(score)
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
### Input format
|
| 79 |
+
|
| 80 |
+
The input is `[QUES] question [ANS] answer [DIS1] d1 [DIS2] d2 [DIS3] d3 [ART] article`. Fill missing
|
| 81 |
+
distractors with `[EMPT]` (the paper's single-distractor setting is one distractor in `[DIS1]` and
|
| 82 |
+
`[EMPT]` in the other two). Put the article last, since only the article is cut at 512 tokens. The Hub
|
| 83 |
+
inference widget does not build this format or apply the sigmoid, so use one of the options above.
|
| 84 |
+
|
| 85 |
+
## Model details
|
| 86 |
+
|
| 87 |
+
- Architecture: `distilroberta-base` with a single-output regression head (`RobertaForSequenceClassification`,
|
| 88 |
+
`num_labels=1`) and a sigmoid applied to the logit. Seven special tokens are added to the tokenizer.
|
| 89 |
+
- Max input length: 512 tokens (the article comes last and is the only part truncated).
|
| 90 |
+
- Training: MSE loss, AdamW, learning rate 3e-5, batch size 20, early stopping on validation loss.
|
| 91 |
+
- Training data: CosmosQA, DREAM, MCScript, MCTest, QuAIL, RACE and SciQ. Good distractors have a target of 1;
|
| 92 |
+
negative samples are built by copying the answer, drawing a random distractor, taking the farthest point of
|
| 93 |
+
the distractor's k-means cluster, or rewriting a distractor with BERT `[MASK]` filling.
|
| 94 |
+
|
| 95 |
+
## Evaluation
|
| 96 |
+
|
| 97 |
+
Held-out test split of the release (66,322 instances): MAE 0.0286, Pearson correlation 0.966.
|
| 98 |
+
|
| 99 |
+
In the paper, DISTO correlates with Amazon Mechanical Turk ratings of distractor quality at Pearson 0.81 on
|
| 100 |
+
gold and negatively sampled distractors, and between 0.28 and 0.75 on distractors produced by five
|
| 101 |
+
distractor generation models.
|
| 102 |
+
|
| 103 |
+
## Limitations
|
| 104 |
+
|
| 105 |
+
- The score reflects consistency with the context, learned from English reading-comprehension datasets. It is
|
| 106 |
+
not a replacement for review by an educator.
|
| 107 |
+
- Human agreement on this task is only moderate (Fleiss' kappa 0.45 in the paper's study).
|
| 108 |
+
- Only English has been tested, and only up to three distractors per question.
|
| 109 |
+
|
| 110 |
+
## Citation
|
| 111 |
+
|
| 112 |
+
```bibtex
|
| 113 |
+
@inproceedings{ghanem2024disto,
|
| 114 |
+
title = {{DISTO}: Textual Distractors for Multiple Choice Reading Comprehension Questions Using Negative Sampling},
|
| 115 |
+
author = {Ghanem, Bilal and Fyshe, Alona},
|
| 116 |
+
booktitle = {Proceedings of the 17th International Conference on Educational Data Mining},
|
| 117 |
+
pages = {6--17},
|
| 118 |
+
year = {2024},
|
| 119 |
+
doi = {10.5281/zenodo.12729766}
|
| 120 |
+
}
|
| 121 |
+
```
|
config.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_cross_attention": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"RobertaForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": 0,
|
| 8 |
+
"classifier_dropout": null,
|
| 9 |
+
"dtype": "float32",
|
| 10 |
+
"eos_token_id": 2,
|
| 11 |
+
"hidden_act": "gelu",
|
| 12 |
+
"hidden_dropout_prob": 0.1,
|
| 13 |
+
"hidden_size": 768,
|
| 14 |
+
"id2label": {
|
| 15 |
+
"0": "LABEL_0"
|
| 16 |
+
},
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 3072,
|
| 19 |
+
"is_decoder": false,
|
| 20 |
+
"label2id": {
|
| 21 |
+
"LABEL_0": 0
|
| 22 |
+
},
|
| 23 |
+
"layer_norm_eps": 1e-05,
|
| 24 |
+
"max_position_embeddings": 514,
|
| 25 |
+
"model_type": "roberta",
|
| 26 |
+
"num_attention_heads": 12,
|
| 27 |
+
"num_hidden_layers": 6,
|
| 28 |
+
"pad_token_id": 1,
|
| 29 |
+
"tie_word_embeddings": true,
|
| 30 |
+
"transformers_version": "5.18.0",
|
| 31 |
+
"type_vocab_size": 1,
|
| 32 |
+
"use_cache": true,
|
| 33 |
+
"vocab_size": 50272
|
| 34 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fe86a0fbb929517b41fb24f898f39b8045d48fef8bb120058fd696140b2639ea
|
| 3 |
+
size 328510708
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"cls_token": "<s>",
|
| 6 |
+
"eos_token": "</s>",
|
| 7 |
+
"errors": "replace",
|
| 8 |
+
"is_local": true,
|
| 9 |
+
"local_files_only": false,
|
| 10 |
+
"mask_token": "<mask>",
|
| 11 |
+
"model_max_length": 512,
|
| 12 |
+
"pad_token": "<pad>",
|
| 13 |
+
"sep_token": "</s>",
|
| 14 |
+
"tokenizer_class": "RobertaTokenizer",
|
| 15 |
+
"trim_offsets": true,
|
| 16 |
+
"unk_token": "<unk>"
|
| 17 |
+
}
|