Skip to content

Instantly share code, notes, and snippets.

@caleb-kaiser
Last active October 9, 2020 16:56
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 caleb-kaiser/d6f0550637b39a4c4083d161fa53847e to your computer and use it in GitHub Desktop.
Save caleb-kaiser/d6f0550637b39a4c4083d161fa53847e to your computer and use it in GitHub Desktop.
import torch
from transformers import BertTokenizerFast, BertModel
class PythonPredictor:
def __init__(self, config):
self.device = "cpu"
self.tokenizer = BertTokenizerFast.from_pretrained("bert-base-uncased")
self.model = BertModel.from_pretrained("bert-base-uncased")
def predict(self, payload):
inputs = self.tokenizer(payload["text"], return_tensors="pt")
predictions = self.model(**inputs)
return {"request": "done"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment