Skip to main content

Biterm Topic Model

Project description

Biterm Topic Model

CircleCI Documentation Status Downloads PyPI

Bitermplus implements Biterm topic model for short texts introduced by Xiaohui Yan, Jiafeng Guo, Yanyan Lan, and Xueqi Cheng. It uses Cython for better performance and includes two implementations of BTM: 1) bitermplus.BTM class (based on BTM by Xiaohui Yan), 2) bitermplus.btm_depr.BTM class (based on biterm package by Markus Tretzmüller). This package is also capable of computing perplexity and semantic coherence metrics.

Requirements

  • Cython
  • NumPy
  • Pandas
  • SciPy
  • Scikit-learn
  • pyLDAvis (optional)

Setup

Linux and Windows

There should be no issues with installing bitermplus under these OSes. You can install the package directly from PyPi.

pip install bitermplus

Or from this repo:

pip install git+https://github.com/maximtrp/bitermplus.git

Mac OS

First, you need to install XCode CLT and Homebrew. Then, install libomp using brew:

xcode-select --install
brew install libomp
pip3 install bitermplus

Example

import bitermplus as btm
import numpy as np
from gzip import open as gzip_open

# Importing and vectorizing text data
with gzip_open('dataset/SearchSnippets.txt.gz', 'rb') as file:
    texts = file.readlines()

# Vectorizing documents, obtaining full vocabulary and biterms
X, vocab = btm.util.get_words_freqs(texts)
docs_vec = btm.util.get_vectorized_docs(X)
biterms = btm.util.get_biterms(X)

# Initializing and running model
model = btm.BTM(X, T=8, W=vocab.size, M=20, alpha=50/8, beta=0.01)
model.fit(biterms, iterations=20)
p_zd = model.transform(docs_vec)

# Calculating metrics
perplexity = btm.metrics.perplexity(model.matrix_words_topics_, p_zd, X, 8)
coherence = btm.metrics.coherence(model.matrix_words_topics_, X, M=20)
# or
perplexity = model.perplexity_
coherence = model.coherence_

Acknowledgement

Markus Tretzmüller @markoarnauto

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bitermplus-0.5.2.tar.gz (725.9 kB view details)

Uploaded Source

File details

Details for the file bitermplus-0.5.2.tar.gz.

File metadata

  • Download URL: bitermplus-0.5.2.tar.gz
  • Upload date:
  • Size: 725.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for bitermplus-0.5.2.tar.gz
Algorithm Hash digest
SHA256 57b61414b2c3ddbd2a5ed6bd3cb129db90efd9b1a902bb18d0360b8891b5718b
MD5 f0ef03bdd5687b1020751139c8c3f890
BLAKE2b-256 b0a15f614e0b0337089836d507ebe48c7b40890e9f37c151739df2af40900b8d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page