Nurisslam commited on
Commit
ac627d3
·
verified ·
1 Parent(s): 7cc244b

Create inference.py

Browse files
Files changed (1) hide show
  1. inference.py +13 -0
inference.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import MT5ForConditionalGeneration, MT5Tokenizer
2
+
3
+ model = MT5ForConditionalGeneration.from_pretrained("./model")
4
+ tokenizer = MT5Tokenizer.from_pretrained("google/mt5-small")
5
+
6
+ def ask(question, context):
7
+ input_text = f"Сұрақ: {question} Контекст: {context}"
8
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids
9
+ output = model.generate(input_ids, max_length=100)
10
+ return tokenizer.decode(output[0], skip_special_tokens=True)
11
+
12
+ context = """Мәліметтер қоры дегеніміз – белгілі бір сипаттамасы бар, өзара байланыса сақталатын ақпараттар жиынтығы."""
13
+ print(ask("Мәліметтер қоры дегеніміз не?", context))