Skip to main content

Fast weighted-average word shift computation with bundled labMT lexicons, powered by Rust

Project description

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        # once published
# or, from source:
maturin build --release -m crates/wordshift-py/Cargo.toml && pip install target/wheels/wordshift-*.whl

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.

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

wordshift-0.1.0.tar.gz (530.3 kB view details)

Uploaded Source

Built Distributions

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

wordshift-0.1.0-cp39-abi3-win_amd64.whl (661.6 kB view details)

Uploaded CPython 3.9+Windows x86-64

wordshift-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (776.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

wordshift-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (774.8 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

wordshift-0.1.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (1.5 MB view details)

Uploaded CPython 3.9+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file wordshift-0.1.0.tar.gz.

File metadata

  • Download URL: wordshift-0.1.0.tar.gz
  • Upload date:
  • Size: 530.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","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}

File hashes

Hashes for wordshift-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0a14f3dd063ee648ca86f8552da5411831d36bf64d57aedc9018fad35ff1484a
MD5 f6c3de019cdc38c256d2539b80e7b792
BLAKE2b-256 650f15a22a7257e82435e084edbaaeb84890cd5fa714d2625ff3a54102b24e42

See more details on using hashes here.

File details

Details for the file wordshift-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: wordshift-0.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 661.6 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","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}

File hashes

Hashes for wordshift-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 40099b8b8b70905ab46cee422072e6df1edc30b0a28eb72bf96571187e60cd90
MD5 b04943b37181ff80721993bbec952ae1
BLAKE2b-256 e1f44898c6727072362ce00caa43a2202ac3003791c9550a3ad037fe69bcb106

See more details on using hashes here.

File details

Details for the file wordshift-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: wordshift-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 776.2 kB
  • Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","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}

File hashes

Hashes for wordshift-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c0def39953c3ff07daf547f94eb476bcf6eb349a1ddac3171d743f850e63d7c9
MD5 c84b05b0dd80862911262b948a99646f
BLAKE2b-256 b827fdc802e010fd9f2529307fb4f526d5ce47aa7ae274d71b8cc4060ab7150c

See more details on using hashes here.

File details

Details for the file wordshift-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: wordshift-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 774.8 kB
  • Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","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}

File hashes

Hashes for wordshift-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8295924b1e3c86b892bd2d64b55ba1f5589f6019b99d6bfb6f8206f55e77d7b1
MD5 82bd87d09605a9a83a122bb9f16cbc87
BLAKE2b-256 a9b4fc2c2090c319e35362fc00e5ec453d79a8aa2eebf6fee820e2ade64a8cd5

See more details on using hashes here.

File details

Details for the file wordshift-0.1.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

  • Download URL: wordshift-0.1.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.9+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","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}

File hashes

Hashes for wordshift-0.1.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 ff5af7de19ecfb034d4204c1229c6abf795b8cc49691bc0908b1c0682349f54f
MD5 f76d96f6a1c924f76f3189fa31f201f3
BLAKE2b-256 48d8ea7c4872559362ceb5181c0aec996507e80f0f1c87b16e9c4559d4af964c

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