Skip to main content

Humetrix

License: MIT

Automatic metrics for humorous texts. Currently supporting English, Spanish, French, Portuguese and Mandarin Chinese.

Metric Method Reference
Quantum Uncertainty / Incongruity quantum_uncertainty, quantum_incongruity Liu and Hou (2023)
Surprise Ratio local_global_surprise He et al. (2019)
Ambiguity / Distinctiveness kao_ambiguity, kao_distinctiveness Kao et al. (2016)

Description

Humetrix is a Python library that provides a collection of automatic metrics for evaluating humor in text. Quantum Entropy metrics apply to any text with a setup and a punchline, while Surprise Ratio and Ambiguity/Distinctiveness are designed for puns and need the pun and alternative words.

All resources are downloaded automatically on first use, but the repository also contains the scripts used to train our models (see docs/skipgram.md)

Installation

Humetrix requires Python 3.12 or above:

pip install humetrix

PyTorch is installed from PyPI by default. For a CPU-only install, install PyTorch first following the official instructions.

Usage

Here is a simple example of how to use Humetrix:

from humetrix import HumorAnalyzer

# Needed resources are downloaded automatically on first use
analyzer = HumorAnalyzer(language='en')
sent = 'Not all math puns are bad. Just sum of them.'
sign = 'sum'
alt_sign = 'some'

qi_score = analyzer.quantum_incongruity(sent)
qi_xlm_score = analyzer.quantum_incongruity(sent, backend='transformer')
qu_score = analyzer.quantum_uncertainty(sent)
qu_xlm_score = analyzer.quantum_uncertainty(sent, backend='transformer')
lgs_score = analyzer.local_global_surprise(sent, sign, alt_sign)
kao_amb_score = analyzer.kao_ambiguity(sent, sign, alt_sign)
kao_dist_score = analyzer.kao_distinctiveness(sent, sign, alt_sign)

Metrics return None when they cannot be computed.

Use HumorAnalyzer(<language>, device="cpu") too choose where neural models run, and transformer_model_name to choose the model for the transformer backend.

Resources

Embeddings, skip-gram models, n-gram tables, spaCy and transformer models are downloaded on first use and cached locally, so the first call of each metric may take a while. They are hosted at NLP-CISUC/humetrix-resources.

Development

To reproduce the experiments of the paper, clone the repository and use uv:

uv sync

License

This project is licensed under the MIT License - see the LICENSE file for details.

The resources have their own licenses, listed in the resources repository.

How to cite

To be announced

Metadata

Release files for humetrix 0.3.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 humetrix 0.3.0
File Size Uploaded Provenance Actions
humetrix-0.3.0.tar.gz 16.1 MB Without provenance Details for humetrix-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 16.1 MB

Release files / humetrix-0.3.0.tar.gz

Download URL humetrix-0.3.0.tar.gz
Size 16.1 MB
Tags Source
SHA-256 checksum
How to use checksums
9884c5648ad91aecffa6b35121f5878159017e1cd0fa564391520cf0d65b9e38
BLAKE2b-256 checksum
How to use checksums
8e3818d1a9c46a381c0199a6ffd82b7b3954de669f00b3bbdb5f2fae083b7430
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / humetrix-0.3.0-py3-none-any.whl

Download URL humetrix-0.3.0-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46f32789b22751f9369185535ad0c13f68f475423ee68c71706430dd67d4432b
BLAKE2b-256 checksum
How to use checksums
fe4efa541021471c3ef49039439958d3f0c0b7ae9368cbe54963a903e06186e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for humetrix 0.3.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.

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.3.0 This release

2 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