This model is fine tuned to generate a question with answers from a context , why that can be very usful this can help you to generate a dataset from a book article any thing you would to make from it dataset and train another model on this dataset , give the model any context with pre prometed of quation you want + context and it will extarct question + answer for you this are promted i use [ "which", "how", "when", "where", "who", "whom", "whose", "why", "which", "who", "whom", "whose", "whereas", "can", "could", "may", "might", "will", "would", "shall", "should", "do", "does", "did", "is", "are", "am", "was", "were", "be", "being", "been", "have", "has", "had", "if", "is", "are", "am", "was", "were", "do", "does", "did", "can", "could", "will", "would", "shall", "should", "might", "may", "must", "may", "might", "must"]

1from transformers import AutoTokenizer, AutoModelForQuestionAnswering
2model_name="mohamedemam/Question_generator"
3def generate_question_answer(context, prompt, model_name="mohamedemam/Question_generator"):
4 """
5 Generates a question-answer pair using the provided context, prompt, and model.
6
7 Args:
8 context: String containing the text or URL of the source material.
9 prompt: String starting with a question word (e.g., "what," "who").
10 model_name: Optional string specifying the model name (default: google/flan-t5-base).
11
12 Returns:
13 A tuple containing the generated question and answer strings.
14 """
15
16 tokenizer = AutoTokenizer.from_pretrained(model_name)
17 model = AutoModelForQuestionAnswering.from_pretrained(model_name)
18
19 inputs = tokenizer(context, return_tensors="pt")
20 with torch.no_grad():
21 outputs = model(**inputs)
22
23 start_scores, end_scores = outputs.start_logits, outputs.end_logits
24 answer_start = torch.argmax(start_scores)
25 answer_end = torch.argmax(end_scores) + 1 # Account for inclusive end index
26
27 answer = tokenizer.convert_tokens_to_strings(tokenizer.convert_ids_to_tokens(inputs["input_ids"][answer_start:answer_end]))[0]
28 question = f"{prompt} {answer}" # Formulate the question using answer
29
30 return question, answer
31
32# Example usage
33context = "The capital of France is Paris."
34prompt = "What"
35question, answer = generate_question_answer(context, prompt)
36print(f"Question: {question}")
37print(f"Answer: {answer}")