Giter Club home page Giter Club logo

bayespa's Introduction

BayesPA

This repository contains code for the following paper:

Specifically, the code is a streaming implementation of MedLDA

What is MedLDA ?

Maximum Entropy Discriminant LDA (MedLDA) is a max-margin supervised topic model. It jointly trains Latent Dirichlet Allocation (LDA) with SVM, and obtains a topic representation more suitable for discriminative tasks such as classification.

What is BayesPA ?

Online Bayesian PA (BayesPA) is a generalization of classic Passive-Aggressive learning to the Bayesian and latent-variable setting. For every incoming mini-batch of documents, BayesPA first applies Bayes' rule to update the LDA topic model, then projects the posterior distribution to a region where the hinge-loss on the mini-batch data is minimized.

How to Use

The python interface of Online MedLDA is simple.

To use, simply

import medlda

To create a classifer with 2 labels and 61188 words,

pamedlda = medlda.OnlineGibbsMedLDA(num_topic = 5, labels = 2, words = 61188)

The training and inference are also straightfoward,

pamedlda.train_with_gml('../data/binary_train.gml', batchsize=64)
(pred, ind, acc) = pamedlda.infer_with_gml('../data/binary_test.gml', num_sample=100)

Please refer to docs for more detals.

Installing Online MedLDA

This release is for early adopters of this premature software. Please let us know if you have comments or suggestions. Contact: tianlinshi [AT] gmail.com

Online MedLDA is written in C++ 11, with a friendly python interface. It depends on gcc >= 4.8, python (numpy >= 1.7.0, distutils) and boost::python. To install, follow the instructions below.

Dependencies (Ubuntu)

# system dependency
sudo apt-get install libboost-all-dev gcc-4.8
sudo apt-get install python-numpy

Dependencies (OS X, Homebrew)

brew install gcc
brew install boost --cc=gcc-4.9
brew install boost-python --cc=gcc-4.9
pip install numpy scipy

Installation

sudo python setup.py install

Citation

If you use online MedLDA in your work, please cite

Shi, T., & Zhu, J. (2014). Online Bayesian Passive-Aggressive Learning. In Proceedings of The 31st International Conference on Machine Learning (pp. 378-386).

License (GPL V3)

Copyright (C) 2014 Tianlin Shi

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributeCd in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

bayespa's People

Contributors

strin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bayespa's Issues

Obtain "topics"

Hi, is there any way of obtaining some description of the topics learned by this model (for example, a list of top words)?

Help me to solve this issues plz

when I enter
$sudo python setup.py install
I got this follow blew:

/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'zip_safe'
warnings.warn(msg)
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/medlda
copying medlda/init.py -> build/lib.linux-x86_64-2.7/medlda
running build_ext
building 'libbayespagibbs' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/medlda
creating build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA
creating build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src
creating build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/utils/ap.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/ap.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/utils/cholesky.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/cholesky.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/utils/cokus.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/cokus.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/utils/InverseGaussian.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/InverseGaussian.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/utils/Mapper.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/Mapper.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/utils/MVGaussian.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/MVGaussian.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/utils/objcokus.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/objcokus.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/utils/spdinverse.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/spdinverse.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/utils/Document.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/Document.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/utils/Sample.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/Sample.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/OnlineGibbsMedLDA.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/OnlineGibbsMedLDA.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -Imedlda/OnlineGibbsMedLDA/inc -Imedlda/OnlineGibbsMedLDA/inc/utils -I/usr/include/python2.7 -c medlda/OnlineGibbsMedLDA/src/OnlineGibbsMedLDAWrapper.cpp -o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/OnlineGibbsMedLDAWrapper.o -std=c++11 -w
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/ap.o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/cholesky.o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/cokus.o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/InverseGaussian.o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/Mapper.o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/MVGaussian.o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/objcokus.o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/spdinverse.o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/Document.o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/utils/Sample.o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/OnlineGibbsMedLDA.o build/temp.linux-x86_64-2.7/medlda/OnlineGibbsMedLDA/src/OnlineGibbsMedLDAWrapper.o -L/opt/local/lib/ -lboost_python-mt -o build/lib.linux-x86_64-2.7/libbayespagibbs.so
/usr/bin/ld: cannot find -lboost_python-mt
collect2: error: ld returned 1 exit status
error: command 'g++' failed with exit status 1

libboost-all-dev is already the newest version.
gcc-4.8 is already the newest version.
python-numpy is already the newest version.
Plz help.

release multi-task medlda

  • refractor global sample representation
  • implement multi-task sampling procedure
  • implement multi-task wrapper

accuracy decays with more topics

with the following setting

import medlda
log = open("20ng_result.txt", "a")
batchsize = 512
label = 20
numword = 53975
num_sample = 100
for k in range(20, 120, 20):
        pamedlda = medlda.OnlineGibbsMedLDA(num_topic = k, labels = label, words = numword, alpha=1/k)
        pamedlda.train_with_gml('/home/wenbo/mfs/data/20ng/20ng_train.gml', batchsize)
        (pred, ind, acc) = pamedlda.infer_with_gml('/home/wenbo/mfs/data/20ng/20ng_test.gml', num_sample)
        log.write("topic: %d, batch: %d, numsample: %d, acc: %0.2f\n" % (k, batchsize, num_sample, acc))
log.close()

the results seem to differ from original paMedLDAgibbs implementation. Here the accuracy drops dramatically as the number of topics k increases.

topic: 10, batch: 512, numsample: 100, acc: 0.80
topic: 20, batch: 512, numsample: 100, acc: 0.80
topic: 30, batch: 512, numsample: 100, acc: 0.80
topic: 40, batch: 512, numsample: 100, acc: 0.80
topic: 50, batch: 512, numsample: 100, acc: 0.79
topic: 60, batch: 512, numsample: 100, acc: 0.78
topic: 70, batch: 512, numsample: 100, acc: 0.76
topic: 80, batch: 512, numsample: 100, acc: 0.72
topic: 90, batch: 512, numsample: 100, acc: 0.72
topic: 100, batch: 512, numsample: 100, acc: 0.70

Obtain scores from infer_with_gml

Hi, thank you for this project! I was able to set up, train and infer this model on my own (binary classification) dataset.

However, infer_with_gml only provides me predicted labels; I would like to obtain a score that I can later use to construct an ROC curve for this model.

Could you guide me on how to modify the code to obtain scores instead of binary predictions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.