Views
No views yet
question {SEP_TOKEN} correct {SEP_TOKEN} contextincorrect1 {SEP_TOKEN} incorrect2 {SEP_TOKEN} incorrect3SEP_TOKEN is added to the tokenizer and is used to separate different parts of the input and target sequences.| Distractor | BLEU-1 | BLEU-2 | BLEU-3 | BLEU-4 |
|---|---|---|---|---|
| Distractor 1 | 32.29 | 23.85 | 19.86 | 17.53 |
| Distractor 2 | 26.70 | 17.76 | 14.01 | 11.77 |
| Distractor 3 | 23.63 | 14.89 | 11.29 | 9.41 |
1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
3model_name = "fares7elsadek/t5-large-distractor-generation"
4tokenizer = AutoTokenizer.from_pretrained(model_name)
5model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
6
7SEP_TOKEN = "<sep>"
8
9def generate_distractors(question, context, correct, max_length=64):
10 input_text = f"{question}{SEP_TOKEN}{correct}{SEP_TOKEN}{context}"
11 inputs = tokenizer([input_text], return_tensors="pt", truncation=True, padding=True)
12 outputs = model.generate(
13 input_ids=inputs["input_ids"],
14 attention_mask=inputs["attention_mask"],
15 max_length=max_length
16 )
17
18 decoded = tokenizer.decode(outputs[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
19 distractors = [d.strip() for d in decoded.split(SEP_TOKEN)]
20 return distractors
21
22# Example usage:
23question = "What is the capital of France?"
24context = "France is a country in Western Europe known for its rich history and cultural heritage."
25correct = "Paris"
26print(generate_distractors(question, context, correct))