All Projects → JoeZJH → Labeled Lda Python

JoeZJH / Labeled Lda Python

Licence: mit
Implement of L-LDA Model(Labeled Latent Dirichlet Allocation Model) with python

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects
python2
120 projects
python27
39 projects

Projects that are alternatives of or similar to Labeled Lda Python

Lda
LDA topic modeling for node.js
Stars: ✭ 262 (+336.67%)
Mutual labels:  topic-modeling
Ldavis
R package for web-based interactive topic model visualization.
Stars: ✭ 466 (+676.67%)
Mutual labels:  topic-modeling
Owl
Owl - OCaml Scientific and Engineering Computing @ http://ocaml.xyz
Stars: ✭ 919 (+1431.67%)
Mutual labels:  topic-modeling
2018 Machinelearning Lectures Esa
Machine Learning Lectures at the European Space Agency (ESA) in 2018
Stars: ✭ 280 (+366.67%)
Mutual labels:  topic-modeling
Pyshorttextcategorization
Various Algorithms for Short Text Mining
Stars: ✭ 429 (+615%)
Mutual labels:  topic-modeling
Bigartm
Fast topic modeling platform
Stars: ✭ 563 (+838.33%)
Mutual labels:  topic-modeling
topicApp
A simple Shiny App for Topic Modeling in R
Stars: ✭ 40 (-33.33%)
Mutual labels:  topic-modeling
Lightlda
fast sampling algorithm based on CGS
Stars: ✭ 49 (-18.33%)
Mutual labels:  topic-modeling
Corex topic
Hierarchical unsupervised and semi-supervised topic models for sparse count data with CorEx
Stars: ✭ 439 (+631.67%)
Mutual labels:  topic-modeling
Pycmf
A python library for Collective Matrix Factorization (CMF)
Stars: ✭ 22 (-63.33%)
Mutual labels:  topic-modeling
Contextualized Topic Models
A python package to run contextualized topic modeling. CTMs combine BERT with topic models to get coherent topics. Also supports multilingual tasks. Cross-lingual Zero-shot model published at EACL 2021.
Stars: ✭ 318 (+430%)
Mutual labels:  topic-modeling
Guidedlda
semi supervised guided topic model with custom guidedLDA
Stars: ✭ 390 (+550%)
Mutual labels:  topic-modeling
Text2vec
Fast vectorization, topic modeling, distances and GloVe word embeddings in R.
Stars: ✭ 715 (+1091.67%)
Mutual labels:  topic-modeling
Unsupervised Aspect Extraction
Code for acl2017 paper "An unsupervised neural attention model for aspect extraction"
Stars: ✭ 277 (+361.67%)
Mutual labels:  topic-modeling
Top2vec
Top2Vec learns jointly embedded topic, document and word vectors.
Stars: ✭ 972 (+1520%)
Mutual labels:  topic-modeling
latent-semantic-analysis
Pipeline for training LSA models using Scikit-Learn.
Stars: ✭ 20 (-66.67%)
Mutual labels:  topic-modeling
Paper Reading
Paper reading list in natural language processing, including dialogue systems and text generation related topics.
Stars: ✭ 508 (+746.67%)
Mutual labels:  topic-modeling
Topicmodels
topics Models extension for Mallet & scikit-learn
Stars: ✭ 50 (-16.67%)
Mutual labels:  topic-modeling
Twitterldatopicmodeling
Uses topic modeling to identify context between follower relationships of Twitter users
Stars: ✭ 48 (-20%)
Mutual labels:  topic-modeling
Bertopic
Leveraging BERT and c-TF-IDF to create easily interpretable topics.
Stars: ✭ 745 (+1141.67%)
Mutual labels:  topic-modeling

Implement of L-LDA Model(Labeled Latent Dirichlet Allocation Model) with python

References:

  • Labeled LDA: A supervised topic model for credit attribution in multi-labeled corpora, Daniel Ramage...
  • Parameter estimation for text analysis, Gregor Heinrich.
  • Latent Dirichlet Allocation, David M. Blei, Andrew Y. Ng...

An efficient implementation based on Gibbs sampling

The following descriptions come from Labeled LDA: A supervised topic model for credit attribution in multi-labeled corpora, Daniel Ramage...

Introduction:

Labeled LDA is a topic model that constrains Latent Dirichlet Allocation by defining a one-to-one correspondence between LDA’s latent topics and user tags. Labeled LDA can directly learn topics(tags) correspondences.

Gibbs sampling:
  • Graphical model of Labeled LDA:
  • Generative process for Labeled LDA:
  • Gibbs sampling equation:

Usage

  • new llda model
  • training
  • ?is_convergence
  • update
  • inference
  • save model to disk
  • load model from disk
  • get top-k terms of target topic

Example

# @source code: example/exapmle.py

import sys
sys.path.append('../')
import model.labeled_lda as llda

# initialize data
labeled_documents = [("example example example example example"*10, ["example"]),
                     ("test llda model test llda model test llda model"*10, ["test", "llda_model"]),
                     ("example test example test example test example test"*10, ["example", "test"]),
                     ("good perfect good good perfect good good perfect good "*10, ["positive"]),
                     ("bad bad down down bad bad down"*10, ["negative"])]

# new a Labeled LDA model
# llda_model = llda.LldaModel(labeled_documents=labeled_documents, alpha_vector="50_div_K", eta_vector=0.001)
# llda_model = llda.LldaModel(labeled_documents=labeled_documents, alpha_vector=0.02, eta_vector=0.002)
llda_model = llda.LldaModel(labeled_documents=labeled_documents, alpha_vector=0.01)
print(llda_model)

# training
# llda_model.training(iteration=10, log=True)
while True:
    print("iteration %s sampling..." % (llda_model.iteration + 1))
    llda_model.training(1)
    print("after iteration: %s, perplexity: %s" % (llda_model.iteration, llda_model.perplexity()))
    print("delta beta: %s" % llda_model.delta_beta)
    if llda_model.is_convergent(method="beta", delta=0.01):
        break

# update
print("before updating: ", llda_model)
update_labeled_documents = [("new example test example test example test example test", ["example", "test"])]
llda_model.update(labeled_documents=update_labeled_documents)
print("after updating: ", llda_model)

# train again
# llda_model.training(iteration=10, log=True)
while True:
    print("iteration %s sampling..." % (llda_model.iteration + 1))
    llda_model.training(1)
    print("after iteration: %s, perplexity: %s" % (llda_model.iteration, llda_model.perplexity()))
    print("delta beta: %s" % llda_model.delta_beta)
    if llda_model.is_convergent(method="beta", delta=0.01):
        break

# inference
# note: the result topics may be different for difference training, because gibbs sampling is a random algorithm
document = "example llda model example example good perfect good perfect good perfect" * 100

topics = llda_model.inference(document=document, iteration=100, times=10)
print(topics)

# perplexity
# calculate perplexity on test data
perplexity = llda_model.perplexity(documents=["example example example example example",
                                              "test llda model test llda model test llda model",
                                              "example test example test example test example test",
                                              "good perfect good good perfect good good perfect good",
                                              "bad bad down down bad bad down"],
                                   iteration=30,
                                   times=10)
print("perplexity on test data: %s" % perplexity)
# calculate perplexity on training data
print("perplexity on training data: %s" % llda_model.perplexity())

# save to disk
save_model_dir = "../data/model"
# llda_model.save_model_to_dir(save_model_dir, save_derivative_properties=True)
llda_model.save_model_to_dir(save_model_dir)

# load from disk
llda_model_new = llda.LldaModel()
llda_model_new.load_model_from_dir(save_model_dir, load_derivative_properties=False)
print("llda_model_new", llda_model_new)
print("llda_model", llda_model)
print("Top-5 terms of topic 'negative': ", llda_model.top_terms_of_topic("negative", 5, False))
print("Doc-Topic Matrix: \n", llda_model.theta)
print("Topic-Term Matrix: \n", llda_model.beta)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].