<jupyter_start><jupyter_text>Modeling<jupyter_code>cv = CountVectorizer(max_df=0.9, min_df=5, stop_words='english')
dtm = cv.fit_transform(sums)
pd.DataFrame(cv.get_feature_names_out(), columns=['Words'])
LDA = LatentDirichletAllocation(n_components=5,random_state=42)
# This can take awhile, we're dealing with a large amount of documents!
LDA.fit(dtm)
myDict = {}
word_distribution = LDA.components_ / LDA.components_.sum(axis=1)[:, np.newaxis]
cnt = 0
for index,topic in enumerate(word_distribution):
    print(f'THE TOP 30 WORDS FOR TOPIC #{index}')
    myDict[cnt] = [[cv.get_feature_names_out()[i], round(topic[i],3)] for i in topic.argsort()]
    print(list(reversed([cv.get_feature_names_out()[i] for i in topic.argsort()[-50:]])))
    print('\n')
    cnt += 1
sums_list = [item.split() for item in sums]
eval_coherence(myDict, sums_list)<jupyter_output>Evaluating topic coherence...
Done<jupyter_text>Store results<jupyter_code>results = pd.DataFrame(columns = np.array([['Topic_{}_words'.format(str(i)), 'Topic_{}_significance'.format(str(i))] for i in range(5)]).flatten())
results
for i in range(5):
    results['Topic_{}_words'.format(str(i))] = np.flip(myDict[i][-50:]).T[1]
    results['Topic_{}_significance'.format(str(i))] = np.flip(myDict[i][-50:]).T[0]
results.head()
results.to_excel('LDA_results.xlsx', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17702999268471104, 'fraction_numerical': 0.016093635698610095, 'mean_word_length': 7.191616766467066, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '35739', 'license': 'MIT', 'n_tokens_mistral': 543, 'n_tokens_neox': 514, 'n_words': 87, 'path': 'LDA.ipynb', 'repo_name': 'jasonsoti1/SherlocAnalysis', 'size': '1367'}