Downloads · 30 days
4
7% of all-time downloads
maxhirez/question-paraphrase-t5
question-paraphrase-t5 is a machine learning model from maxhirez. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft. The card lists the license as apache-2.0.
LoRA fine-tune of Google-T5-base for generative question paraphrasing
Downloads · 30 days
4
7% of all-time downloads
All-time downloads
61
Public
Repo size
4.4 MB
Likes
0
Public
Click a slice to open those files.
.safetensors3.6 MB · 81%
From the Hugging Face model README
LoRA fine-tune of Google-T5-base for generative question paraphrasing
Originally develped as a proof-of-concept mechanism for preventing the sharing of knowledge check questions and answers in e-learning, generating on-the-fly paraphrasing of knowledge check questions so no two learners would see the same thing and could not effectively share questions/answers with others. The model was set aside. Its effectiveness for the task was never fully evaluated, though certain shortcomings were apparent in some circusmtances.
Noted tendency to switch POV (ie, "How do you do ABC?"->"How do I do ABC?") and in the case of questions requiring a high degree of regime expertise, paraphrases tended not to vary significantly from original source.
Experimentation is the only recommended use. If an effective use case is discovered, please let us know!
Use the code below to get started with the model.
import torch
from transformers import T5Tokenizer
from peft import PeftModel, PeftConfig
# Check for MPS availability (Apple Silicon)
device = torch.device("mps" if torch.backends.mps.is_available() else "cpu")
#CUDA
#device = torch.device("CUDA")
# Path to your saved model
model_path = "./question-paraphrase-T5"
tokenizer = T5Tokenizer.from_pretrained("t5-base")
config = PeftConfig.from_pretrained(model_path)
from transformers import AutoModelForSeq2SeqLM
model = AutoModelForSeq2SeqLM.from_pretrained(config.base_model_name_or_path)
model = PeftModel.from_pretrained(model, model_path)
model = model.to(device)
model.eval() # Set to evaluation mode
def generate_paraphrase(text):
"""Generate a paraphrase for the given text."""
input_text = f"paraphrase : {text}"
print(f"Input: {input_text}")
inputs = tokenizer(input_text, return_tensors="pt").to(device)
# Use keyword arguments for generate
with torch.no_grad():
outputs = model.generate(
input_ids=inputs.input_ids,
attention_mask=inputs.attention_mask,
max_length=128,
num_beams=4, # Use beam search for better quality
no_repeat_ngram_size=2, # Avoid repeating phrases
temperature=0.7 # Add some randomness for diversity
)
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
return result
# Interactive mode
print("\nInteractive Mode: Enter questions to paraphrase (type 'exit' to quit)")
while True:
user_input = input("\nEnter text to paraphrase: ")
if user_input.lower() == 'exit':
break
paraphrase = generate_paraphrase(user_input)
print(f"Paraphrase: {paraphrase}")
Used GLUE/mrpc and GLUE/qqp (cards not appearing on HF.)
Trained on Mac Studio M3 Ultra using metal shaders in torch.