本文整理汇总了Python中tensorflow.python.ops.lookup_ops.index_to_string_table_from_tensor方法的典型用法代码示例。如果您正苦于以下问题:Python lookup_ops.index_to_string_table_from_tensor方法的具体用法?Python lookup_ops.index_to_string_table_from_tensor怎么用?Python lookup_ops.index_to_string_table_from_tensor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.ops.lookup_ops
的用法示例。
在下文中一共展示了lookup_ops.index_to_string_table_from_tensor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _class_string_table
# 需要导入模块: from tensorflow.python.ops import lookup_ops [as 别名]
# 或者: from tensorflow.python.ops.lookup_ops import index_to_string_table_from_tensor [as 别名]
def _class_string_table(self):
"""Creates a lookup table for class_string.
In eager execution, this lookup table will be lazily created on the first
call of `self._class_string_table` and cached for later use; In graph
execution, it will be created on demand.
Returns:
A hash table for lookup.
"""
if (self._cached_class_string_table is None or not tf.executing_eagerly()):
self._cached_class_string_table = (
lookup_ops.index_to_string_table_from_tensor(
vocabulary_list=self._label_vocabulary,
name='class_string_lookup'))
return self._cached_class_string_table
示例2: create_test_iterator
# 需要导入模块: from tensorflow.python.ops import lookup_ops [as 别名]
# 或者: from tensorflow.python.ops.lookup_ops import index_to_string_table_from_tensor [as 别名]
def create_test_iterator(hparams, mode):
"""Create test iterator."""
src_vocab_table = lookup_ops.index_table_from_tensor(
tf.constant([hparams.eos, "a", "b", "c", "d"]))
tgt_vocab_mapping = tf.constant([hparams.sos, hparams.eos, "a", "b", "c"])
tgt_vocab_table = lookup_ops.index_table_from_tensor(tgt_vocab_mapping)
if mode == tf.contrib.learn.ModeKeys.INFER:
reverse_tgt_vocab_table = lookup_ops.index_to_string_table_from_tensor(
tgt_vocab_mapping)
src_dataset = tf.contrib.data.Dataset.from_tensor_slices(
tf.constant(["a a b b c", "a b b"]))
if mode != tf.contrib.learn.ModeKeys.INFER:
tgt_dataset = tf.contrib.data.Dataset.from_tensor_slices(
tf.constant(["a b c b c", "a b c b"]))
return (
iterator_utils.get_iterator(
src_dataset=src_dataset,
tgt_dataset=tgt_dataset,
src_vocab_table=src_vocab_table,
tgt_vocab_table=tgt_vocab_table,
batch_size=hparams.batch_size,
sos=hparams.sos,
eos=hparams.eos,
source_reverse=hparams.source_reverse,
random_seed=hparams.random_seed,
num_buckets=hparams.num_buckets),
src_vocab_table,
tgt_vocab_table)
else:
return (
iterator_utils.get_infer_iterator(
src_dataset=src_dataset,
src_vocab_table=src_vocab_table,
eos=hparams.eos,
source_reverse=hparams.source_reverse,
batch_size=hparams.batch_size),
src_vocab_table,
tgt_vocab_table,
reverse_tgt_vocab_table)
示例3: create_test_iterator
# 需要导入模块: from tensorflow.python.ops import lookup_ops [as 别名]
# 或者: from tensorflow.python.ops.lookup_ops import index_to_string_table_from_tensor [as 别名]
def create_test_iterator(hparams, mode):
"""Create test iterator."""
src_vocab_table = lookup_ops.index_table_from_tensor(
tf.constant([hparams.eos, "a", "b", "c", "d"]))
tgt_vocab_mapping = tf.constant([hparams.sos, hparams.eos, "a", "b", "c"])
tgt_vocab_table = lookup_ops.index_table_from_tensor(tgt_vocab_mapping)
if mode == tf.contrib.learn.ModeKeys.INFER:
reverse_tgt_vocab_table = lookup_ops.index_to_string_table_from_tensor(
tgt_vocab_mapping)
src_dataset = tf.data.Dataset.from_tensor_slices(
tf.constant(["a a b b c", "a b b"]))
if mode != tf.contrib.learn.ModeKeys.INFER:
tgt_dataset = tf.data.Dataset.from_tensor_slices(
tf.constant(["a b c b c", "a b c b"]))
return (
iterator_utils.get_iterator(
src_dataset=src_dataset,
tgt_dataset=tgt_dataset,
src_vocab_table=src_vocab_table,
tgt_vocab_table=tgt_vocab_table,
batch_size=hparams.batch_size,
sos=hparams.sos,
eos=hparams.eos,
random_seed=hparams.random_seed,
num_buckets=hparams.num_buckets),
src_vocab_table,
tgt_vocab_table)
else:
return (
iterator_utils.get_infer_iterator(
src_dataset=src_dataset,
src_vocab_table=src_vocab_table,
eos=hparams.eos,
batch_size=hparams.batch_size),
src_vocab_table,
tgt_vocab_table,
reverse_tgt_vocab_table)
示例4: create_test_iterator
# 需要导入模块: from tensorflow.python.ops import lookup_ops [as 别名]
# 或者: from tensorflow.python.ops.lookup_ops import index_to_string_table_from_tensor [as 别名]
def create_test_iterator(hparams, mode, trie_excludes=None):
"""Create test iterator."""
src_vocab_table = lookup_ops.index_table_from_tensor(
tf.constant([hparams.eos, "a", "b", "c", "d"]))
tgt_vocab_mapping = tf.constant([hparams.sos, hparams.eos, "a", "b", "c"])
tgt_vocab_table = lookup_ops.index_table_from_tensor(tgt_vocab_mapping)
reverse_tgt_vocab_table = lookup_ops.index_to_string_table_from_tensor(
tgt_vocab_mapping)
src_dataset = tf.data.Dataset.from_tensor_slices(
tf.constant(["a a b b c", "a b b"]))
ctx_dataset = tf.data.Dataset.from_tensor_slices(
tf.constant(["c b c b a", "b c b a"]))
trie_excludes = trie_excludes or []
trie_excludes = " {} ".format(hparams.eos).join(trie_excludes)
tex_dataset = tf.data.Dataset.from_tensor_slices(
tf.constant([trie_excludes, trie_excludes]))
if mode != tf.contrib.learn.ModeKeys.INFER:
tgt_dataset = tf.data.Dataset.from_tensor_slices(
tf.constant(["a b c b c", "a b c b"]))
return (iterator_utils.get_iterator(
hparams=hparams,
src_dataset=src_dataset,
tgt_dataset=tgt_dataset,
ctx_dataset=ctx_dataset,
annot_dataset=None,
src_vocab_table=src_vocab_table,
tgt_vocab_table=tgt_vocab_table,
batch_size=hparams.batch_size,
sos=hparams.sos,
eos=hparams.eos,
random_seed=hparams.random_seed,
num_buckets=hparams.num_buckets), src_vocab_table, tgt_vocab_table,
reverse_tgt_vocab_table)
else:
return (iterator_utils.get_infer_iterator(
hparams=hparams,
src_dataset=src_dataset,
ctx_dataset=ctx_dataset,
annot_dataset=None,
trie_exclude_dataset=tex_dataset,
src_vocab_table=src_vocab_table,
tgt_vocab_table=tgt_vocab_table,
eos=hparams.eos,
batch_size=hparams.batch_size), src_vocab_table, tgt_vocab_table,
reverse_tgt_vocab_table)