import math


def generate_IDF(corpus, corpus_dict, total_queries):
    """
    Function to generate IDF for all the words in the vocab.
    :param corpus: Corpus of words in the queries.
    :param corpus_dict: Mapping of query number and its corpus.
    :param total_queries: Total number of queries.
    :return idf_dict: Inverse Document Frequency Mapping.
    """

    # Compute the number of documents in which the words exist.
    idf_dict = dict()

    for word in corpus:

        count = 0
        for document_number, words_in_it in corpus_dict.items():

            if word in words_in_it:

                count += 1

        if count == 0:

            continue

        else:
            
            idf_dict[word] = math.log(total_queries / count)

    return idf_dict