Skip to main content

Hyperreal is a library and tool for intepretive topic modelling.

Project description

Hyperreal

Hyperreal is a Python tool for interactive qualitative analysis of large collections of documents.

Requirements

Hyperreal requires the installation of the Python programming language.

Installation

Hyperreal can be installed using Pip from the command line ( Windows, Mac) by running the following commands:

python -m pip install hyperreal

Usage

Hyperreal can be used in three different ways to flexibly support different use cases:

  • as a command line application
  • as a Python library
  • via the built in web application

All of hyperreal's functionality is available from the Python library, but you will need to write Python code to use it directly. The command line interface allows for quick and repeatable experimentation and automation for standard data types - for example if you often work with Twitter data the command line will allow you to rapidly work with many different Twitter data collections. The web application is currently focused solely on creating and interactive editing of models.

Command Line

The following script gives a basic example of using the command line interface for hyperreal. This will work for cases where you have a plain text file (here called corpus.txt), with each document in the collection on its own line.

If you haven't worked with the command line before, you might find the following resources useful:

# Create a corpus database from the plaintext file
hyperreal plaintext-corpus create corpus.txt corpus.db

# Create an index from the corpus
hyperreal plaintext-corpus index corpus.db corpus_index.db

# Create a model from that index, in this case with 128 clusters and
# only include features present in 10 or more documents.
hyperreal model corpus_index.db --min-docs 10 --clusters 128

# Use the web interface to serve the results of that modelling
# After running this command point your web browser to http://localhost:8080
hyperreal plaintext-corpus serve corpus.db corpus_index.db

Library

This example script performs the same steps as the command line example.

from hyperreal import corpus, index

# create and populate the corpus with some documents
c = corpus.PlainTextSqliteCorpus('corpus.db')

with open('corpus.txt', 'r') as f:
  # This will drop any line that has no text (such as a paragraph break)
  docs = (line for line in f if line.strip())
  c.replace_docs(docs)


# Index that corpus - note that we need to pass the corpus object for
# initialisation.
i = index.Index('corpus_index.db', corpus=c)
# This only needs to be done once, unless the corpus changes.
i.index()

# Create a model on this index, with 128 clusters and only including features
# that match at least 10 documents.
i.initialise_clusters(n_clusters=128, min_docs=10)
# Refine the model for 10 iterations. Note that you can continue to refine
# the model without initialising the clusters.
i.refine_clusters(iterations=10)

# Inspect the output of the model using the index instance (currently quite
# limited). This will print the top 10 most frequent features in each
# cluster.
for cluster_id in i.cluster_ids:
    cluster_features = i.cluster_features(cluster_id)
    for feature in cluster_features[:10]:
        print(feature)

# Perform a boolean query on the corpus, looking for documents that contain
# both apples AND oranges in the text field.
q = i[('text', 'apples')] & i[('text', 'oranges')]
# Lookup all of the documents in the corpus that match this query.
docs = i.get_docs(q)

# 'Pivot' the features in the index with respect to all cluster in the model.
#  This will show the top 10 features in each cluster that are similar to the
#  query.
i.pivot_clusters_by_query(query, top_k=10)

# This will show the top 10 features for a selected set of cluster_ids.
i.pivot_clusters_by_query(query, cluster_ids=[3,5,7], top_k=10)

Development

Installation

To install the development version:

  1. Clone the repository using git.

  2. From the cloned repository, use pip for an editable install:

    pip install -e .

Running Tests

The full test suite and other checks are orchestrated via tox:

python -m pip install -e .[test]

# To run just the testsuite
pytest

# To run everything, including code formatting via black and check coverage
tox

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

hyperreal-0.3.0.tar.gz (49.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hyperreal-0.3.0-py3-none-any.whl (49.4 kB view details)

Uploaded Python 3

File details

Details for the file hyperreal-0.3.0.tar.gz.

File metadata

  • Download URL: hyperreal-0.3.0.tar.gz
  • Upload date:
  • Size: 49.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for hyperreal-0.3.0.tar.gz
Algorithm Hash digest
SHA256 01dc3ae4cdbfc266b527afc155891a22d0335d50011f41ce9e5684e50c1761d6
MD5 6f90b41a94e51f6b39a744ef40ce22e4
BLAKE2b-256 781ae36cc55f7c23e0f0f8d23bd198f069c08cc3482d56e492b3e3d0ebd21cfd

See more details on using hashes here.

File details

Details for the file hyperreal-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: hyperreal-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 49.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for hyperreal-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c0ff85e0fec94e1febd58c49b55cd73fc60242fe91b2f9830ac5bd2f7569376
MD5 e4670b28b24a10385ab1de405c81342c
BLAKE2b-256 5f3cc1ab78cd25d1c3d59620d945b858c6d29c732884680c86d2a2fe899a9d44

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