Save the date! Google I/O returns May 18-20 Register now

TensorFlow Hub Library Overview

The tensorflow_hub library lets you download and reuse trained models in your TensorFlow program with a minimum amount of code. The main way to load a trained model is using the hub.KerasLayer API.

import tensorflow_hub as hub

embed = hub.KerasLayer("")
embeddings = embed(["A long sentence.", "single-word", ""])
print(embeddings.shape, embeddings.dtype)

Setting the cache location for downloads.

By default, tensorflow_hub uses a system-wide, temporary directory to cache downloaded and uncompressed models. See Caching for options to use other, possibly more persistent locations.

API stability

Although we hope to prevent breaking changes, this project is still under active development and is not yet guaranteed to have a stable API or model format.


As in all of machine learning, fairness is an important consideration. Many pre-trained models are trained on large datasets. When reusing any model, it’s important to be mindful of what data the model was trained on (and whether there are any existing biases there), and how these might impact your use of it.


Since they contain arbitrary TensorFlow graphs, models can be thought of as programs. Using TensorFlow Securely describes the security implications of referencing a model from an untrusted source.

Next Steps