Skip to main content

wordshift

Fast weighted-average word shift computation with bundled labMT lexicons, powered by Rust (wordshift-core).

A word shift quantifies which words drive the difference in average sentiment between two texts, and in which direction. This is a lean Rust port of Shifterator's WeightedAvgShift for the single-lexicon (sentiment) case.

Install

pip install wordshift

Usage

import wordshift

type2freq_1 = {"happy": 1, "sad": 9, "love": 2}
type2freq_2 = {"happy": 9, "sad": 1, "love": 8}

result = wordshift.weighted_avg_shift(
    type2freq_1,
    type2freq_2,
    lexicon="labMT_English",   # or "English", "French", ...
    reference_value=None,       # None -> system 1's mean score (the baseline)
    top_n=50,                   # cap returned entries (0 = all)
)

for entry in result["entries"][:5]:
    print(entry["type"], round(entry["shift_score"], 4))

result is a dict with:

  • entries — per-word {type, p_diff, s_diff, p_avg, s_ref_diff, shift_score}, sorted by absolute contribution. shift_score is normalized so absolute scores sum to 1 (the "variation" scheme).
  • component_sums — the six sign-quadrant totals for the stacked summary bars.
  • total_diff, norm, s_avg_1, s_avg_2, reference_value, normalization.

To supply your own scores instead of labMT, use weighted_avg_shift_custom:

scores = {"happy": 8.0, "sad": 2.0}
result = wordshift.weighted_avg_shift_custom(type2freq_1, type2freq_2, scores)

Words present in the texts but missing from the lexicon are excluded.

Reference value

By convention, system 1 is the baseline and system 2 is read as a shift away from it. reference_value=None (or "average") partitions words around system 1's frequency-weighted mean score. Pass a float for a fixed reference — labMT's neutral midpoint is 5.0.

Metadata

Release files for wordshift 0.1.1

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

Source distribution (sdist)

Source distribution for wordshift 0.1.1
File Size Uploaded Provenance Actions
wordshift-0.1.1.tar.gz 531.7 kB Without provenance Details for wordshift-0.1.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for wordshift 0.1.1
File Actions
wordshift-0.1.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for wordshift-0.1.1-cp39-abi3-win_amd64.whl
wordshift-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for wordshift-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
wordshift-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for wordshift-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
wordshift-0.1.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.9 abi3 macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64 Details for wordshift-0.1.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Total release size: 4.3 MB

Release files / wordshift-0.1.1.tar.gz

Download URL wordshift-0.1.1.tar.gz
Size 531.7 kB
Tags Source
SHA-256 checksum
How to use checksums
53f6a17dc2ec4c31e2c66327bf4c7a529938926b50b33ac4d5c9537d421efe94
BLAKE2b-256 checksum
How to use checksums
fe3f7b64e7948312a8e064181f0f20a8761025b173a20ea328864a24a828dd57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wordshift-0.1.1-cp39-abi3-win_amd64.whl

Download URL wordshift-0.1.1-cp39-abi3-win_amd64.whl
Size 665.7 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
bb22748233ce640a7ddca5ed2b128e7e8495bbfaf87220b37db4102c23978abc
BLAKE2b-256 checksum
How to use checksums
1a2dd001c3235109517a81c7f50efd8ae756a18ec832bdeb68f5a52f75ffd45d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wordshift-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL wordshift-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 781.0 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
65272f4cc9424db08653318ebdd182572bf3d45ba02eab8a80d64840ff7a03e4
BLAKE2b-256 checksum
How to use checksums
750bcd783ad56d3593614668d58b67af41f46ce623e07ccf14e14869a294e4e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wordshift-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL wordshift-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 779.6 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
246c8ce45568c988bd3ef102e65074f425ecf8698916feb49e40869132b41327
BLAKE2b-256 checksum
How to use checksums
2dab5d2680e7dd9e5b1383cfaf139ece9368dafa16a325a68f7c0a6650819be2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wordshift-0.1.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL wordshift-0.1.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 1.5 MB
Tags CPython 3.9 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f31a514251959165b67ffa91c6b0aedc3bd905205f0a3f384a9849d4f7a02155
BLAKE2b-256 checksum
How to use checksums
c07f7d8c37d6be5c1bead6618d70465a69059ce43aabd23ca465bad722342419
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for wordshift 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

5 release files No provenance

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