nodes: 0, module; 1, function_definition; 2, function_name:_build_vocab; 3, parameters; 4, block; 5, identifier:filename; 6, identifier:vocab_path; 7, identifier:vocab_size; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, with_statement; 15, comment:"""Reads a file to build a vocabulary of `vocab_size` most common words.
  
     The vocabulary is sorted by occurrence count and has one word per line.
     Originally from:
     https://github.com/tensorflow/models/blob/master/tutorials/rnn/ptb/reader.py
  
    Args:
      filename: file to read list of words from.
      vocab_path: path where to save the vocabulary.
      vocab_size: size of the vocabulary to generate.
    """; 16, assignment; 17, assignment; 18, assignment; 19, assignment; 20, assignment; 21, with_clause; 22, block; 23, identifier:data; 24, call; 25, identifier:counter; 26, call; 27, identifier:count_pairs; 28, call; 29, pattern_list; 30, call; 31, identifier:words; 32, subscript; 33, with_item; 34, expression_statement; 35, identifier:_read_words; 36, argument_list; 37, attribute; 38, argument_list; 39, identifier:sorted; 40, argument_list; 41, identifier:words; 42, identifier:_; 43, identifier:list; 44, argument_list; 45, identifier:words; 46, slice; 47, as_pattern; 48, call; 49, identifier:filename; 50, identifier:collections; 51, identifier:Counter; 52, identifier:data; 53, call; 54, keyword_argument; 55, call; 56, identifier:vocab_size; 57, call; 58, as_pattern_target; 59, attribute; 60, argument_list; 61, attribute; 62, argument_list; 63, identifier:key; 64, lambda; 65, identifier:zip; 66, argument_list; 67, identifier:open; 68, argument_list; 69, identifier:f; 70, identifier:f; 71, identifier:write; 72, call; 73, identifier:counter; 74, identifier:items; 75, lambda_parameters; 76, tuple; 77, list_splat; 78, identifier:vocab_path; 79, string:"w"; 80, attribute; 81, argument_list; 82, identifier:x; 83, unary_operator; 84, subscript; 85, identifier:count_pairs; 86, string:"\n"; 87, identifier:join; 88, identifier:words; 89, subscript; 90, identifier:x; 91, integer:0; 92, identifier:x; 93, integer:1
code: def _build_vocab(filename, vocab_path, vocab_size):
    """Reads a file to build a vocabulary of `vocab_size` most common words.
  
     The vocabulary is sorted by occurrence count and has one word per line.
     Originally from:
     https://github.com/tensorflow/models/blob/master/tutorials/rnn/ptb/reader.py
  
    Args:
      filename: file to read list of words from.
      vocab_path: path where to save the vocabulary.
      vocab_size: size of the vocabulary to generate.
    """
    data = _read_words(filename)
    counter = collections.Counter(data)
    count_pairs = sorted(counter.items(), key=lambda x: (-x[1], x[0]))
    words, _ = list(zip(*count_pairs))
    words = words[:vocab_size]
    with open(vocab_path, "w") as f:
      f.write("\n".join(words))