<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Topic Modeling Using Turicreate
王成军
wangchengjun@nju.edu.cn
计算传播网 http
Step1:  Download Data
Step2:  Transformations
https
Step3:  Text cleaning
Step4:  Topic modeling
Step5:  pred = m.predict(another_data) 
pred = m.predict(another_data, output_type='probabilities')
Initializing from other models
Step6:  Seeding the model with prior knowledge
<ASSISTANT_TASK:>
Python Code:
import turicreate as tc
Explanation: Topic Modeling Using Turicreate
王成军
wangchengjun@nju.edu.cn
计算传播网 http://computational-communication.com
End of explanation
sf = tc.SFrame.read_csv("/Users/datalab/bigdata/cjc/w15", 
                              header=False)
sf
Explanation: Download Data: <del>http://select.cs.cmu.edu/code/graphlab/datasets/wikipedia/wikipedia_raw/w15
End of explanation
dir(sf['X1']) 
bow = sf['X1']._count_words() 
type(sf['X1'])
type(bow)
bow.dict_has_any_keys(['limited'])
bow.dict_values()[0][:20]
sf
sf['bow'] = bow
sf
type(sf['bow'])
len(sf['bow'])
list(sf['bow'][0].items())[:3]
sf['tfidf'] = tc.text_analytics.tf_idf(sf['X1'])
sf
list(sf['tfidf'][0].items())[:5]
Explanation: Transformations
https://dato.com/learn/userguide/text/analysis.html
End of explanation
docs = sf['bow'].dict_trim_by_values(2)
docs = docs.dict_trim_by_keys(
    tc.text_analytics.stop_words(),
    exclude=True)
Explanation: Text cleaning
End of explanation
help(tc.topic_model.create)
help(tc.text_analytics.random_split)
train, test = tc.text_analytics.random_split(docs, .8)
m = tc.topic_model.create(train, 
                                num_topics=100,       # number of topics
                                num_iterations=100,   # algorithm parameters
                                alpha=None, beta=.1)  # hyperparameters
results = m.evaluate(test)
print(results['perplexity'])
m
m.get_topics()
help(m.get_topics)
topics = m.get_topics(num_words=10).unstack(['word','score'], \
                                new_column_name='topic_words')['topic_words'].apply(lambda x: x.keys())
for topic in topics:
    print(topic)
help(m)
def print_topics(m):
    topics = m.get_topics(num_words=5)
    topics = topics.unstack(['word','score'], new_column_name='topic_words')['topic_words']
    topics = topics.apply(lambda x: x.keys())
    for topic in topics:
        print(topic)
print_topics(m)
Explanation: Topic modeling
End of explanation
dir(m)
m.vocabulary
m.topics
m2 = tc.topic_model.create(docs,
                                 num_topics=100,
                                 initial_topics=m.topics)
Explanation: pred = m.predict(another_data) 
pred = m.predict(another_data, output_type='probabilities')
Initializing from other models
End of explanation
associations = tc.SFrame()
associations['word'] = ['recognition']
associations['topic'] = [0]
m2 = tc.topic_model.create(docs,
                                 num_topics=20,
                                 num_iterations=50,
                                 associations=associations, 
                                 verbose=False)
m2.get_topics(num_words=10)
print_topics(m2)
Explanation: Seeding the model with prior knowledge
End of explanation
<END_TASK>