1 Introduction
TensorFlow Hub is a library for enabling distribution, distribution, and consumption of reusable parts of machine learning models. A module is an independent tensorflow graph, along with its weights, etc., that can be reused for different tasks in the transfer learning process.
Modules contain variables that are pretrained on tasks using large datasets. By reusing modules on related tasks, you can:
- Train the model with a smaller dataset
- Improve generalization ability
- Significantly Speeds Up Training
Here 's an example, using the English Embedding module, which maps an array of strings to this embedding:
import tensorflow as tf
import tensorflow_hub as hub
with tf.Graph().as_default():
embed = hub.Module("https://tfhub.dev/google/nnlm-en-dim128-with-normalization/1")
embeddings = embed(["A long sentence.", "single-word", "http://example.com"])
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(tf.tables_initializer())
print(sess.run(embeddings))
2. Installation
Tensorflow Hub depends on bug fixes and enhancements that did not appear in versions prior to tensorflow 1.7. You must install or upgrade your tensorflow package to at least version 1.7 to use TensorFlow Hub:
pip install "tensorflow>=1.7.0"
pip install tensorflow-hub
This section will be updated to include a specific tensorflow version requirement when a compatible version is available.
Reference documentation: https://github.com/tensorflow/hub