<jupyter_start><jupyter_text>Topic Modeling This tutorial is available as an IPython notebook at [Malaya/example/topic-modeling](https://github.com/huseinzol05/Malaya/tree/master/example/topic-modeling).<jupyter_code>import pandas as pd
import malaya
df = pd.read_csv('tests/02032018.csv',sep=';')
df = df.iloc[3:,1:]
df.columns = ['text','label']
corpus = df.text.tolist()<jupyter_output><empty_output><jupyter_text>You can get this file [Malaya/tests](https://github.com/huseinzol05/Malaya/tree/master/tests). **This csv already stemmed.**  Load TransformerWe can use Transformer model to build topic modeling for corpus we have, the power of attention!<jupyter_code>electra = malaya.transformer.load(model = 'electra')
attention = malaya.topic_model.transformer(corpus, n_topics = 10, vectorizer = electra)<jupyter_output>INFO:tensorflow:Restoring parameters from /Users/huseinzolkepli/Malaya/electra-model/base/electra-base/model.ckpt<jupyter_text>Get topics<jupyter_code>attention.top_topics(5, top_n = 10, return_df = True)<jupyter_output><empty_output><jupyter_text>Get topics as string<jupyter_code>attention.get_topics(10)
attention = malaya.topic_model.transformer(corpus, n_topics = 10, vectorizer = electra)
attention.top_topics(5, top_n = 10, return_df = True)
attention.get_topics(10)<jupyter_output><empty_output><jupyter_text>Train LDA2Vec model<jupyter_code>lda2vec = malaya.topic_model.lda2vec(corpus, 10, vectorizer = 'skip-gram', skip = 4)<jupyter_output><empty_output><jupyter_text>Get topicsYou able to set to return as Pandas Dataframe or not by using `return_df` parameter<jupyter_code>lda2vec.top_topics(5, top_n = 10, return_df = True)<jupyter_output><empty_output><jupyter_text>Important sentences based on topics<jupyter_code>lda2vec.get_sentences(5)<jupyter_output><empty_output><jupyter_text>Get topics as string<jupyter_code>lda2vec.get_topics(10)<jupyter_output><empty_output><jupyter_text>Visualize topicsThis will initiate [pyLDAvis](https://github.com/bmabey/pyLDAvis) object, to understand [pyLDAvis](https://github.com/bmabey/pyLDAvis) more, read at https://github.com/bmabey/pyLDAvis.<jupyter_code>lda2vec.visualize_topics(notebook_mode = True)<jupyter_output>/usr/local/lib/python3.7/site-packages/past/types/oldstr.py:5: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
  from collections import Iterable<jupyter_text>Train LDA model<jupyter_code>lda = malaya.topic_model.lda(
    corpus,
    10,
    vectorizer = 'skip-gram',
    ngram = (1, 4),
    skip = 3,
)<jupyter_output><empty_output><jupyter_text>Print topics<jupyter_code>lda.top_topics(5, top_n = 10, return_df = True)<jupyter_output><empty_output><jupyter_text>Important sentences based on topics<jupyter_code>lda.get_sentences(5)<jupyter_output><empty_output><jupyter_text>Get topics<jupyter_code>lda.get_topics(10)<jupyter_output><empty_output><jupyter_text>Visualize topics<jupyter_code>lda.visualize_topics(notebook_mode = True)<jupyter_output>/usr/local/lib/python3.7/site-packages/past/types/oldstr.py:5: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
  from collections import Iterable<jupyter_text>Train NMF model<jupyter_code>nmf = malaya.topic_model.nmf(corpus,10)
nmf.top_topics(5, top_n = 10, return_df = True)
nmf.get_sentences(5)
nmf.get_topics(10)<jupyter_output><empty_output><jupyter_text>Train LSA model<jupyter_code>lsa = malaya.topic_model.lsa(corpus,10)
lsa.top_topics(5, top_n = 10, return_df = True)
lsa.get_sentences(5)
lsa.get_topics(10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11701556629092862, 'fraction_numerical': 0.022812667740203973, 'mean_word_length': 8.112469437652813, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 62, 'https://': 5, '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': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '165112', 'license': 'MIT', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1393, 'n_words': 229, 'path': 'docs/load-topic-modeling.ipynb', 'repo_name': 'illaiza115/malaya', 'size': '3726'}