Downloads · 30 days
31
2% of all-time downloads
thenHung/question_decomposer_t5
question_decomposer_t5 is a text generation model from thenHung. Use it when you need the model to write or continue text.
Example: What is the capital of France and when it entablish ?
Downloads · 30 days
31
2% of all-time downloads
All-time downloads
1.9K
Public
Parameters
60.5M
243 MB on disk
Likes
4
Public
Click a slice to open those files.
.safetensors242 MB · 100%
From the Hugging Face model README
Example: What is the capital of France and when it entablish ?
Checkout my demo here 👉🏻 demo
from transformers import T5Tokenizer, T5ForConditionalGeneration
import torch
# Set device
device = "mps" if torch.backends.mps.is_available() else "cuda" if torch.cuda.is_available() else "cpu"
# Load model and tokenizer
model_path = "thenHung/question_decomposer_t5"
tokenizer = T5Tokenizer.from_pretrained(model_path)
model = T5ForConditionalGeneration.from_pretrained(model_path)
model.to(device)
model.eval()
# Decompose question
question = "Who is taller between John and Mary?"
input_text = f"decompose question: {question}"
input_ids = tokenizer(
input_text,
max_length=128,
padding="max_length",
truncation=True,
return_tensors="pt"
).input_ids.to(device)
with torch.no_grad():
outputs = model.generate(
input_ids,
max_length=128,
num_beams=4,
early_stopping=True
)
# Decode output
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
sub_questions = decoded_output.split(" [SEP] ")
# Print sub-questions
print(sub_questions)
# ['What is the height of John?', 'What is the height of Mary?']