from typing import Counter


def compute_signature(lang_data):
    """Compute a 'signature' using `lang_data`.

    Args:
        lang_data (dict): A dictionary containing the extracted tokens, the
            text's first line, a list of ignored characters and, if provided,
            the language's flags and unique tokens.

    Returns:
        dict: The computed signature.
    """
    tokens = lang_data.get("tokens")
    if not tokens:
        return {}

    lines = lang_data.get("lines", 1)
    signature = {}
    signature["tokens"] = Counter(tokens)
    for key in signature["tokens"]:
        signature["tokens"][key] /= lines

    signature["first_line"] = lang_data.get("first_line")
    signature["unique"] = lang_data.get("unique", [])
    signature["ignores"] = lang_data.get("ignores")
    signature["flags"] = lang_data.get("flags", [])
    return signature