Created
June 29, 2022 14:49
-
-
Save Rocketknight1/16476fbb6138f06d7812fb949ce90d22 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 install transformers from main first! | |
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