Views
No views yet
1from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
2
3# Load the tokenizer and model from Hugging Face
4tokenizer = AutoTokenizer.from_pretrained("prabinpanta0/ZenGQ")
5model = AutoModelForQuestionAnswering.from_pretrained("prabinpanta0/ZenGQ")
6
7# Create a pipeline for question answering
8qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer)
9
10# Define your context and questions
11contexts = ["Berlin is the capital of Germany.",
12 "Paris is the capital of France.",
13 "Madrid is the capital of Spain."]
14questions = [
15 "What is the capital of Germany?",
16 "Which city is the capital of France?",
17 "What is the capital of Spain?"
18]
19
20# Get answers
21for context, question in zip(contexts, questions):
22 result = qa_pipeline(question=question, context=context)
23 print(f"Question: {question}")
24 print(f"Answer: {result['answer']}\n")text = "Berlin is the capital of Germany. Paris is the capital of France. Madrid is the capital of Spain."
tokens = tokenizer.tokenize(text)
print(tokens)['berlin', 'is', 'the', 'capital', 'of', 'germany', '.', 'paris', 'is', 'the', 'capital', 'of', 'france', '.', 'madrid', 'is', 'the', 'capital', 'of', 'spain', '.']