Test_Question_Ai / inference.py
Nurisslam's picture
Create inference.py
ac627d3 verified
raw
history blame
772 Bytes
from transformers import MT5ForConditionalGeneration, MT5Tokenizer
model = MT5ForConditionalGeneration.from_pretrained("./model")
tokenizer = MT5Tokenizer.from_pretrained("google/mt5-small")
def ask(question, context):
input_text = f"Сұрақ: {question} Контекст: {context}"
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
output = model.generate(input_ids, max_length=100)
return tokenizer.decode(output[0], skip_special_tokens=True)
context = """Мәліметтер қоры дегеніміз – белгілі бір сипаттамасы бар, өзара байланыса сақталатын ақпараттар жиынтығы."""
print(ask("Мәліметтер қоры дегеніміз не?", context))