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.10 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)
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.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wordlevel-0.1.0.tar.gz | 721.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wordlevel-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.2 MB
Release files / wordlevel-0.1.0.tar.gz
| Download URL | wordlevel-0.1.0.tar.gz |
|---|---|
| Size | 721.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63f5cf55bed9913d69489432952a8973157e043ec6cedd3b37529df028f1c100
|
|
BLAKE2b-256 checksum How to use checksums |
787dba22606978bcc0377ce282826b1c091d49c1c09f1e15adc919cbd5569867
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 11, 2026.
Transparency logRelease files / wordlevel-0.1.0-py3-none-any.whl
| Download URL | wordlevel-0.1.0-py3-none-any.whl |
|---|---|
| Size | 448.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b4cb0e818ab5e463d6806f7bd6a545df5cb4a564f719f1c59d214fac05cd6489
|
|
BLAKE2b-256 checksum How to use checksums |
0b2c76542939a7b0b8b2514c1ae5a1a9231b27bc7d9bd8dc90442731ca4b4b53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 11, 2026.
Transparency log