Metadata-Version: 2.5
Name: humetrix
Version: 0.4.0
Summary: Automatic metrics for evaluation of humorous content
Project-URL: Repository, https://github.com/NLP-CISUC/Humetrix
Project-URL: Issues, https://github.com/NLP-CISUC/Humetrix/issues
Project-URL: Resources, https://huggingface.co/NLP-CISUC/humetrix-resources
Project-URL: Documentation, https://nlp-cisuc.github.io/Humetrix/
Author-email: Marcio Lima Inácio <mlinacio@dei.uc.pt>
License: MIT
License-File: LICENSE
Keywords: computational humor,evaluation,humor,natural language generation,natural language processing,nlg,nlp
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.12
Requires-Dist: accelerate>=1.11.0
Requires-Dist: gensim>=4.3.3
Requires-Dist: huggingface-hub>=1.14.0
Requires-Dist: numpy>=1.26.4
Requires-Dist: polars[rt64]>=1.34.0
Requires-Dist: safetensors>=0.7.0
Requires-Dist: scipy>=1.17.1
Requires-Dist: spacy-curated-transformers<1.0.0,>=0.2.2
Requires-Dist: spacy>=3.8.0
Requires-Dist: torch>=2.6.0
Requires-Dist: transformers>=4.49.0
Description-Content-Type: text/markdown

# Humetrix

[![License: MIT](https://img.shields.io/badge/License-MIT-orange.svg)](https://opensource.org/license/mit)
[![PyPI](https://img.shields.io/pypi/v/humetrix)](https://pypi.org/project/humetrix/)

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)](https://aclanthology.org/2023.findings-eacl.152) |
| Surprise Ratio | `surprise_ratio` | [He et al. (2019)](http://aclweb.org/anthology/N19-1172) |
| Ambiguity / Distinctiveness | `kao_ambiguity`, `kao_distinctiveness` | [Kao et al. (2016)](https://onlinelibrary.wiley.com/doi/10.1111/cogs.12269) |

## 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](docs/skipgram.md))

## Installation

Humetrix requires Python 3.12 or above:

```bash
pip install humetrix
```

PyTorch is installed from PyPI by default. For a CPU-only install, install PyTorch first following the [official instructions](https://pytorch.org/get-started/locally/).

## Usage

Here is a simple example of how to use Humetrix:

```python
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')
sr_score = analyzer.surprise_ratio(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.

Full API Documentation is available at [https://nlp-cisuc.github.io/Humetrix/](https://nlp-cisuc.github.io/Humetrix/).

## 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](https://huggingface.co/NLP-CISUC/humetrix-resources).

## Development

To reproduce the experiments of the paper, clone the repository and use [uv](https://docs.astral.sh/uv/):

```bash
uv sync
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

The resources have their own licenses, listed in the [resources repository](https://huggingface.co/NLP-CISUC/humetrix-resources).

## How to cite

```bibtex
To be announced
```
