utils.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:seq2seq 作者: google 项目源码 文件源码
def create_temporary_vocab_file(words, counts=None):
  """
  Creates a temporary vocabulary file.

  Args:
    words: List of words in the vocabulary

  Returns:
    A temporary file object with one word per line
  """
  vocab_file = tempfile.NamedTemporaryFile()
  if counts is None:
    for token in words:
      vocab_file.write((token + "\n").encode("utf-8"))
  else:
    for token, count in zip(words, counts):
      vocab_file.write("{}\t{}\n".format(token, count).encode("utf-8"))
  vocab_file.flush()
  return vocab_file
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号