Skip to main content
wordlevel

PyPI Python versions Pytest Documentation DOI License

WordLevel is an open-source library for word-level natural language processing and text analysis. It allows you to measure how two bodies of text differ token by token, and turn that measurement into a publication-ready word shift graph: a chart that shows not only which words distinguish the texts, but also how they do so.

Install

WordLevel runs on Python 3.11 and above, and installs with any Python package manager. See the install guide for details.

pip install wordlevel

Compare texts

The code below compares the speeches of Presidents Franklin D. Roosevelt and Joe Biden by sentiment, scoring each president with a lexicon from each era.

import wordlevel as wl

speeches = wl.Dataset("presidential_speeches")

cl = wl.Catalog(speeches, corpora=["Franklin D. Roosevelt", "Joe Biden"])

cl = cl.with_comparisons(
    wl.comp("Franklin D. Roosevelt", "Joe Biden")
        .score.lexicon(
            lexicon_reference=wl.lex.SocialSent("1940"),
            lexicon_comparison=wl.lex.SocialSent("2000"),
            reference_score="center",
        )
        .normalize(by="total_diff")
        .alias("roosevelt_biden"),
)

chart = cl.plot.shift("roosevelt_biden", show_totals=True)
Word shift graph comparing the sentiment of Joe Biden's speeches against Franklin D. Roosevelt's

Biden's speeches score lower in sentiment overall. From the word shift graph, we can see that most of the gap comes from words like "nation," "families," and "americans" carrying lower sentiment in the 2000s lexicon than the 1940s one (▽), only partly offset by Biden using relatively positive words such as "together" and "well" more often (+↑).

Where to go next

  • Quick Start — install the package, make your first comparison, and build a word shift graph.
  • Cookbooks — task-by-task recipes for constructing catalogs, scoring, and plotting.
  • Concepts — the ideas behind corpora, comparisons, and word shift graphs.
  • API Reference — every public class, method, and configuration, generated from the source.

Citation

If you use WordLevel in your research, please cite the following paper:

Gallagher, R. J., Frank, M. R., Mitchell, L., Schwartz, A. J., Reagan, A. J., Danforth, C. M., & Dodds, P. S. (2021). Generalized word shift graphs: a method for visualizing and explaining pairwise comparisons between texts. EPJ Data Science, 10(1), 4.

License

WordLevel is released under the MIT License.

AI Disclosure

AI tools have been used to assist in the development of this package, including Claude Opus 4 & 5 and Gemini 3 Pro. I have opted to use AI for this project because I have found it to be a useful sounding board, learning resource, and agent for development. Despite its usefulness, I recognize that AI tools have a variety of negative social, economic, and ecological effects. I do not make excuses for these externalities, and I continue to try and navigate the tension between the usefulness of AI tools in software development and their threat as a larger social and political project.

The ideas for this package—including its architecture and design—all came from me and the lessons that I learned developing one of the original packages for word shift graphs, Shifterator. Any and all code produced by AI tools has been reviewed by me for correctness, clarity, and style. Within the bounds of the license, I take responsibility for errors in the code and documentation.

I have been developing code on this subject for nearly a decade. I hope that you are able to see the care that I have taken to make it accessible through this package.

Metadata

Release files for wordlevel 0.2.0

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

Source distribution (sdist)

Source distribution for wordlevel 0.2.0
File Size Uploaded Provenance Actions
wordlevel-0.2.0.tar.gz 701.1 kB With provenance Details for wordlevel-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wordlevel 0.2.0
File Interpreter ABI Platform Actions
wordlevel-0.2.0-py3-none-any.whl Python 3 none any Details for wordlevel-0.2.0-py3-none-any.whl

Total release size: 1.2 MB

Release files / wordlevel-0.2.0.tar.gz

Download URL wordlevel-0.2.0.tar.gz
Size 701.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9cec5df08354ce2e2cbbaa8d99733771bbcd46af27d051bc8a45218ec7435e80
BLAKE2b-256 checksum
How to use checksums
dea9f5a23ccc3a8692333aef7a04f6ee558bba1cfdf4c65a06f62e250d1b6398
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / wordlevel-0.2.0-py3-none-any.whl

Download URL wordlevel-0.2.0-py3-none-any.whl
Size 449.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5dfb4e41175031904c23638982083a6bb001f34c92644169122cc90bc14ac14
BLAKE2b-256 checksum
How to use checksums
fc4cde2721fa531bde0a2be5250c2e29cba76402ae9e55e280bc66e7b6abe0fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for wordlevel 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for wordlevel-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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