本文整理匯總了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)