Skip to main content

Zenodo citation

lda implements latent Dirichlet allocation (LDA) using collapsed Gibbs sampling. lda is fast and is tested on Linux, OS X, and Windows. This is a maintainance fork of the original code for newer Python versions.

You can read more about lda in the documentation.

Installation

pip install ldafork

Getting started

lda.LDA implements latent Dirichlet allocation (LDA). The interface follows conventions found in scikit-learn.

The following demonstrates how to inspect a model of a subset of the Reuters news dataset. The input below, X, is a document-term matrix (sparse matrices are accepted).

>>> import numpy as np
>>> import lda
>>> import lda.datasets
>>> X = lda.datasets.load_reuters()
>>> vocab = lda.datasets.load_reuters_vocab()
>>> titles = lda.datasets.load_reuters_titles()
>>> X.shape
(395, 4258)
>>> X.sum()
84010
>>> model = lda.LDA(n_topics=20, n_iter=1500, random_state=1)
>>> model.fit(X)  # model.fit_transform(X) is also available
>>> topic_word = model.topic_word_  # model.components_ also works
>>> n_top_words = 8
>>> for i, topic_dist in enumerate(topic_word):
...     topic_words = np.array(vocab)[np.argsort(topic_dist)][:-(n_top_words+1):-1]
...     print('Topic {}: {}'.format(i, ' '.join(topic_words)))

Topic 0: british churchill sale million major letters west britain
Topic 1: church government political country state people party against
Topic 2: elvis king fans presley life concert young death
Topic 3: yeltsin russian russia president kremlin moscow michael operation
Topic 4: pope vatican paul john surgery hospital pontiff rome
Topic 5: family funeral police miami versace cunanan city service
Topic 6: simpson former years court president wife south church
Topic 7: order mother successor election nuns church nirmala head
Topic 8: charles prince diana royal king queen parker bowles
Topic 9: film french france against bardot paris poster animal
Topic 10: germany german war nazi letter christian book jews
Topic 11: east peace prize award timor quebec belo leader
Topic 12: n't life show told very love television father
Topic 13: years year time last church world people say
Topic 14: mother teresa heart calcutta charity nun hospital missionaries
Topic 15: city salonika capital buddhist cultural vietnam byzantine show
Topic 16: music tour opera singer israel people film israeli
Topic 17: church catholic bernardin cardinal bishop wright death cancer
Topic 18: harriman clinton u.s ambassador paris president churchill france
Topic 19: city museum art exhibition century million churches set

The document-topic distributions are available in model.doc_topic_.

>>> doc_topic = model.doc_topic_
>>> for i in range(10):
...     print("{} (top topic: {})".format(titles[i], doc_topic[i].argmax()))
0 UK: Prince Charles spearheads British royal revolution. LONDON 1996-08-20 (top topic: 8)
1 GERMANY: Historic Dresden church rising from WW2 ashes. DRESDEN, Germany 1996-08-21 (top topic: 13)
2 INDIA: Mother Teresa's condition said still unstable. CALCUTTA 1996-08-23 (top topic: 14)
3 UK: Palace warns British weekly over Charles pictures. LONDON 1996-08-25 (top topic: 8)
4 INDIA: Mother Teresa, slightly stronger, blesses nuns. CALCUTTA 1996-08-25 (top topic: 14)
5 INDIA: Mother Teresa's condition unchanged, thousands pray. CALCUTTA 1996-08-25 (top topic: 14)
6 INDIA: Mother Teresa shows signs of strength, blesses nuns. CALCUTTA 1996-08-26 (top topic: 14)
7 INDIA: Mother Teresa's condition improves, many pray. CALCUTTA, India 1996-08-25 (top topic: 14)
8 INDIA: Mother Teresa improves, nuns pray for "miracle". CALCUTTA 1996-08-26 (top topic: 14)
9 UK: Charles under fire over prospect of Queen Camilla. LONDON 1996-08-26 (top topic: 8)

Requirements

Python 3.6+ is required. The following packages are required and will be installed along with with ldafork when you use pip:

Caveat

lda aims for simplicity. (It happens to be fast, as essential parts are written in C via Cython.) If you are working with a very large corpus you may wish to use more sophisticated topic models such as those implemented in hca and MALLET. hca is written entirely in C and MALLET is written in Java. Unlike lda, hca can use more than one processor at a time. Both MALLET and hca implement topic models known to be more robust than standard latent Dirichlet allocation.

Notes

Latent Dirichlet allocation is described in Blei et al. (2003) and Pritchard et al. (2000). Inference using collapsed Gibbs sampling is described in Griffiths and Steyvers (2004).

Other implementations

License

lda is licensed under Version 2.0 of the Mozilla Public License.

Release files for ldafork 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for ldafork 1.2.0
File
ldafork-1.2.0-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
ldafork-1.2.0-cp38-cp38-win32.whl CPython 3.8 CPython 3.8 Windows x86-32 Details
ldafork-1.2.0-cp38-cp38-manylinux1_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.5+ x86-64 Details
ldafork-1.2.0-cp38-cp38-manylinux1_i686.whl CPython 3.8 CPython 3.8 Linux glibc 2.5+ x86-32 Details
ldafork-1.2.0-cp38-cp38-macosx_10_15_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.15+ x86-64 Details
ldafork-1.2.0-cp38-cp38-macosx_10_14_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.14+ x86-64 Details
ldafork-1.2.0-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
ldafork-1.2.0-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details
ldafork-1.2.0-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details
ldafork-1.2.0-cp37-cp37m-manylinux1_i686.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-32 Details
ldafork-1.2.0-cp37-cp37m-macosx_10_15_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.15+ x86-64 Details
ldafork-1.2.0-cp37-cp37m-macosx_10_14_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.14+ x86-64 Details
ldafork-1.2.0-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
ldafork-1.2.0-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
ldafork-1.2.0-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
ldafork-1.2.0-cp36-cp36m-manylinux1_i686.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32 Details
ldafork-1.2.0-cp36-cp36m-macosx_10_15_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.15+ x86-64 Details
ldafork-1.2.0-cp36-cp36m-macosx_10_14_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64 Details

Total release size:7.4 MB

Release files / ldafork-1.2.0-cp38-cp38-win_amd64.whl

Download URL ldafork-1.2.0-cp38-cp38-win_amd64.whl
Size 346.0 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
605faa687ec2092bcd591063c08345175f9a44e23cc033240e86416157341c40
BLAKE2b-256 checksum
How to use checksums
b86e9d14fc1a75de046f9dca274bd9afd963559f112108606d8e78ab1aa22251
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp38-cp38-win32.whl

Download URL ldafork-1.2.0-cp38-cp38-win32.whl
Size 333.3 kB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
7c6d3c7f1f5e087fac7890e7aa4792812e8a964a92f7eaced10727d6da54ef02
BLAKE2b-256 checksum
How to use checksums
9e69db96e4dc9491eaab0c57e4ce8d264d9bb355ee6a22aea86e6703b5794eee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp38-cp38-manylinux1_x86_64.whl

Download URL ldafork-1.2.0-cp38-cp38-manylinux1_x86_64.whl
Size 564.0 kB
Tags CPython 3.8 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
61e38e1a34510a8eab3a1d075fb18ad374765898df475ca49267f2f80889db1b
BLAKE2b-256 checksum
How to use checksums
f7863b92084b0abac056628061141c5257193b819fd5e659c56dec55198246e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp38-cp38-manylinux1_i686.whl

Download URL ldafork-1.2.0-cp38-cp38-manylinux1_i686.whl
Size 547.6 kB
Tags CPython 3.8 Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
58c747b7f898ec40e68b1726e83a01c3831e3201f3fe65f0572bde1b301671f8
BLAKE2b-256 checksum
How to use checksums
690750bb26f7816c413bc9d6bcca6aac0c3ad2c5ccce1fb6ea0ebf8b3349342b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp38-cp38-macosx_10_15_x86_64.whl

Download URL ldafork-1.2.0-cp38-cp38-macosx_10_15_x86_64.whl
Size 344.8 kB
Tags CPython 3.8 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
5a179376d1bab1e9fa24abd80919f1f7e45611fc25e2b8ead37319030bb1a75f
BLAKE2b-256 checksum
How to use checksums
32bfe46345d7ffa2dd34e96c28f2136f2ddfbcecc92aaa27e4affcfab6ecb9af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp38-cp38-macosx_10_14_x86_64.whl

Download URL ldafork-1.2.0-cp38-cp38-macosx_10_14_x86_64.whl
Size 345.3 kB
Tags CPython 3.8 macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
8961fa74eda2931e7c709878ec2cbd1761d9edfe39e2fb14d07abc4501ac9115
BLAKE2b-256 checksum
How to use checksums
806ba33de36873013daad04ee01554b2870c20d0171a0378800f915cf1a587c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp37-cp37m-win_amd64.whl

Download URL ldafork-1.2.0-cp37-cp37m-win_amd64.whl
Size 345.2 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
c13eeafc247434196dd8b8630033d906ce7f7512ba73b6ca2b4c6068aa60eda0
BLAKE2b-256 checksum
How to use checksums
d5e873ba42aec85fe14f463993542bbd1b3c76cab7624dda3c324a03b495230d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp37-cp37m-win32.whl

Download URL ldafork-1.2.0-cp37-cp37m-win32.whl
Size 332.4 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
b3e7c8eb05541da30730a8eff575d515ef7350fdf8236b1c16322a878f67d115
BLAKE2b-256 checksum
How to use checksums
41618f45c2db4f2b7c9e5f62522bee60a9f2ed79a285622a01a0e54c579b4553
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp37-cp37m-manylinux1_x86_64.whl

Download URL ldafork-1.2.0-cp37-cp37m-manylinux1_x86_64.whl
Size 564.4 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
14b42beba7a0c028d36d57bcb857ca06673fd0526eab666ee5d1c51dcd19e325
BLAKE2b-256 checksum
How to use checksums
e474f22931ffd8c791f680b147b3756d274cbaa70381e68c644f5b863d7169a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp37-cp37m-manylinux1_i686.whl

Download URL ldafork-1.2.0-cp37-cp37m-manylinux1_i686.whl
Size 548.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
6ab463d0ffd9797523be57abc27ea9252c23dba861753908a94626084dd4dc70
BLAKE2b-256 checksum
How to use checksums
a77610cf4c7169ba494fce62da8fe86e2346984d970ca669dcbff5bc7d2a95e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp37-cp37m-macosx_10_15_x86_64.whl

Download URL ldafork-1.2.0-cp37-cp37m-macosx_10_15_x86_64.whl
Size 345.5 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
5b8df294513f0483b1865a00c0c8c44077ef9730217a0dfd116008bb0bc12234
BLAKE2b-256 checksum
How to use checksums
e045ab714186841e99982d518b690966b8defbfef629d587c0353714ed8c126f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp37-cp37m-macosx_10_14_x86_64.whl

Download URL ldafork-1.2.0-cp37-cp37m-macosx_10_14_x86_64.whl
Size 345.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
531dbf8b604bf471a07b4303bda6a309e99985cb8390d1074d770b1fa7099051
BLAKE2b-256 checksum
How to use checksums
624808d522e78d46b41ce997e5812c510bae2f4b6a8ad2a6bb579c64656ff953
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp36-cp36m-win_amd64.whl

Download URL ldafork-1.2.0-cp36-cp36m-win_amd64.whl
Size 345.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
6b25c6a8cfb8f03a8b9cf5f6bba76118e44b3a455135473236540f85a0288705
BLAKE2b-256 checksum
How to use checksums
cf01f0afb4dd408ceb33e97903a8fb5f05d8dba682ddb862879a0023d3f7876f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp36-cp36m-win32.whl

Download URL ldafork-1.2.0-cp36-cp36m-win32.whl
Size 332.3 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
a96ee6986ac789cd930f52acd561b118c16ebf9dc58e183ed6e4a0abd55ea065
BLAKE2b-256 checksum
How to use checksums
0bea41cec5c20c4340375c4b591d2c0f93f2a5865227b28677be76e200a26659
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp36-cp36m-manylinux1_x86_64.whl

Download URL ldafork-1.2.0-cp36-cp36m-manylinux1_x86_64.whl
Size 564.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
f7960366442be2b545b030a56d96ecb8c3e2d6f6accacaf36b11d1e63c5808f9
BLAKE2b-256 checksum
How to use checksums
a152f4a08b2d71168dec25eb45abf644009d8ddaaba5adacb24daa65feebae96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp36-cp36m-manylinux1_i686.whl

Download URL ldafork-1.2.0-cp36-cp36m-manylinux1_i686.whl
Size 548.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
c334172312dccb88539403a00716a49222d1ec18ba7b951c504bf18321167fff
BLAKE2b-256 checksum
How to use checksums
b2a7e92b99d4f6f7bde712d734f7c4f44e6271ef3a4ddcda1c9bd2fe8d791cb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp36-cp36m-macosx_10_15_x86_64.whl

Download URL ldafork-1.2.0-cp36-cp36m-macosx_10_15_x86_64.whl
Size 345.4 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
8f0b0d53b18b4a13192261199ca7c73c0a6fb5a79ec74a4eeba792684987c6e5
BLAKE2b-256 checksum
How to use checksums
f22e0f7857e08a19a5911057bcafcf5f9af19bb7ed8c9e4d875e4ca8be4238da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release files / ldafork-1.2.0-cp36-cp36m-macosx_10_14_x86_64.whl

Download URL ldafork-1.2.0-cp36-cp36m-macosx_10_14_x86_64.whl
Size 345.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
8358d05e91ab0314d159bfcf75715a7a00bbce849ca9e8e654aaac26dcba5f7f
BLAKE2b-256 checksum
How to use checksums
4cada9e518557fbb5b954eaca18221d900b96d6f62c65d4a848032a7ec137b03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page