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


Python text_encoder.PAD属性代码示例

本文整理汇总了Python中tensor2tensor.data_generators.text_encoder.PAD属性的典型用法代码示例。如果您正苦于以下问题:Python text_encoder.PAD属性的具体用法?Python text_encoder.PAD怎么用?Python text_encoder.PAD使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在tensor2tensor.data_generators.text_encoder的用法示例。


在下文中一共展示了text_encoder.PAD属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_vocab_list

# 需要导入模块: from tensor2tensor.data_generators import text_encoder [as 别名]
# 或者: from tensor2tensor.data_generators.text_encoder import PAD [as 别名]
def build_vocab_list(data_path):
  """Reads a file to build a vocabulary with letters and phonemes.

    Args:
      data_path: data file to read list of words from.

    Returns:
      vocab_list: vocabulary list with both graphemes and phonemes."""
  vocab = {}
  with tf.gfile.GFile(data_path, "r") as data_file:
    for line in data_file:
      items = line.strip().split()
      vocab.update({char:1 for char in list(items[0])})
      vocab.update({phoneme:1 for phoneme in items[1:]})
    vocab_list = [PAD, EOS]
    for key in sorted(vocab.keys()):
      vocab_list.append(key)
  return vocab_list 
开发者ID:steveash,项目名称:NETransliteration-COLING2018,代码行数:20,代码来源:g2p_encoder.py

示例2: test_reserved_tokens_in_corpus

# 需要导入模块: from tensor2tensor.data_generators import text_encoder [as 别名]
# 或者: from tensor2tensor.data_generators.text_encoder import PAD [as 别名]
def test_reserved_tokens_in_corpus(self):
    """Test that we handle reserved tokens appearing in the corpus."""
    corpus = "A B {} D E F {} G {}".format(text_encoder.EOS,
                                           text_encoder.EOS,
                                           text_encoder.PAD)

    encoder = text_encoder.TokenTextEncoder(None, vocab_list=corpus.split())

    all_tokens = encoder._id_to_token.values()

    # If reserved tokens are removed correctly, then the set of tokens will
    # be unique.
    self.assertEqual(len(all_tokens), len(set(all_tokens))) 
开发者ID:akzaidi,项目名称:fine-lm,代码行数:15,代码来源:text_encoder_test.py


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