Instructions to use fares7elsadek/t5-large-distractor-generation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use fares7elsadek/t5-large-distractor-generation with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="fares7elsadek/t5-large-distractor-generation")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("fares7elsadek/t5-large-distractor-generation") model = AutoModelForSeq2SeqLM.from_pretrained("fares7elsadek/t5-large-distractor-generation") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use fares7elsadek/t5-large-distractor-generation with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "fares7elsadek/t5-large-distractor-generation" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "fares7elsadek/t5-large-distractor-generation", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/fares7elsadek/t5-large-distractor-generation
- SGLang
How to use fares7elsadek/t5-large-distractor-generation with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "fares7elsadek/t5-large-distractor-generation" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "fares7elsadek/t5-large-distractor-generation", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "fares7elsadek/t5-large-distractor-generation" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "fares7elsadek/t5-large-distractor-generation", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use fares7elsadek/t5-large-distractor-generation with Docker Model Runner:
docker model run hf.co/fares7elsadek/t5-large-distractor-generation
YAML Metadata Warning:The pipeline tag "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other
Distractor Generation with T5-large
This repository contains a T5-large model fine-tuned for distractor generation. Leveraging T5’s text-to-text framework and a custom separator token, the model generates three plausible distractors for multiple-choice questions by conditioning on a given question, context, and correct answer.
Model Overview
Built with PyTorch Lightning, this implementation fine-tunes the pre-trained T5-base model to generate distractor options. The model takes a single input sequence formatted with the question, context, and correct answer—separated by a custom token—and generates a target sequence containing three distractors. This approach is particularly useful for multiple-choice question generation tasks.
Data Processing
Input Construction
Each input sample is a single string with the following format:
question {SEP_TOKEN} correct {SEP_TOKEN} context
- question: The question text.
- context: The context passage.
- correct: The correct answer.
- SEP_TOKEN: A special token added to the tokenizer to separate the different fields.
Target Construction
Each target sample is constructed as follows:
incorrect1 {SEP_TOKEN} incorrect2 {SEP_TOKEN} incorrect3
This format allows the model to generate three distractors in one pass.
Training Details
- Framework: PyTorch Lightning
- Base Model: T5-base
- Optimizer: Adam with linear scheduling (using a warmup scheduler)
- Batch Size: 32
- Number of Epochs: 5
- Learning Rate: 2e-5
- Tokenization:
- Input: Maximum length of 512 tokens
- Target: Maximum length of 64 tokens
- Special Tokens: The custom
SEP_TOKENis added to the tokenizer and is used to separate different parts of the input and target sequences.
Evaluation Metrics
The model is evaluated using BLEU scores for each generated distractor. Below are the BLEU scores obtained on the test set:
| 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 |
These scores indicate that the model is capable of generating distractors with high n‑gram overlap compared to reference distractors.
How to Use
You can use this model with Hugging Face's Transformers pipeline as follows:
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model_name = "fares7elsadek/t5-large-distractor-generation"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
SEP_TOKEN = "<sep>"
def generate_distractors(question, context, correct, max_length=64):
input_text = f"{question}{SEP_TOKEN}{correct}{SEP_TOKEN}{context}"
inputs = tokenizer([input_text], return_tensors="pt", truncation=True, padding=True)
outputs = model.generate(
input_ids=inputs["input_ids"],
attention_mask=inputs["attention_mask"],
max_length=max_length
)
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
distractors = [d.strip() for d in decoded.split(SEP_TOKEN)]
return distractors
# Example usage:
question = "What is the capital of France?"
context = "France is a country in Western Europe known for its rich history and cultural heritage."
correct = "Paris"
print(generate_distractors(question, context, correct))
- Downloads last month
- 8
Model tree for fares7elsadek/t5-large-distractor-generation
Base model
google-t5/t5-large