anjali2024's picture
Update app.py
84e4622 verified
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
import torch
# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("ntphuc149/ViBidLEQA_large")
model = AutoModelForQuestionAnswering.from_pretrained("ntphuc149/ViBidLEQA_large")
# Example usage
question = "Thế nào là đấu thầu hạn chế?"
context = "Đấu thầu hạn chế là phương thức lựa chọn nhà thầu trong đó chỉ một số nhà thầu đáp ứng yêu cầu về năng lực và kinh nghiệm được bên mời thầu mời tham gia."
# Tokenize input
inputs = tokenizer(
question,
context,
return_tensors="pt",
max_length=512,
truncation=True,
padding=True
)
# Get model predictions
with torch.no_grad():
outputs = model(**inputs)
# Get answer span
answer_start = torch.argmax(outputs.start_logits)
answer_end = torch.argmax(outputs.end_logits) + 1
answer = tokenizer.decode(inputs.input_ids[0][answer_start:answer_end])
print(f"Question: {question}")
print(f"Answer: {answer}")