def create_terms_of_topic_dict(features, topic_term_matrix, num_terms=8):

    """
    Creates a dictionary containing a mapping from topics to a list of terms
    """


    dic = {}

    for r in range(topic_term_matrix.shape[0]):
        terms = []
        for i in topic_term_matrix[r].data.argsort()[: -num_terms-1 :-1]:
            # this gives us the index of the best indices, which we now have to convert to feature indexes
            index = topic_term_matrix[r].indices[i]
            terms.append(features[index])
        dic[r] = terms

    return dic