CodeBLEU
Unofficial CodeBLEU implementation with Linux and MacOS supports available with PyPI and HF HUB.
Based on original CodeXGLUE/CodeBLEU code -- refactored, build for macos, tested and fixed multiple crutches to make it more usable.
Metric Description
An ideal evaluation metric should consider the grammatical correctness and the logic correctness. We propose weighted n-gram match and syntactic AST match to measure grammatical correctness, and introduce semantic data-flow match to calculate logic correctness.
(from CodeXGLUE repo)
In a nutshell, CodeBLEU is a weighted combination of n-gram match (BLEU), weighted n-gram match (BLEU-weighted), AST match and data-flow match scores.
The metric has shown higher correlation with human evaluation than BLEU and accuracy metrics.
Usage
from codebleu import calc_codebleu
prediction = "def add ( a , b ) :\n return a + b"
reference = "def sum ( first , second ) :\n return second + first"
result = calc_codebleu([reference], [prediction], lang="python", weights=(0.25, 0.25, 0.25, 0.25), tokenizer=None)
print(result)
# {
# 'codebleu': 0.5537,
# 'ngram_match_score': 0.1041,
# 'weighted_ngram_match_score': 0.1109,
# 'syntax_match_score': 1.0,
# 'dataflow_match_score': 1.0
# }
where calc_codebleu takes the following arguments:
refarences(list[str]orlist[list[str]]): reference codepredictions(list[str]) predicted codelang(str): code language, seecodebleu.AVAILABLE_LANGSfor available languages (python, c_sharp, java at the moment)weights(tuple[float,float,float,float]): weights of thengram_match,weighted_ngram_match,syntax_match, anddataflow_matchrespectively, defaults to(0.25, 0.25, 0.25, 0.25)tokenizer(callable): to split code string to tokens, defaults tos.split()
and outputs the dict[str, float] with following fields:
codebleu: the finalCodeBLEUscorengram_match_score:ngram_matchscore (BLEU)weighted_ngram_match_score:weighted_ngram_matchscore (BLEU-weighted)syntax_match_score:syntax_matchscore (AST match)dataflow_match_score:dataflow_matchscore
Alternatively, you can use k4black/codebleu from HuggingFace Spaces:
import evaluate
metric = evaluate.load("dvitel/codebleu")
result = metric.compute([reference], [prediction], lang="python", weights=(0.25, 0.25, 0.25, 0.25))
Feel free to check the HF Space with online example: k4black/codebleu
Installation
Requires Python 3.8+
The metrics can be installed with pip and used as indicated above:
pip install codebleu
alternatively the metric is available as k4black/codebleu in evaluate (lib installation required):
import evaluate
metric = evaluate.load("dvitel/codebleu")
Citation
Official CodeBLEU paper can be cited as follows:
@misc{ren2020codebleu,
title={CodeBLEU: a Method for Automatic Evaluation of Code Synthesis},
author={Shuo Ren and Daya Guo and Shuai Lu and Long Zhou and Shujie Liu and Duyu Tang and Neel Sundaresan and Ming Zhou and Ambrosio Blanco and Shuai Ma},
year={2020},
eprint={2009.10297},
archivePrefix={arXiv},
primaryClass={cs.SE}
}
Metadata
Release files for codebleu 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| codebleu-0.1.5.tar.gz | 7.9 MB | Details |
Built distributions (wheels)
Total release size: 20.4 MB
Release files / codebleu-0.1.5.tar.gz
| Download URL | codebleu-0.1.5.tar.gz |
|---|---|
| Size | 7.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94815cd5804e83aedbd67d34632fe7d8355d0b8f66eca7f0cebb3a8eb6e41f0c
|
|
BLAKE2b-256 checksum How to use checksums |
d5fee451375234b317887e442535d2b501cff4fd72b1c935136ca157d9b542fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | codebleu-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
dfc5b50f6f3149780a32b9bfcdf8e0e347f94eea776c442103bbea53948ffe63
|
|
BLAKE2b-256 checksum How to use checksums |
c032affa806fd2337bb301a4ff05a93d869b47c048a56bbbfbf48201e4037c0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | codebleu-0.1.5-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
0f6834e912ae9cce5a4d2a3a268e1354a74ff720a2f648355681097aa812fcaf
|
|
BLAKE2b-256 checksum How to use checksums |
bf5619d6a2c9d3554d4e29656357d5b5b51a2c6b8ae365894d8613e93c7b71ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp311-cp311-macosx_10_9_x86_64.whl
| Download URL | codebleu-0.1.5-cp311-cp311-macosx_10_9_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.11 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
f63ba6ea07971936f3f5ab26c8de35b4e00b6baa00c00fe4bf7cd67937d860b2
|
|
BLAKE2b-256 checksum How to use checksums |
116c9f1350caf9e0cc30ac8be7166916082ece533e9dcbbc42338ed4feba8708
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | codebleu-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e919f62e9287777b3123c8563dc025bfa4935423cc2c1e992c77627fa57f7c6b
|
|
BLAKE2b-256 checksum How to use checksums |
82203bc13020fffb33e6920c0a29cb8b9882b3e18f36e81f77b38cd585661f58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | codebleu-0.1.5-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
283ad2a30e613019250af6a26be38d133247c6cae6abee730ff7d5de7786eb36
|
|
BLAKE2b-256 checksum How to use checksums |
06915276d09ae09909ea1b3cdc4a20b6681dc5edb41ed02e37721e318699644f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp310-cp310-macosx_10_9_x86_64.whl
| Download URL | codebleu-0.1.5-cp310-cp310-macosx_10_9_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
16cd91e57e92d9ac336f7ed3e37f960aa8790c5d936600d76912a83bf90ec338
|
|
BLAKE2b-256 checksum How to use checksums |
9dacfcb9e6338b6945704264dc337023edb11eecb8db4e0431dc67dae93bcfe4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | codebleu-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e57e0ddfcccd34fd48490f188991329adc9fedc9226941cabe851854e12eb34f
|
|
BLAKE2b-256 checksum How to use checksums |
aa706c52752d60d13706ccfd29292d2e0335f4283ea860fe52b0ea4f67ab1243
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | codebleu-0.1.5-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
4d35f8aec7a67e261f8ddd4f7e866a4a20e85664bcfdb82828ba0e749d00ae8b
|
|
BLAKE2b-256 checksum How to use checksums |
6f5c3689d0335c9b3f62aa9e4666ad50279c8ffe2607a32f3747957e3bae1e54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl
| Download URL | codebleu-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.9 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
1299042429422f723ab40ef85301c618a37d215f675607528d7b70ba22210248
|
|
BLAKE2b-256 checksum How to use checksums |
5b7e18bd069c6c7dc4df85984edfc0cccb1f622124f3b6f46d81f0444bc13f8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | codebleu-0.1.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e0394f661eaf74432f07132ddd940175fe5487f17d4151048c0d90903ea4746f
|
|
BLAKE2b-256 checksum How to use checksums |
63eb2073b2a785d0411f20d886b917c0a43d0db95be7ffdf1c1dcd31266c34c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | codebleu-0.1.5-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
568a53a45f62a5754625c27b3cb69c21368066ff7e6e2db0694576bb36b2a19a
|
|
BLAKE2b-256 checksum How to use checksums |
df5c47957904c6519d90efc35ebe6c1f8d46c2436b09a104801a37c23e9996c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / codebleu-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl
| Download URL | codebleu-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.8 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
8d8f40b2d17a621d66bfe3c259cc94979b26afc6276f3bb8b2a27da97af5be7f
|
|
BLAKE2b-256 checksum How to use checksums |
383e51edcef5e54e25142e85a8347afb487237413ea7084d83253d6aeeb7e806
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|