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
import tensorflow_hub as hub embed = hub.KerasLayer("https://tfhub.dev/google/nnlm-en-dim128/2") embeddings = embed(["A long sentence.", "single-word", "http://example.com"]) print(embeddings.shape, embeddings.dtype)
Note: This documentation uses TFhub.dev URL handles in examples. See more information regarding other valid handle types here.
Setting the cache location for downloads.
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.
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.