def get_topics_description(df, comps, corpus, corpus_tokens, corpus_counts, n_words, ignore_comp=None):
    "\n    Get words from abstracts that describe the components the best way\n    using closest to the 'ideal' frequency vector - [0, ..., 0, 1, 0, ..., 0] in tokens of cosine distance\n    "
    logger.debug(f'Generating topics description, ignore_comp={ignore_comp}')
    comp_idx = {c: i for (i, c) in enumerate((c for c in comps if (c != ignore_comp)))}
    if (len(comp_idx) < 2):
        comp = list(comp_idx.keys())[0]
        if (ignore_comp is None):
            most_frequent = get_frequent_tokens(chain(*chain(*corpus)))
            return {comp: list(sorted(most_frequent.items(), key=(lambda kv: kv[1]), reverse=True))[:n_words]}
        else:
            most_frequent = get_frequent_tokens(chain(*chain(*[corpus[i] for i in np.flatnonzero(df['id'].isin(set(comps[comp])))])))
            return {comp: list(sorted(most_frequent.items(), key=(lambda kv: kv[1]), reverse=True))[:n_words], ignore_comp: []}
    comps_ids = {comp: list(np.flatnonzero(df['id'].isin(comp_pids))) for (comp, comp_pids) in comps.items()}
    result = _get_topics_description_cosine(comps_ids, corpus_tokens, corpus_counts, n_words, ignore_comp=ignore_comp)
    kwds = [(comp, ','.join([f'{t}:{v:.3f}' for (t, v) in vs])) for (comp, vs) in result.items()]
    logger.debug(('Description\n' + '\n'.join((f'{comp}: {kwd}' for (comp, kwd) in kwds))))
    return result
Get words from abstracts that describe the components the best way
using closest to the 'ideal' frequency vector - [0, ..., 0, 1, 0, ..., 0] in tokens of cosine distance
def get_topics_description(df, comps, corpus, corpus_tokens, corpus_counts, n_words, ignore_comp=None):
    "\n    Get words from abstracts that describe the components the best way\n    using closest to the 'ideal' frequency vector - [0, ..., 0, 1, 0, ..., 0] in tokens of cosine distance\n    "
    logger.debug(f'Generating topics description, ignore_comp={ignore_comp}')
    comp_idx = {c: i for (i, c) in enumerate((c for c in comps if (c != ignore_comp)))}
    if (len(comp_idx) < 2):
        comp = list(comp_idx.keys())[0]
        if (ignore_comp is None):
            most_frequent = get_frequent_tokens(chain(*chain(*corpus)))
            return {comp: list(sorted(most_frequent.items(), key=(lambda kv: kv[1]), reverse=True))[:n_words]}
        else:
            most_frequent = get_frequent_tokens(chain(*chain(*[corpus[i] for i in np.flatnonzero(df['id'].isin(set(comps[comp])))])))
            return {comp: list(sorted(most_frequent.items(), key=(lambda kv: kv[1]), reverse=True))[:n_words], ignore_comp: []}
    comps_ids = {comp: list(np.flatnonzero(df['id'].isin(comp_pids))) for (comp, comp_pids) in comps.items()}
    result = _get_topics_description_cosine(comps_ids, corpus_tokens, corpus_counts, n_words, ignore_comp=ignore_comp)
    kwds = [(comp, ','.join([f'{t}:{v:.3f}' for (t, v) in vs])) for (comp, vs) in result.items()]
    logger.debug(('Description\n' + '\n'.join((f'{comp}: {kwd}' for (comp, kwd) in kwds))))
    return result