from typing import Counter


def term_freq(tokens) -> dict: 
    """
    Takes in a spacy doc object and returns a dictionary of term frequency for each token.
    """
    # count how many times unique tokens appear in the doc
    counts = Counter([token.text for token in tokens])
    # return a dictionary with token as key and frequency as value
    return {token: count/len(tokens) for (token, count) in counts.items()}