Deploy the trained model
Browse files- inference.py +19 -0
inference.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import string
|
| 3 |
+
|
| 4 |
+
# Replace this with your own checkpoint
|
| 5 |
+
model_checkpoint = "results/checkpoint-16000"
|
| 6 |
+
question_answerer = pipeline("question-answering", model = model_checkpoint)
|
| 7 |
+
|
| 8 |
+
def predict(question, context):
|
| 9 |
+
answer = question_answerer(question = question,
|
| 10 |
+
context = context)
|
| 11 |
+
|
| 12 |
+
exclude = set(string.punctuation)
|
| 13 |
+
|
| 14 |
+
text = answer['answer']
|
| 15 |
+
text = ''.join(ch for ch in text if ch not in exclude)
|
| 16 |
+
|
| 17 |
+
answer['answer'] = text
|
| 18 |
+
|
| 19 |
+
return answer
|