from typing import Union
from typing import Collection
from typing import Mapping


def _ensure_ids(
    labels_or_ids: Union[Collection[int], Collection[str]],
    label_to_id: Mapping[str, int],
) -> Collection[int]:
    """Convert labels to IDs."""
    return [
        label_to_id[l_or_i] if isinstance(l_or_i, str) else l_or_i
        for l_or_i in labels_or_ids
    ]