文本的常用签名
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页面介绍应由 TF1 Hub 格式的模块为接受文本输入的任务实现的常用签名。(有关 TF2 SavedModel 格式,请参阅具有类似功能的 SavedModel API。)
文本特征向量
文本特征向量模块可以根据文本特征创建密集向量表示。该模块接受一批形状为 [batch_size]
的字符串,并将其映射至形状为 [batch_size, N]
的 float32
张量。此张量通常被称为 N
维文本嵌入向量。
基本用法
embed = hub.Module("path/to/module")
representations = embed([
"A long sentence.",
"single-word",
"http://example.com"])
特征列用法
feature_columns = [
hub.text_embedding_column("comment", "path/to/module", trainable=False),
]
input_fn = tf.estimator.inputs.numpy_input_fn(features, labels, shuffle=True)
estimator = tf.estimator.DNNClassifier(hidden_units, feature_columns)
estimator.train(input_fn, max_steps=100)
说明
模块已在不同的领域和/或任务中进行了预训练,因此并非每个文本特征向量模块都适用于您的问题。例如,某些模块可能仅使用一种语言进行训练。
此接口不支持在 TPU 上微调文本表示,因为它要求模块同时实例化字符串处理和可训练变量。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2022-09-21。
[null,null,["最后更新时间 (UTC):2022-09-21。"],[],[],null,["# Common Signatures for Text\n\n\u003cbr /\u003e\n\nThis page describes common signatures that should be implemented by modules in\nthe [TF1 Hub format](../tf1_hub_module) for tasks that accept text inputs.\n(For the [TF2 SavedModel format](../tf2_saved_model), see the analogous\n[SavedModel API](../common_saved_model_apis/text).)\n\nText feature vector\n-------------------\n\nA **text feature vector** module creates a dense vector representation\nfrom text features.\nIt accepts a batch of strings of shape `[batch_size]` and maps them to\na `float32` tensor of shape `[batch_size, N]`. This is often called\n**text embedding** in dimension `N`.\n\n### Basic usage\n\n embed = hub.Module(\"path/to/module\")\n representations = embed([\n \"A long sentence.\",\n \"single-word\",\n \"http://example.com\"])\n\n### Feature column usage\n\n feature_columns = [\n hub.text_embedding_column(\"comment\", \"path/to/module\", trainable=False),\n ]\n input_fn = tf.estimator.inputs.numpy_input_fn(features, labels, shuffle=True)\n estimator = tf.estimator.DNNClassifier(hidden_units, feature_columns)\n estimator.train(input_fn, max_steps=100)\n\nNotes\n-----\n\nModules have been pre-trained on different domains and/or tasks,\nand therefore not every text feature vector module would be suitable for\nyour problem. E.g.: some modules could have been trained on a single language.\n\nThis interface does not allow fine-tuning of the text representation on TPUs,\nbecause it requires the module to instantiate both string processing and the\ntrainable variables at the same time."]]