Skip to main content

Tensorflow Hub

When to use

  • Less data
  • Less domain expertise
  • Share without code dependencies

Installation

pip install tensorflow-hub

Usage

import tensorflow_hub as hub

text_features = hub.load("https://tfhub.dev/google/tf2-preview/nnlm-en-dim128/1")
example_embeddings = text_features(np.array(["hello world", "test", "1, 2, 3"]))

Integrate with Keras

model = keras.Sequential([
hub.KerasLayer("https://tfhub.dev/google/tf2-preview/nnlm-en-dim128/1", output_shape=[128]),
keras.layeyrs.Dense(16, activation='relu'),
keras.layeyrs.Dense(1, activation='sigmoid')
])

model.fit(...)
model.predict(np.array(["hello world", "test", "1, 2, 3"]))

Source