reverb_purpose_extraction.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:Hanhan_NLP 作者: hanhanwu 项目源码 文件源码
def NMF_feature_extraction(text_lst, n_samples, n_features, n_topics, n_top_words):
    print "Extracting tf-idf features for NMF..."
    tfidf_vectorizer = TfidfVectorizer(max_df=0.95, min_df=2, stop_words='english')
    tfidf = tfidf_vectorizer.fit_transform(text_lst)
    print "Fitting the NMF model with tf-idf features," "n_samples=%d and n_features=%d..." % (n_samples, n_features)
    nmf = NMF(n_components=n_topics, random_state=1, alpha=.1, l1_ratio=.5).fit(tfidf)
    print "\nTopics in NMF model:" 
    tfidf_feature_names = tfidf_vectorizer.get_feature_names()
    print_top_words(nmf, tfidf_feature_names, n_top_words)
    print "*************end NMF****************"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号