Skip to content

Instantly share code, notes, and snippets.

@Rocketknight1
Created June 29, 2022 14:44
Show Gist options
  • Save Rocketknight1/56ad64716ea1a0531087ced48299b730 to your computer and use it in GitHub Desktop.
Save Rocketknight1/56ad64716ea1a0531087ced48299b730 to your computer and use it in GitHub Desktop.
import tensorflow as tf
from transformers import TFAutoModel, TFBertTokenizer
class EndToEndModel(tf.keras.Model):
def __init__(self, checkpoint):
super().__init__()
self.tokenizer = TFBertTokenizer.from_pretrained(checkpoint)
self.model = TFAutoModel.from_pretrained(checkpoint)
def call(self, inputs):
tokenized = self.tokenizer(inputs)
return self.model(**tokenized)
model = EndToEndModel(checkpoint='bert-base-cased')
test_inputs = [
'This is a test sentence!',
'This is another one!'
]
model.predict(test_inputs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment