forked from cortexlabs/cortex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredictor.py
25 lines (19 loc) · 880 Bytes
/
predictor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# WARNING: you are on the master branch, please refer to the examples on the branch that matches your `cortex version`
import torch
from allennlp.predictors.predictor import Predictor as AllenNLPPredictor
class PythonPredictor:
def __init__(self, config):
self.device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"using device: {self.device}")
cuda_device = -1
if self.device == "cuda":
cuda_device = 0
self.predictor = AllenNLPPredictor.from_path(
"https://storage.googleapis.com/allennlp-public-models/bidaf-elmo-model-2018.11.30-charpad.tar.gz",
cuda_device=cuda_device,
)
def predict(self, payload):
prediction = self.predictor.predict(
passage=payload["passage"], question=payload["question"]
)
return prediction["best_span_str"]