(vocabs, vocab_file_path)
Save vocabs, vocab: {"word": 1, ...}
Save vocabs, vocab: {"word": 1, ...}
Save vocabs vocab : { word : 1 ... }
def save_vocabs(vocabs, vocab_file_path):
  """Save vocabs, vocab: {"word": 1, ...}"""
  logging.info("Saving vocab to {}".format(vocab_file_path))
  id_to_vocab = {v: k for k, v in vocabs.items()}
  ordered_vocabs = collections.OrderedDict()
  for _id in sorted(vocabs.values()):
    ordered_vocabs[id_to_vocab[_id]] = _id

  if os.path.isfile(vocab_file_path):
    os.remove(vocab_file_path)
  if not os.path.exists(os.path.dirname(vocab_file_path)):
    os.makedirs(os.path.dirname(vocab_file_path))

  with open(vocab_file_path, "w", encoding='utf-8') as out_f:
    for word, _id in ordered_vocabs.items():
      out_f.write("{}\t{}\n".format(word, _id))
def save_vocabs ( vocabs , vocab_file_path ) : logging . info ( "Saving vocab to {}" . format ( vocab_file_path ) ) id_to_vocab = { v : k for k , v in vocabs . items ( ) } ordered_vocabs = collections . OrderedDict ( ) for _id in sorted ( vocabs . values ( ) ) : ordered_vocabs [ id_to_vocab [ _id ] ] = _id if os . path . isfile ( vocab_file_path ) : os . remove ( vocab_file_path ) if not os . path . exists ( os . path . dirname ( vocab_file_path ) ) : os . makedirs ( os . path . dirname ( vocab_file_path ) ) with open ( vocab_file_path , "w" , encoding = 'utf-8' ) as out_f : for word , _id in ordered_vocabs . items ( ) : out_f . write ( "{}\t{}\n" . format ( word , _id ) )