code: def resize(att_mat, max_length=None):
    
    for i, att in enumerate(att_mat):
      # Add extra batch dim for viz code to work.
      if att.ndim == 3:
        att = np.expand_dims(att, axis=0)
      if max_length is not None:
        # Sum across different attention values for each token.
        att = att[:, :, :max_length, :max_length]
        row_sums = np.sum(att, axis=2)
        # Normalize
        att /= row_sums[:, :, np.newaxis]
      att_mat[i] = att
    return att_mat
docs: Normalize attention matrices and reshape as necessary.