nodes: 0, module; 1, function_definition; 2, function_name:_get_sorted_inputs; 3, parameters; 4, block; 5, identifier:filename; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, with_statement; 10, expression_statement; 11, expression_statement; 12, comment:# We'll need the keys to rearrange the inputs back into their original order; 13, expression_statement; 14, expression_statement; 15, for_statement; 16, return_statement; 17, identifier:delimiter; 18, string:"\n"; 19, comment:"""Returning inputs sorted according to decreasing length.
  
    This causes inputs of similar lengths to be processed in the same batch,
    facilitating early stopping for short sequences.
  
    Longer sequences are sorted first so that if you're going to get OOMs,
    you'll see it in the first batch.
  
    Args:
      filename: path to file with inputs, 1 per line.
      delimiter: str, delimits records in the file.
  
    Returns:
      a sorted list of inputs
  
    """; 20, call; 21, with_clause; 22, block; 23, assignment; 24, assignment; 25, assignment; 26, assignment; 27, pattern_list; 28, call; 29, block; 30, expression_list; 31, attribute; 32, argument_list; 33, with_item; 34, expression_statement; 35, expression_statement; 36, expression_statement; 37, comment:# Strip the last empty line.; 38, if_statement; 39, identifier:input_lens; 40, list_comprehension; 41, identifier:sorted_input_lens; 42, call; 43, identifier:sorted_keys; 44, dictionary; 45, identifier:sorted_inputs; 46, list; 47, identifier:i; 48, tuple_pattern; 49, identifier:enumerate; 50, argument_list; 51, expression_statement; 52, expression_statement; 53, identifier:sorted_inputs; 54, identifier:sorted_keys; 55, attribute; 56, identifier:info; 57, string:"Getting sorted inputs"; 58, as_pattern; 59, assignment; 60, assignment; 61, assignment; 62, not_operator; 63, block; 64, tuple; 65, for_in_clause; 66, identifier:sorted; 67, argument_list; 68, identifier:index; 69, identifier:_; 70, identifier:sorted_input_lens; 71, call; 72, assignment; 73, identifier:tf; 74, identifier:logging; 75, call; 76, as_pattern_target; 77, identifier:text; 78, call; 79, identifier:records; 80, call; 81, identifier:inputs; 82, list_comprehension; 83, subscript; 84, expression_statement; 85, identifier:i; 86, unary_operator; 87, pattern_list; 88, call; 89, identifier:input_lens; 90, keyword_argument; 91, attribute; 92, argument_list; 93, subscript; 94, identifier:i; 95, attribute; 96, argument_list; 97, identifier:f; 98, attribute; 99, argument_list; 100, attribute; 101, argument_list; 102, call; 103, for_in_clause; 104, identifier:inputs; 105, unary_operator; 106, call; 107, call; 108, identifier:i; 109, identifier:line; 110, identifier:enumerate; 111, argument_list; 112, identifier:key; 113, call; 114, identifier:sorted_inputs; 115, identifier:append; 116, subscript; 117, identifier:sorted_keys; 118, identifier:index; 119, attribute; 120, identifier:Open; 121, identifier:filename; 122, identifier:f; 123, identifier:read; 124, identifier:text; 125, identifier:split; 126, identifier:delimiter; 127, attribute; 128, argument_list; 129, identifier:record; 130, identifier:records; 131, integer:1; 132, attribute; 133, argument_list; 134, identifier:len; 135, argument_list; 136, identifier:inputs; 137, attribute; 138, argument_list; 139, identifier:inputs; 140, identifier:index; 141, identifier:tf; 142, identifier:gfile; 143, identifier:record; 144, identifier:strip; 145, identifier:inputs; 146, identifier:pop; 147, call; 148, identifier:operator; 149, identifier:itemgetter; 150, integer:1; 151, attribute; 152, argument_list; 153, identifier:line; 154, identifier:split
code: def _get_sorted_inputs(filename, delimiter="\n"):
    """Returning inputs sorted according to decreasing length.
  
    This causes inputs of similar lengths to be processed in the same batch,
    facilitating early stopping for short sequences.
  
    Longer sequences are sorted first so that if you're going to get OOMs,
    you'll see it in the first batch.
  
    Args:
      filename: path to file with inputs, 1 per line.
      delimiter: str, delimits records in the file.
  
    Returns:
      a sorted list of inputs
  
    """
    tf.logging.info("Getting sorted inputs")
    with tf.gfile.Open(filename) as f:
      text = f.read()
      records = text.split(delimiter)
      inputs = [record.strip() for record in records]
      # Strip the last empty line.
      if not inputs[-1]:
        inputs.pop()
    input_lens = [(i, -len(line.split())) for i, line in enumerate(inputs)]
    sorted_input_lens = sorted(input_lens, key=operator.itemgetter(1))
    # We'll need the keys to rearrange the inputs back into their original order
    sorted_keys = {}
    sorted_inputs = []
    for i, (index, _) in enumerate(sorted_input_lens):
      sorted_inputs.append(inputs[index])
      sorted_keys[index] = i
    return sorted_inputs, sorted_keys