Raw word counts overweight common words that appear everywhere and carry little meaning ("the", "a"). TF-IDF fixes this by multiplying two signals: term frequency (how often the word appears in this document) and inverse document frequency (how rare the word is across the whole corpus):
where N is the number of documents in the corpus and df(t) is how many of them contain t at least once.
Your task: implement tf_idf(term, document, corpus), where document is a list of tokens (assume it's one of the entries in corpus), and corpus is a list of token-lists.