<jupyter_start><jupyter_text>Topic modeling society related entrepreneurial papers<jupyter_code>is_social_corpus = jbv_df[ jbv_df.is_social_topic ]
society_related_abstracts_corpus = is_social_corpus.AB.tolist()
# tf_vectorizer = CountVectorizer(max_df=0.95, min_df=2, max_features=nb_features, stop_words=custom_stop_words)
tfidf_vectorizer = TfidfVectorizer(max_df=0.95, min_df=2, max_features=nb_features, stop_words=custom_stop_words)

tfidf_doc_mat = tfidf_vectorizer.fit_transform(society_related_abstracts_corpus)
tfidf_feat_names = tfidf_vectorizer.get_feature_names()
from textacy.tm import TopicModel

nb_topics=15
nmf = TopicModel(model='nmf', n_topics=nb_topics)
doc_term_mat = nmf.fit(tfidf_doc_mat)
doc_topic_mat = nmf.get_doc_topic_matrix(tfidf_doc_mat)
doc_topic_mat.shape
import numpy as np
topic_wts = np.nansum(doc_topic_mat, axis=0)
sorted_topic_wt_ids = np.argsort(topic_wts)
for idx in sorted_topic_wt_ids:
    print('Topic: {}, Wt: {}'.format(idx+1, topic_wts[idx]))
nmf.termite_plot(tfidf_doc_mat, tfidf_feat_names, topics=-1, n_terms=25, sort_terms_by='seriation')
for topic_idx, topic_data in nmf.top_topic_terms(tfidf_feat_names, topics=range(nb_topics), weights = True):
    topic_terms = [ topic_term + '*' + str(round(topic_prob, 2)) for topic_term, topic_prob in topic_data]
    print('topic', topic_idx + 1, ':', ' | '.join(topic_terms), '\n')
#     print('topic', topic_idx + 1, ':', ' | '.join(topic_terms), file=f)
for topic_idx, top_docs in nmf.top_topic_docs(doc_topic_mat, topics=[1, 12], top_n=3):
    print('Topic {}:\n'.format(topic_idx+1))
    for j in top_docs:
        print('Abstract from doc {}: {}\n'.format(j, jbv_df.AB.tolist()[j]))
#         print(jbv_df.DE.tolist()[j])<jupyter_output>Topic 2:

Abstract from doc 3504: Since its conception in 1999, the Global Reporting Initiative (GRI) has become a leading template for voluntary sustainability reporting by companies. Emerging on the crest of the debate about corporate social responsibility, appropriate roles for business, government, and civil society in the sustainability transition, and private forms of global governance, it is also a descendant of 1970s social movements. Drawing on extensive empirical data collected through interviews and documentary analysis in four countries, the institutional entrepreneurship framework is used to analyse three types of tactics deployed by GRI champions: discursive, material and charismatic. Central to GRI entrepreneurs' success was maintaining balance between the individual and collective interests of their diverse constituencies, between inclusiveness and efficient pursuit of technical objectives, and between building a new institution and not challenging existing institutions[...]
{'fraction_non_alphanumeric': 0.09230207953301715, 'fraction_numerical': 0.013133892739875957, 'mean_word_length': 6.8342857142857145, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '236257', 'license': 'RSA-MD', 'n_tokens_mistral': 914, 'n_tokens_neox': 865, 'n_words': 241, 'path': 'notebooks/0.1-spider101-kmeans-doc-clustering.ipynb', 'repo_name': 'CIT-ee/Darden-Entrepreneurship-Faculty-Corpus-Exploration', 'size': '2741'}