TensorFlow Hub ライブラリの概要
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
tensorflow_hub
ライブラリでは、最小限のコードでトレーニング済みのモデルをダウンロードし、TensorFlow プログラムで再利用することができます。トレーニング済みモデルの読み込みには、主に hub.KerasLayer
API が使用されます。
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)
注意: このドキュメントの例では、TFhub.dev URL ハンドルを使用しています。その他の有効なハンドルタイプについては、こちらをご覧ください。
ダウンロードのキャッシュロケーションを設定する
デフォルトでは、tensorflow_hub
はシステム全体の一時ディレクトリを使用して、ダウンロードや圧縮されたモデルをキャッシュします。その他のより永続的なロケーションのオプションについては、キャッシングをご覧ください。
API の安定性
変更による破損を回避することに努めてはいますが、このプロジェクトは現在開発中であるため、安定した API やモデル形式は保証されていません。
公平性
すべての機械学習と同様に、公平性は重要な考慮事項です。多くのトレーニング済みモデルは、大規模なデータセットでトレーニングされています。モデルを再利用する際は、どのデータを使ってモデルがトレーニングされたのか(およびバイアスが既存していたかどうか)、およびこのことがモデルの使用にどのような影響を与えるのかに配慮することが重要です。
セキュリティ
任意の TensorFlow グラフが含まれるため、モデルはプログラムとして捉えられます。「TensorFlow を安全に使用する」では、信頼されないソースのモデルを参照する際のセキュリティ問題が説明されています。
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-01-16 UTC。
[null,null,["最終更新日 2024-01-16 UTC。"],[],[],null,["# TensorFlow Hub Library Overview\n\n\u003cbr /\u003e\n\nThe [`tensorflow_hub`](https://github.com/tensorflow/hub) library lets you\ndownload and reuse trained models in your TensorFlow program with a minimum\namount of code. The main way to load a trained model is using the\n[`hub.KerasLayer`](https://www.tensorflow.org/hub/api_docs/python/hub/KerasLayer) API. \n\n import tensorflow_hub as hub\n\n embed = hub.KerasLayer(\"https://tfhub.dev/google/nnlm-en-dim128/2\")\n embeddings = embed([\"A long sentence.\", \"single-word\", \"http://example.com\"])\n print(embeddings.shape, embeddings.dtype)\n\n**Note:** This documentation uses TFhub.dev URL handles in examples. See more\ninformation regarding other valid handle types [here](/hub/tf2_saved_model#model_handles).\n\nSetting the cache location for downloads.\n-----------------------------------------\n\nBy default, `tensorflow_hub` uses a system-wide, temporary directory to cache\ndownloaded and uncompressed models. See [Caching](/hub/caching) for options to use\nother, possibly more persistent locations.\n\nAPI stability\n-------------\n\nAlthough we hope to prevent breaking changes, this project is still under active\ndevelopment and is not yet guaranteed to have a stable API or model format.\n\nFairness\n--------\n\nAs in all of machine learning, [fairness](http://ml-fairness.com) is an\n[important](https://research.googleblog.com/2016/10/equality-of-opportunity-in-machine.html)\nconsideration. Many pre-trained models are trained on large datasets. When\nreusing any model, it's important to be mindful of what data the model was\ntrained on (and whether there are any existing biases there), and how these\nmight impact your use of it.\n\nSecurity\n--------\n\nSince they contain arbitrary TensorFlow graphs, models can be thought of as\nprograms.\n[Using TensorFlow Securely](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md)\ndescribes the security implications of referencing a model from an untrusted\nsource.\n\nNext Steps\n----------\n\n- [Use the library](/hub/tf2_saved_model)\n- [Reusable SavedModels](/hub/reusable_saved_models)"]]