Last active
August 3, 2022 11:24
-
-
Save Rocketknight1/b479d57e3d2f94420b11ca8d319cc68f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a new feature, so make sure to update to the latest version of transformers! | |
# You will also need to pip install tensorflow_text | |
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) # Pass strings straight to model! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment