Metadata-Version: 2.5
Name: rapidrouge
Version: 0.3.0
Summary: Fast pure-Python drop-in replacement for rouge-score with a bit-parallel ROUGE-L
Project-URL: Homepage, https://github.com/aisilab/rapidrouge
Project-URL: Source, https://github.com/aisilab/rapidrouge
Project-URL: Issues, https://github.com/aisilab/rapidrouge/issues
Author-email: William Brach <claudesomm@brch.sk>
License: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: bit-parallel,evaluation,lcs,rouge,rouge-l,rouge-score,summarization
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Free Threading :: 3 - Stable
Classifier: Topic :: Text Processing :: Linguistic
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: aggregate
Requires-Dist: numpy>=1.21; extra == 'aggregate'
Provides-Extra: full
Requires-Dist: nltk>=3.8; extra == 'full'
Requires-Dist: numpy>=1.21; extra == 'full'
Provides-Extra: stemmer
Requires-Dist: nltk>=3.8; extra == 'stemmer'
Description-Content-Type: text/markdown

# rapidrouge

**A fast, threads and free-threaded, pure-Python drop-in replacement for [`rouge-score`](https://pypi.org/project/rouge-score/).**
Change one import and get the same scores:

```python
from rapidrouge import rouge_scorer

 scorer = rouge_scorer.RougeScorer(["rouge1", "rouge2", "rougeL", "rougeLsum"], use_stemmer=True)
 scorer.score(target, prediction)
```

```bash
uv add rapidrouge              # or: pip install rapidrouge
uv add rapidrouge[stemmer]     # nltk, for `use_stemmer=True`
uv add rapidrouge[aggregate]   # numpy, for `BootstrapAggregator`
uv add rapidrouge[full] 
```


## How fast

![rapidrouge speedup over rouge_score vs document length, per rouge type](https://raw.githubusercontent.com/aisilab/rapidrouge/main/docs/speedup_vs_length.png)


## How we got here

![time per document pair after each change, from rouge_score to rapidrouge](https://raw.githubusercontent.com/aisilab/rapidrouge/main/docs/progress.png)

## How it works

ROUGE-L needs the length of the longest common subsequence (LCS) of two token lists. `rouge_score` fills an n × m table, one Python step per cell. Hyyrö's algorithm keeps one row of that table as a bit-vector and updates the whole row with an addition, a subtraction and two bitwise operations. A Python `int` has as many bits as you need, so the row is one integer and the arithmetic runs in C:

```python
def lcs_length(a, b):
    masks = {}                         # masks[t]: bit i is set where a[i] == t
    for i, token in enumerate(a):
        masks[token] = masks.get(token, 0) | (1 << i)
    ones = (1 << len(a)) - 1
    row = ones                         # one row of the DP table, as one big integer
    for token in b:                    # one step per token of b
        carry = row & masks.get(token, 0)
        row = ((row + carry) | (row - carry)) & ones
    return len(a) - row.bit_count()    # every zero bit is one token of the LCS
```

## References

- H. Hyyrö. [Bit-parallel LCS-length computation revisited](https://researchr.org/publication/Hyyro04%3A0).
  Proc. 15th Australasian Workshop on Combinatorial Algorithms (AWOCA), pp. 16-27, 2004. The
  algorithm rapidrouge uses.
- H. Hyyrö. [Mining bit-parallel LCS-length algorithms](https://doi.org/10.1007/978-3-319-67428-5_18).
  SPIRE 2017. Compares the bit-parallel LCS algorithms.
- C.-Y. Lin. [ROUGE: A package for automatic evaluation of summaries](https://aclanthology.org/W04-1013/).
  ACL Workshop, 2004.

## License

Apache-2.0. Portions derived from `rouge_score` (Apache-2.0); see `NOTICE`.
