Skip to content

Instantly share code, notes, and snippets.

@Sirsirious
Created December 14, 2020 17:48
Show Gist options
  • Save Sirsirious/f49a98753daddb2ad369990e4aafec2a to your computer and use it in GitHub Desktop.
Save Sirsirious/f49a98753daddb2ad369990e4aafec2a to your computer and use it in GitHub Desktop.
# To convert the model to Keras, simply run:
keras_layer = trax.AsKeras(sentiment_analysis_model)
# This will be a trax.trax2keras.AsKeras object
print(keras_layer)
# Run the Keras layer to verify it returns the same result.
example_input = list(data.tokenize(iter(["I loved the way that the actors were cast, also, It is clear that they've put a huge effort in post-production."]), vocab_file="en_8k.subword"))[0]
sentiment_activations = keras_layer(example_input[None, :])
print(f'Keras returned sentiment activations: {numpy.asarray(sentiment_activations)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment