def _get_topics_description_cosine(comps, corpus_tokens, corpus_counts, n_words, ignore_comp=None):
    "\n    Select words with the frequency vector that is the closest to the 'ideal' frequency vector\n    ([0, ..., 0, 1, 0, ..., 0]) in tokens of cosine distance\n    "
    logger.debug('Compute average tokens counts per components')
    comp_idx = {c: i for (i, c) in enumerate((c for c in comps if (c != ignore_comp)))}
    tokens_freqs_per_comp = np.zeros(shape=(len(comp_idx), corpus_counts.shape[1]), dtype=np.float)
    for (comp, comp_ids) in comps.items():
        if (comp != ignore_comp):
            tokens_freqs_per_comp[comp_idx[comp], :] = np.sum(corpus_counts[comp_ids, :], axis=0)
    tokens_freqs_total = np.sum(tokens_freqs_per_comp, axis=0)
    tokens_freqs_norm = np.sqrt(np.diag((tokens_freqs_per_comp.T @ tokens_freqs_per_comp)))
    tokens_freqs_per_comp = (tokens_freqs_per_comp / tokens_freqs_norm)
    logger.debug('Take frequent tokens that have the most descriptive frequency vector for topics')
    cluster_mask = np.eye(len(comp_idx))
    distance = (tokens_freqs_per_comp.T @ cluster_mask)
    adjusted_distance = (distance.T * np.log(tokens_freqs_total))
    result = {}
    for comp in comps.keys():
        if (comp == ignore_comp):
            result[comp] = []
            continue
        c = comp_idx[comp]
        cluster_tokens_idx = np.argsort((- adjusted_distance[c, :]))[:n_words].tolist()
        result[comp] = [(corpus_tokens[i], adjusted_distance[(c, i)]) for i in cluster_tokens_idx]
    return result
Select words with the frequency vector that is the closest to the 'ideal' frequency vector
([0, ..., 0, 1, 0, ..., 0]) in tokens of cosine distance
def _get_topics_description_cosine(comps, corpus_tokens, corpus_counts, n_words, ignore_comp=None):
    "\n    Select words with the frequency vector that is the closest to the 'ideal' frequency vector\n    ([0, ..., 0, 1, 0, ..., 0]) in tokens of cosine distance\n    "
    logger.debug('Compute average tokens counts per components')
    comp_idx = {c: i for (i, c) in enumerate((c for c in comps if (c != ignore_comp)))}
    tokens_freqs_per_comp = np.zeros(shape=(len(comp_idx), corpus_counts.shape[1]), dtype=np.float)
    for (comp, comp_ids) in comps.items():
        if (comp != ignore_comp):
            tokens_freqs_per_comp[comp_idx[comp], :] = np.sum(corpus_counts[comp_ids, :], axis=0)
    tokens_freqs_total = np.sum(tokens_freqs_per_comp, axis=0)
    tokens_freqs_norm = np.sqrt(np.diag((tokens_freqs_per_comp.T @ tokens_freqs_per_comp)))
    tokens_freqs_per_comp = (tokens_freqs_per_comp / tokens_freqs_norm)
    logger.debug('Take frequent tokens that have the most descriptive frequency vector for topics')
    cluster_mask = np.eye(len(comp_idx))
    distance = (tokens_freqs_per_comp.T @ cluster_mask)
    adjusted_distance = (distance.T * np.log(tokens_freqs_total))
    result = {}
    for comp in comps.keys():
        if (comp == ignore_comp):
            result[comp] = []
            continue
        c = comp_idx[comp]
        cluster_tokens_idx = np.argsort((- adjusted_distance[c, :]))[:n_words].tolist()
        result[comp] = [(corpus_tokens[i], adjusted_distance[(c, i)]) for i in cluster_tokens_idx]
    return result