当前位置: 首页>>代码示例>>Python>>正文


Python lookup_ops.index_to_string_table_from_tensor方法代码示例

本文整理汇总了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 
开发者ID:tensorflow,项目名称:estimator,代码行数:18,代码来源:binary_class_head.py

示例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) 
开发者ID:steveash,项目名称:NETransliteration-COLING2018,代码行数:43,代码来源:common_test_utils.py

示例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) 
开发者ID:snuspl,项目名称:parallax,代码行数:41,代码来源:common_test_utils.py

示例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) 
开发者ID:google,项目名称:active-qa,代码行数:52,代码来源:common_test_utils.py


注:本文中的tensorflow.python.ops.lookup_ops.index_to_string_table_from_tensor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。