當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。