Views
No views yet
transformers library installed. You can install it via pip:pip install transformerstransformers library. Ensure you have the correct repository ID or local path.1from transformers import T5ForConditionalGeneration, T5Tokenizer
2
3# Load the model and tokenizer
4model = T5ForConditionalGeneration.from_pretrained("miiiciiii/I-Comprehend_qg")
5tokenizer = T5Tokenizer.from_pretrained("miiiciiii/I-Comprehend_qg")
6
7def get_question(context, answer, model, tokenizer):
8 """Generate a question for the given answer and context."""
9 answer_span = context.replace(answer, f"<hl>{answer}<hl>", 1) + "</s>"
10 inputs = tokenizer(answer_span, return_tensors="pt")
11 question = model.generate(input_ids=inputs.input_ids, max_length=50)[0]
12
13 return tokenizer.decode(question, skip_special_tokens=True)
14
15# Define the context and answer
16context = "The Eiffel Tower is located in Paris and is one of the most famous landmarks in the world."
17answer = "Eiffel Tower"
18
19# Generate the question
20question = get_question(context, answer, model, tokenizer)
21print("Generated Question:", question)