Skip to main content

A fast bleu score calculator

Project description

bleuscore

Crates.io PyPI - Version npm version docs.rs codecov MIT licensed CodSpeed Badge

bleuscore is a fast BLEU score calculator written in rust. You can check try the web demo here for a quick experience.

Installation

The python package has been published to pypi, so we can install it directly with many ways:

  • uv

    uv add bleuscore
    
  • pip

    pip install bleuscore
    

Quick Start

The usage is exactly same with huggingface evaluate:

- import evaluate
+ import bleuscore

predictions = ["hello there general kenobi", "foo bar foobar"]
references = [
    ["hello there general kenobi", "hello there !"],
    ["foo bar foobar"]
]

- bleu = evaluate.load("bleu")
- results = bleu.compute(predictions=predictions, references=references)
+ results = bleuscore.compute(predictions=predictions, references=references)

print(results)
# {'bleu': 1.0, 'precisions': [1.0, 1.0, 1.0, 1.0], 'brevity_penalty': 1.0, 
# 'length_ratio': 1.1666666666666667, 'translation_length': 7, 'reference_length': 6}

Benchmark

TLDR: We got more than 10x speedup when the corpus size beyond 100K

Benchmark

We use the demo data shown in quick start to do this simple benchmark. You can check the benchmark/simple for the benchmark source code.

  • rs_bleuscore: bleuscore python library
  • local_hf_bleu: huggingface evaluate bleu algorithm in local
  • sacre_bleu: sacrebleu
    • Note that we got different result with sacrebleu in the simple demo data and all the rests have same result
  • hf_evaluate: huggingface evaluate bleu algorithm with evaluate package

The N is used to enlarge the predictions/references size by simply duplication the demo data as shown before. We can see that as N increase, the bleuscore gets better performance. You can navigate benchmark for more benchmark details.

N=100

hyperfine --warmup 5 --runs 10   \
  "python simple/rs_bleuscore.py 100" \
  "python simple/local_hf_bleu.py 100" \
  "python simple/sacre_bleu.py 100"   \
  "python simple/hf_evaluate.py 100"

Benchmark 1: python simple/rs_bleuscore.py 100
  Time (mean ± σ):      19.0 ms ±   2.6 ms    [User: 17.8 ms, System: 5.3 ms]
  Range (min  max):    14.8 ms   23.2 ms    10 runs

Benchmark 2: python simple/local_hf_bleu.py 100
  Time (mean ± σ):      21.5 ms ±   2.2 ms    [User: 19.0 ms, System: 2.5 ms]
  Range (min  max):    16.8 ms   24.1 ms    10 runs

Benchmark 3: python simple/sacre_bleu.py 100
  Time (mean ± σ):      45.9 ms ±   2.2 ms    [User: 38.7 ms, System: 7.1 ms]
  Range (min  max):    43.5 ms   50.9 ms    10 runs

Benchmark 4: python simple/hf_evaluate.py 100
  Time (mean ± σ):      4.504 s ±  0.429 s    [User: 0.762 s, System: 0.823 s]
  Range (min  max):    4.163 s   5.446 s    10 runs

Summary
  python simple/rs_bleuscore.py 100 ran
    1.13 ± 0.20 times faster than python simple/local_hf_bleu.py 100
    2.42 ± 0.35 times faster than python simple/sacre_bleu.py 100
  237.68 ± 39.88 times faster than python simple/hf_evaluate.py 100

N = 1K ~ 1M

Command Mean [ms] Min [ms] Max [ms] Relative
python simple/rs_bleuscore.py 1000 20.3 ± 1.3 18.2 21.4 1.00
python simple/local_hf_bleu.py 1000 45.8 ± 1.2 44.2 47.5 2.26 ± 0.16
python simple/rs_bleuscore.py 10000 37.8 ± 1.5 35.9 39.5 1.87 ± 0.14
python simple/local_hf_bleu.py 10000 295.0 ± 5.9 288.6 304.2 14.55 ± 0.98
python simple/rs_bleuscore.py 100000 219.6 ± 3.3 215.3 224.0 10.83 ± 0.72
python simple/local_hf_bleu.py 100000 2781.4 ± 42.2 2723.1 2833.0 137.13 ± 9.10
python simple/rs_bleuscore.py 1000000 2048.8 ± 31.4 2013.2 2090.3 101.01 ± 6.71
python simple/local_hf_bleu.py 1000000 28285.3 ± 100.9 28182.1 28396.1 1394.51 ± 90.21

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

bleuscore-0.1.6.tar.gz (26.1 kB view details)

Uploaded Source

Built Distributions

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

bleuscore-0.1.6-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

bleuscore-0.1.6-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (1.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ i686

bleuscore-0.1.6-cp38-abi3-win_amd64.whl (760.1 kB view details)

Uploaded CPython 3.8+Windows x86-64

bleuscore-0.1.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

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

bleuscore-0.1.6-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (1.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

bleuscore-0.1.6-cp38-abi3-macosx_11_0_arm64.whl (858.7 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

bleuscore-0.1.6-cp38-abi3-macosx_10_12_x86_64.whl (906.1 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file bleuscore-0.1.6.tar.gz.

File metadata

  • Download URL: bleuscore-0.1.6.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for bleuscore-0.1.6.tar.gz
Algorithm Hash digest
SHA256 e1cb94997961d5382cb3b90df898a67ac7b372ef4a8037f9018bd4c58dbb5fb0
MD5 ea1984ebc6e471da642163200938714f
BLAKE2b-256 4eba0aa16e38253357d47fc604c0b1afa2c8f44374f62b19998a644abff068ba

See more details on using hashes here.

File details

Details for the file bleuscore-0.1.6-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bleuscore-0.1.6-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 91a6c559e119c4dd2ab05a06bead590daa19d6e52f58b16007e42a14db420878
MD5 c762b4b9c44ed27458081982d932d09f
BLAKE2b-256 5bdc79b262bf9c8ffa2b5af28ba6a031e72d30d7cd53f2ccb800b8e8fde556f9

See more details on using hashes here.

File details

Details for the file bleuscore-0.1.6-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for bleuscore-0.1.6-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 63c6c6826ef0885175c41d3342cc52c47e5189a43afb6b60d4ec37db3db2d8eb
MD5 2cd0e71104a065350e4ef98158d3acb4
BLAKE2b-256 8d822be4b3c47fdd55d3ee31db5686e40cd2420150ef4527653f375dbe937329

See more details on using hashes here.

File details

Details for the file bleuscore-0.1.6-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: bleuscore-0.1.6-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 760.1 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for bleuscore-0.1.6-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c99ec5859d3f6064af7a6c49ee2dc4aa0b3630d5ba3a2a526735eea54d77a3fe
MD5 c3e8b4dd7bfbd2f3be77614538715b87
BLAKE2b-256 48779011fead5cf73bbc9cbd58ddbf2ac3132daff8a9f5197f4f2c34fada9af9

See more details on using hashes here.

File details

Details for the file bleuscore-0.1.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bleuscore-0.1.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cedbdeca792d8c8c9ebe545d07b215e473964adaa8be1fb542275058456147cf
MD5 24ac785c3324ec1c3b390f0a55de32f4
BLAKE2b-256 1df361904420526bcf4939c7943875c9a65739d6227c60851e8d16fd74c02607

See more details on using hashes here.

File details

Details for the file bleuscore-0.1.6-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for bleuscore-0.1.6-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 a1cf5e680a774b61937c1fca7065e9e0fa6954de5224d7b7df895c84970a892b
MD5 34c5387fcb54ee253719371c7a7cb87f
BLAKE2b-256 0727a3e5fcc631d0ce66424dde3a845bfc8f118123f63a51d65e3a350c971858

See more details on using hashes here.

File details

Details for the file bleuscore-0.1.6-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bleuscore-0.1.6-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 25482cdfbc43ada27f48c7bf886fc2318f7b0178db8c3c0de3e58489f558bc62
MD5 9995a59bf05547b624253cbfaba9bad6
BLAKE2b-256 40b98c95228aca1653f504bfa585136c6f3ad9c2f34273ca9d83ed1af93350d6

See more details on using hashes here.

File details

Details for the file bleuscore-0.1.6-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for bleuscore-0.1.6-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c1b91d5b603a9ea9e122c2b131cf8e48d23398b949e5ee6e9e2e2b5efb704b23
MD5 e3874175d909f3a8c7cbe4a437977730
BLAKE2b-256 ee176b991461d1038a84fb41a0142882c652cdbe8797a5a0453560e5c219a0ed

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