def normalize_token_scalars(
    list_of_sequence_lists: list[list[list[TokenAndRawScalar]]],
) -> list[list[list[TokenAndScalar]]]:
    """The input ist a list of lists of lists of TokenAndRawScalar objects; the
    outer list is indexed by provenance, e.g. top or random token sequences;
    the middle list is indexed by token sequence; the inner list is indexed by token
    within a sequence.
    flatten() collapses the outermost level of nesting. We first flatten the whole thing,
    to compute the max activation across all tokens in all sequences of all provenances.
    We floor at 0, so if all activations are negative max_activation is 0.

    Then we step through each token in each sequence in each provenance, and divide by
    that max activation, and floor at 0, to get a normalized activation with ceiling at 1
    and floor at 0. This normalized_activation goes in a TokenAndScalar object, which
    is in a nested list structure parallel to the input structure."""
    indexed_by_token: list[TokenAndRawScalar] = flatten(flatten(list_of_sequence_lists))
    indexed_by_token = [
        TokenAndRawScalar(token=d.token, scalar=max(d.scalar, 0)) for d in indexed_by_token
    ]
    max_scalar = max([d.scalar for d in indexed_by_token]) or 0
    neuron_scale = create_scale_linear(max_scalar)

    return [
        [
            [
                TokenAndScalar(
                    token=d.token,
                    scalar=d.scalar,
                    normalized_scalar=neuron_scale(d.scalar),
                )
                for d in sequence
            ]
            for sequence in list_of_sequences
        ]
        for list_of_sequences in list_of_sequence_lists
    ]
The input ist a list of lists of lists of TokenAndRawScalar objects; the
    outer list is indexed by provenance, e.g. top or random token sequences;
    the middle list is indexed by token sequence; the inner list is indexed by token
    within a sequence.
    flatten() collapses the outermost level of nesting. We first flatten the whole thing,
    to compute the max activation across all tokens in all sequences of all provenances.
    We floor at 0, so if all activations are negative max_activation is 0.

    Then we step through each token in each sequence in each provenance, and divide by
    that max activation, and floor at 0, to get a normalized activation with ceiling at 1
    and floor at 0. This normalized_activation goes in a TokenAndScalar object, which
    is in a nested list structure parallel to the input structure.
neuron_explainer/activation_server/read_routes.py