Skip to content

Instantly share code, notes, and snippets.

@mapmeld
Last active January 5, 2020 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapmeld/5805f36e9d018538e53f25e1898e2abf to your computer and use it in GitHub Desktop.
Save mapmeld/5805f36e9d018538e53f25e1898e2abf to your computer and use it in GitHub Desktop.
first-draft qa
from allennlp.predictors import Predictor
from transformers.tokenization_gpt2 import GPT2Tokenizer
from transformers import pipeline
class HuggingFacePredictor(Predictor):
def __init__(self) -> None:
self.tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
self.model = pipeline('question-answering')
def predict(self, passage='', question=''):
return self.model({
'context': passage,
'question': question
})
def __getitem__(self, index: int) -> str:
return self.tokenizer.decode([index])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment