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
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_scoreis 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wordshift-0.1.1.tar.gz.
File metadata
- Download URL: wordshift-0.1.1.tar.gz
- Upload date:
- Size: 531.7 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53f6a17dc2ec4c31e2c66327bf4c7a529938926b50b33ac4d5c9537d421efe94
|
|
| MD5 |
6eb46bb3de0d7254bcea811b0d71db88
|
|
| BLAKE2b-256 |
fe3f7b64e7948312a8e064181f0f20a8761025b173a20ea328864a24a828dd57
|
File details
Details for the file wordshift-0.1.1-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: wordshift-0.1.1-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 665.7 kB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb22748233ce640a7ddca5ed2b128e7e8495bbfaf87220b37db4102c23978abc
|
|
| MD5 |
c0f8ccfb9142d888db25ab9971c02e37
|
|
| BLAKE2b-256 |
1a2dd001c3235109517a81c7f50efd8ae756a18ec832bdeb68f5a52f75ffd45d
|
File details
Details for the file wordshift-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: wordshift-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 781.0 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65272f4cc9424db08653318ebdd182572bf3d45ba02eab8a80d64840ff7a03e4
|
|
| MD5 |
8a7a01838b78cbe30aa1968fe2c1bb9b
|
|
| BLAKE2b-256 |
750bcd783ad56d3593614668d58b67af41f46ce623e07ccf14e14869a294e4e0
|
File details
Details for the file wordshift-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: wordshift-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 779.6 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
246c8ce45568c988bd3ef102e65074f425ecf8698916feb49e40869132b41327
|
|
| MD5 |
fe753903fb8332d6c8bf8ddc437a89fb
|
|
| BLAKE2b-256 |
2dab5d2680e7dd9e5b1383cfaf139ece9368dafa16a325a68f7c0a6650819be2
|
File details
Details for the file wordshift-0.1.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: wordshift-0.1.1-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.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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f31a514251959165b67ffa91c6b0aedc3bd905205f0a3f384a9849d4f7a02155
|
|
| MD5 |
32936925f70fe2f53955461c3532d7a5
|
|
| BLAKE2b-256 |
c07f7d8c37d6be5c1bead6618d70465a69059ce43aabd23ca465bad722342419
|