class_docstr: A `Trimmer` that truncates the longest segment.
  
  A `Trimmer` that allocates a length budget to segments by shrinking whatever
  is the longest segment at each round at the end, until the total length of
  segments is no larger than the allocated budget.
  See `generate_mask()` for more details.
class_docstr_tok: ["A","`","Trimmer","`","that","truncates","the","longest","segment",".","A","`","Trimmer","`","that","allocates","a","length","budget","to","segments","by","shrinking","whatever","is","the","longest","segment","at","each","round","at","the","end",",","until","the","total","length","of","segments","is","no","larger","than","the","allocated","budget",".","See","`","generate_mask","(",")","`","for","more","details","."]
docstr: Calculates a truncation mask given a per-batch budget.
  
  Calculate a truncation mask given a budget of the max number of items for
  each batch row. The allocation of the budget is done using a
  'shrink the largest segment' algorithm. This algorithm identifies the
  currently longest segment (in cases of tie, picking whichever segment occurs
  first) and reduces its length by 1 by dropping its last element, repeating
  until the total length of segments is no larger than `_max_seq_length`.
  
  For example if the budget is [7] and we have segments of size
  [3, 4, 4], the truncate budget will be allocated as [2, 2, 3], going through
  truncation steps
    # Truncate the second segment.
    [3, 3, 4]
    # Truncate the last segment.
    [3, 3, 3]
    # Truncate the first segment.
    [2, 3, 3]
    # Truncate the second segment.
    [2, 2, 3]
  
  Args:
    segments: A list of `RaggedTensor` each w/ a shape of [num_batch,
      (num_items)].
  
  Returns:
    a list with len(segments) of `RaggedTensor`s, see superclass for details.
docstr_tok: ["Calculates","a","truncation","mask","given","a","per-batch","budget",".","Calculate","a","truncation","mask","given","a","budget","of","the","max","number","of","items","for","each","batch","row",".","The","allocation","of","the","budget","is","done","using","a","'shrink","the","largest","segment","'","algorithm",".","This","algorithm","identifies","the","currently","longest","segment","(","in","cases","of","tie",",","picking","whichever","segment","occurs","first",")","and","reduces","its","length","by","1","by","dropping","its","last","element",",","repeating","until","the","total","length","of","segments","is","no","larger","than","`","_max_seq_length","`",".","For","example","if","the","budget","is","[","7","]","and","we","have","segments","of","size","[","3",",","4",",","4","]",",","the","truncate","budget","will","be","allocated","as","[","2",",","2",",","3","]",",","going","through","truncation","steps","#","Truncate","the","second","segment",".","[","3",",","3",",","4","]","#","Truncate","the","last","segment",".","[","3",",","3",",","3","]","#","Truncate","the","first","segment",".","[","2",",","3",",","3","]","#","Truncate","the","second","segment",".","[","2",",","2",",","3","]","Args",":","segments",":","A","list","of","`","RaggedTensor","`","each","w\/","a","shape","of","[","num_batch",",","(","num_items",")","]",".","Returns",":","a","list","with","len","(","segments",")","of","`","RaggedTensor","`","s",",","see","superclass","for","details","."]
code: def generate_mask(self, segments):
      """Calculates a truncation mask given a per-batch budget.
  
      Calculate a truncation mask given a budget of the max number of items for
      each batch row. The allocation of the budget is done using a
      'shrink the largest segment' algorithm. This algorithm identifies the
      currently longest segment (in cases of tie, picking whichever segment occurs
      first) and reduces its length by 1 by dropping its last element, repeating
      until the total length of segments is no larger than `_max_seq_length`.
  
      For example if the budget is [7] and we have segments of size
      [3, 4, 4], the truncate budget will be allocated as [2, 2, 3], going through
      truncation steps
        # Truncate the second segment.
        [3, 3, 4]
        # Truncate the last segment.
        [3, 3, 3]
        # Truncate the first segment.
        [2, 3, 3]
        # Truncate the second segment.
        [2, 2, 3]
  
      Args:
        segments: A list of `RaggedTensor` each w/ a shape of [num_batch,
          (num_items)].
  
      Returns:
        a list with len(segments) of `RaggedTensor`s, see superclass for details.
      """
      with ops.name_scope("ShrinkLongestTrimmer/generate_mask"):
          segment_row_lengths = [
              _get_row_lengths(s, self._axis) for s in segments
          ]
          segment_row_lengths = array_ops_stack.stack(
              segment_row_lengths, axis=-1
          )
          segment_row_lengths = math_ops.cast(
              segment_row_lengths, dtypes.int32
          )
          budget = ops.convert_to_tensor(self._max_seq_length)
          results = array_ops_stack.unstack(
              _shrink_longest_allocation(segment_row_lengths, budget),
              axis=-1,
          )
  
          item_selectors = [
              item_selector_ops.FirstNItemSelector(i) for i in results
          ]
          return [
              i.get_selectable(s, self._axis)
              for s, i in zip(segments, item_selectors)
          ]
  
imports: import abc
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import array_ops_stack
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops.ragged import ragged_array_ops
  from tensorflow.python.ops.ragged import ragged_tensor
  from tensorflow_text.python.ops import item_selector_ops
  from tensorflow.python.framework import load_library
  from tensorflow.python.platform import resource_loader
  from tensorflow.python.ops import while_loop
label_desc: Use image node_id 2 for calling the ShrinkLongestTrimmer obj's underlying member method code with example usage: obj.generate_mask(segments) and returns: unknown