- Notifications
You must be signed in to change notification settings - Fork1
KentoW/mixture-of-unigram-model
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
混合ユニグラムモデル(mixture of unigram model)をPythonで実装
無限混合ユニグラムモデル(infinite mixture of unigram model)をPythonで実装
# Sample code.frommixture_of_unigram_modelimportMUMalpha=0.01# 初期ハイパーパラメータalphabeta=0.01# 初期ハイパーパラメータbetaK=10# トピック数N=1000# 最大イテレーション回数converge=0.01# イテレーション10回ごとに対数尤度を計算し,その差分(converge)が小さければ学習を終了するmum=MUM("data.txt")mum.set_param(alpha,beta,K,N,converge)mum.learn()mum.output_model()
# Sample code.frominfinite_mixture_of_unigram_modelimportIMUMalpha=0.01# 初期ハイパーパラメータalphabeta=0.01# 初期ハイパーパラメータbetaN=1000# 最大イテレーション回数converge=0.01# イテレーション10回ごとに対数尤度を計算し,その差分(converge)が小さければ学習を終了するimum=IMUM("data.txt")imum.set_param(alpha,beta,N,converge)imum.learn()imum.output_model()
1単語をスペースで分割した1行1文書形式
先頭に#(シャープ)記号を入れてコメントを記述可能
# 文書1単語1 単語2 単語3 ...# 文書2単語10 単語11 単語11 ......
例としてWiki.pyを使用して収集した アニメのあらすじ文章をdata.txtに保存
必要な情報は各自で抜き取って使用してください.
modelmixture_of_unigram_model # 学習の種類@parametercorpus_filedata.txt # トレーニングデータのPATHhyper_parameter_alpha1.834245 # ハイパーパラメータalphahyper_parameter_beta0.089558 # ハイパーパラメータbetanumber_of_topic10 # トピック数number_of_iteration121 # 収束した時のイテレーション回数@likelihood # 尤度initial likelihood-1389.55970144last likelihood-1382.11395248@vocaburary # 学習で使用した単語vtarget_word出産target_word拓きtarget_word土target_word吉日target_word遂げる...@counttopic_document_freq1109 # トピック分布に必要な情報 左の数字から順に トピックID, そのトピックが割り当てられた文書の数topic_document_freq2167topic_document_freq352...topic_word_sum118137 # 単語生成確率分布に必要な情報 左の数字から順に トピックID, そのトピックが割り当てられた単語の数topic_word_freq1の1111 # 単語生成確率分布に必要な情報 左の数字から順に トピックID, 単語v, そのトピックが割り当てられた単語vの数topic_word_freq1に761topic_word_freq1を621topic_word_freq1は589...topic_word_sum227892topic_word_freq2の1762topic_word_freq2に1378topic_word_freq2を1138topic_word_freq2た995...@data # 訓練データと各文書に割り当てられたトピック(state)# state 4 # comment今日 は いい 天気 ...
About
Mixture of Unigram Model and Infinite Mixture of Unigram Model in Python. (混合ユニグラムモデルと無限混合ユニグラムモデル)
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published