TuoTuo
Stable 0.2.7 release
Tuotuo用Python編寫的主題建模庫。 Tuotuo也是一個可愛的男孩,我的兒子,現在已經6個月大了。
使用包裝管理器PIP安裝Tuotuo。您可能會在這裡找到PYPI分佈。
pip install TuoTuo --upgrade當前,庫僅支持通過潛在Dirichlet分配(LDA)進行主題建模。眾所周知,可以使用Gibbs採樣和變異推理來實現LDA,我們選擇後者,因為這在數學上更複雜
import torch as tr
from tuotuo . generator import doc_generator
gen = doc_generator (
M = 100 ,
# we sample 100 documents
L = 20 ,
# each document would contain 20 pre-defined words
topic_prior = tr . tensor ([ 1 , 1 , 1 , 1 , 1 ], dtype = tr . double )
# we use a exchangable Dirichlet Distribution as our topic prior,
# that is a uniform distribution on 5 topics
)
train_docs = gen . generate_doc () from tuotuo . lda_model import LDASmoothed
import matplotlib . pyplot as plt
lda = LDASmoothed (
num_topics = 5 ,
)
perplexes = lda . fit (
train_docs ,
sampling = False ,
verbose = True ,
return_perplexities = True ,
)
plt . plot ( perplexes )
= >= >= >= >= >= >= >= >
Topic Dirichlet Prior , Alpha
1
Exchangeable Word Dirichlet Prior , Eta
1
Var Inf - Word Dirichlet prior , Lambda
( 5 , 40 )
Var Inf - Topic Dirichlet prior , Gamma
( 100 , 5 )
Init perplexity = 84.99592157507153
End perplexity = 45.96696541539976 
for topic_index in range ( lda . _lambda_ . shape [ 0 ]):
top5 = np . argsort ( lda . _lambda_ [ topic_index ,:],)[ - 5 :]
print ( f"Topic { topic_index } " )
for i , idx in enumerate ( top5 ):
print ( f"Top { i + 1 } -> { lda . train_doc . idx_to_vocab [ idx ] } " )
print ()
= >= >= >= >= >= >= >= >
Topic 0
Top 1 -> physical
Top 2 -> quantum
Top 3 -> research
Top 4 -> scientst
Top 5 -> astrophysics
Topic 1
Top 1 -> divorce
Top 2 -> attorney
Top 3 -> court
Top 4 -> bankrupt
Top 5 -> contract
Topic 2
Top 1 -> content
Top 2 -> Craftsmanship
Top 3 -> concert
Top 4 -> asymmetrical
Top 5 -> Symmetrical
Topic 3
Top 1 -> recreation
Top 2 -> FIFA
Top 3 -> football
Top 4 -> Olympic
Top 5 -> athletics
Topic 4
Top 1 -> fever
Top 2 -> appetite
Top 3 -> contagious
Top 4 -> decongestant
Top 5 -> injection正如我們可以從前5個單詞中看到的那樣,我們可以輕鬆地實現以下映射:
主題0->科學主題1->法律主題2->藝術主題3->體育主題4->健康
歡迎拉動請求。對於重大更改,請先開設一個問題,以討論您想更改的內容。
由於沒有可用的成熟主題建模庫,因此我們還在尋找想在以下方向上做出貢獻的合作者:
這部分完成了大部分工作,我們仍然需要研究:
擴展庫以支持此ICML論文之後的神經變性推斷:文本處理的神經變異推斷
擴展培訓以支持此ACL論文:通過增強學習的神經主題模型支持加強學習
麻省理工學院