Tổng quan về thư viện TensorFlow Hub
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Thư viện tensorflow_hub
cho phép bạn tải xuống và sử dụng lại các mô hình đã đào tạo trong chương trình TensorFlow của mình với số lượng mã tối thiểu. Cách chính để tải mô hình đã đào tạo là sử dụng API hub.KerasLayer
.
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)
Lưu ý: Tài liệu này sử dụng các thẻ xử lý URL TFhub.dev trong các ví dụ. Xem thêm thông tin về các loại xử lý hợp lệ khác tại đây .
Đặt vị trí bộ đệm để tải xuống.
Theo mặc định, tensorflow_hub
sử dụng thư mục tạm thời trên toàn hệ thống để lưu vào bộ đệm các mô hình đã tải xuống và không nén. Xem Bộ nhớ đệm để biết các tùy chọn sử dụng các vị trí khác, có thể ổn định hơn.
Tính ổn định của API
Mặc dù chúng tôi hy vọng ngăn chặn những thay đổi đột phá nhưng dự án này vẫn đang được phát triển tích cực và chưa được đảm bảo có định dạng mô hình hoặc API ổn định.
Sự công bằng
Như trong tất cả các lĩnh vực học máy, tính công bằng là một điều quan trọng cần cân nhắc. Nhiều mô hình được đào tạo trước được đào tạo trên các tập dữ liệu lớn. Khi sử dụng lại bất kỳ mô hình nào, điều quan trọng là phải lưu ý đến dữ liệu mà mô hình đã được đào tạo (và liệu có bất kỳ thành kiến nào hiện có ở đó hay không) và những thành kiến này có thể ảnh hưởng như thế nào đến việc bạn sử dụng mô hình đó.
Bảo vệ
Vì chúng chứa các biểu đồ TensorFlow tùy ý nên các mô hình có thể được coi là các chương trình. Sử dụng TensorFlow mô tả một cách an toàn ý nghĩa bảo mật của việc tham chiếu mô hình từ một nguồn không đáng tin cậy.
Các bước tiếp theo
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-25 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 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)"]]