<jupyter_start><jupyter_text>Input<jupyter_code>text = 'Most hotlines are at least partially staffed by trained volunteers, so check out agencies in your area.'
pred = {'body': text}
data = data_f.append(pred, ignore_index = True);
data
data.head()
from sklearn.feature_extraction.text import CountVectorizer
data.shape
cv = CountVectorizer(max_df=0.9,min_df=2,stop_words='english')

dtm = cv.fit_transform(data['body'])
dtm
from sklearn.decomposition import LatentDirichletAllocation
LDA = LatentDirichletAllocation(n_components=3,random_state=32)
LDA.fit(dtm)
len(cv.get_feature_names())
type(cv.get_feature_names())
import random
random_word_id = random.randint(0,1610)
cv.get_feature_names()[random_word_id]
len(LDA.components_)
type(LDA.components_)
LDA.components_.shape
single_topic = LDA.components_[0]
single_topic.argsort()
import numpy as np
single_topic.argsort()[-10:]
top_ten_words = single_topic.argsort()[-20:]
for index in top_ten_words:
    print(cv.get_feature_names()[index])
for i,topic in enumerate(LDA.components_):
    print(f"top 30 words for topic #{i}")
    print([cv.get_feature_names()[index] for index in topic.argsort()[-30:]])
    print('\n')
    print('\n')
    
topic_results = LDA.transform(dtm)
topic_results.shape
data['Topic'] = topic_results.argmax(axis=1)
data
len(data)<jupyter_output><empty_output><jupyter_text>Output<jupyter_code>def predict(val):
    if val == 0:
        print('Suicidal')
    elif val == 1:
        print('Abusive/Threatening')
    else:
        print('Completely Normal')
val = data['Topic'][len(data)-1]
predict(val)<jupyter_output>Completely Normal
{'fraction_non_alphanumeric': 0.13382899628252787, 'fraction_numerical': 0.01486988847583643, 'mean_word_length': 6.274774774774775, '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': '487683', 'license': 'Apache-2.0', 'n_tokens_mistral': 586, 'n_tokens_neox': 569, 'n_words': 109, 'path': 'models/Model.ipynb', 'repo_name': 'P-star-art/M7-Mind-Install', 'size': '1614'}