def extract_tail_partial_sequence(partial_sequence_string, tail_length):
  """Extracts the tail of a partial sequence.

  If the specified tail length is larger than the partial sequence length, get
  the entire partial sequence. For example, when partial_sequence_string is
  '1_6' and tail_length is 4, it should give '1_6'.

  Args:
    partial_sequence_string: String, a partial sequence string, such as
        '1_6_7_6'.
    tail_length: Integer, length of the tail partial sequence to extract.

  Returns:
    The extracted tail partial sequence. When partial_sequence_string is
    '1_6_7_6' and tail_length is 2, it should give '7_6'.
  """
  partial_sequence_indices = partial_sequence_string.split('_')
  return '_'.join(partial_sequence_indices[-tail_length:])