返回基于给定数据集的索引查找表。
用法
tf.data.experimental.index_table_from_dataset(
dataset=None, num_oov_buckets=0, vocab_size=None, default_value=-1,
hasher_spec=lookup_ops.FastHashSpec, key_dtype=tf.dtypes.string, name=None
)参数
-
dataset键的数据集。 -
num_oov_buckets词汇表外存储桶的数量。 -
vocab_size词汇表中元素的数量(如果已知)。 -
default_value用于词汇外特征值的值。默认为 -1。 -
hasher_specHasherSpec指定用于分配词汇外存储桶的散列函数。 -
key_dtypekey数据类型。 -
name此操作的名称(可选)。
返回
- 基于给定数据集的查找表。
抛出
-
ValueError如果num_oov_buckets为负数vocab_size不大于零key_dtype不是整数或字符串
此操作基于给定的键数据集构造查找表。
如果 num_oov_buckets 大于零,则对词汇表外令牌的任何查找都将根据其哈希返回存储桶 ID。否则,它被分配 default_value 。存储桶 ID 范围为 [vocabulary size, vocabulary size + num_oov_buckets - 1] 。
示例用法:
ds = tf.data.Dataset.range(100).map(lambda x:tf.strings.as_string(x * 2))
table = tf.data.experimental.index_table_from_dataset(
ds, key_dtype=dtypes.int64)
table.lookup(tf.constant(['0', '2', '4'], dtype=tf.string)).numpy()
array([0, 1, 2])
相关用法
- Python tf.data.experimental.ignore_errors用法及代码示例
- Python tf.data.experimental.RandomDataset.group_by_window用法及代码示例
- Python tf.data.experimental.SqlDataset.enumerate用法及代码示例
- Python tf.data.experimental.make_saveable_from_iterator用法及代码示例
- Python tf.data.experimental.SqlDataset.zip用法及代码示例
- Python tf.data.experimental.Counter用法及代码示例
- Python tf.data.experimental.SqlDataset.shard用法及代码示例
- Python tf.data.experimental.CsvDataset.window用法及代码示例
- Python tf.data.experimental.RandomDataset.cache用法及代码示例
- Python tf.data.experimental.SqlDataset.snapshot用法及代码示例
- Python tf.data.experimental.CsvDataset.apply用法及代码示例
- Python tf.data.experimental.DatasetInitializer用法及代码示例
- Python tf.data.experimental.unbatch用法及代码示例
- Python tf.data.experimental.RandomDataset.map用法及代码示例
- Python tf.data.experimental.CsvDataset.flat_map用法及代码示例
- Python tf.data.experimental.assert_cardinality用法及代码示例
- Python tf.data.experimental.CsvDataset.random用法及代码示例
- Python tf.data.experimental.save用法及代码示例
- Python tf.data.experimental.CsvDataset.cardinality用法及代码示例
- Python tf.data.experimental.CsvDataset.interleave用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.data.experimental.index_table_from_dataset。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
