Views
No views yet
transformers library installed. You can install it via pip:1pip install transformers
2pip install torchtransformers library. Ensure you have the correct repository ID or local path.1from transformers import T5ForConditionalGeneration, T5Tokenizer
2import torch
3
4# Load the model and tokenizer
5t5ag_model = T5ForConditionalGeneration.from_pretrained("miiiciiii/I-Comprehend_ag")
6t5ag_tokenizer = T5Tokenizer.from_pretrained("miiiciiii/I-Comprehend_ag")
7
8def answer_question(question, context):
9 """Generate an answer for a given question and context."""
10 input_text = f"question: {question} context: {context}"
11 input_ids = t5ag_tokenizer.encode(input_text, return_tensors="pt", max_length=512, truncation=True)
12
13 with torch.no_grad():
14 output = t5ag_model.generate(input_ids, max_length=512, num_return_sequences=1, max_new_tokens=200)
15
16 return t5ag_tokenizer.decode(output[0], skip_special_tokens=True)
17
18# Example usage
19question = "What is the location of the Eiffel Tower?"
20context = "The Eiffel Tower is located in Paris and is one of the most famous landmarks in the world."
21answer = answer_question(question, context)
22print("Generated Answer:", answer)