TUOTUO ห้องสมุดการสร้างแบบจำลองหัวข้อที่เขียนใน Python Tuotuo ยังเป็นเด็กน่ารักลูกชายของฉันซึ่งตอนนี้อายุ 6 เดือน
ใช้ Package Manager Pip เพื่อติดตั้ง Tuotuo คุณอาจพบการกระจาย PYPI ที่นี่
pip install TuoTuo --upgradeปัจจุบันห้องสมุดรองรับการสร้างแบบจำลองหัวข้อผ่านการจัดสรร Dirichlet แฝง (LDA) เท่านั้น อย่างที่เราทราบ LDA สามารถนำไปใช้ได้โดยใช้การสุ่มตัวอย่าง Gibbs และการอนุมานแบบแปรปรวนเราเลือกหลังเนื่องจากมีความซับซ้อนทางคณิตศาสตร์มากขึ้น
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 นี้: รูปแบบหัวข้อประสาทด้วยการเรียนรู้การเสริมแรง
มิกซ์