返回基於給定數據集的索引查找表。
用法
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_spec
HasherSpec
指定用於分配詞匯外存儲桶的散列函數。 -
key_dtype
key
數據類型。 -
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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。