import tensorflow_hub as hub embed = hub.KerasLayer("https://hub.tensorflow.google.cn/google/nnlm-en-dim128/2") embeddings = embed(["A long sentence.", "single-word", "http://example.com"]) print(embeddings.shape, embeddings.dtype)
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.