Computate metrics for machine translation
Project description
cyzil
Description
Cyzil provides tools that enable quick and in-depth analysis of sequence generation models such as machine translation models. It contains a Cython module that provides fast computation of standard metrics. It covers edit distance (Levenstein Distance) and BLEU score proposed by Papineni et al. (2002) so far.
Requirements
- Python 3.7+
Installation
Cyzil requires Python 3.7+. Please install it by running the following code:
pip install cyzil
Command-line tool
User Guide
With cyzil, you can compute BLEU score and Edit distance on your terminal. All you have to do is to specify the path to a reference file (correct translations) and a candidate file (translation generated by a machine translation model). The reference and candidate sentences should be stored in separate lines, e.g. sentence 1\n sentence 2\n ... sentence k\n. Please see examples here. For computing score, you can tokenize sentences by white space or nltk tokenizer. By default, it tokenizes sentences by white space.
Usage
The following code shows an example for corpus-leve BLEU score. It prints out the precision, the brevity penalty and BLEU score.
> cyzil-bleu-corpus \
--reference data/ref.en \
--candidate data/can.en \
--ngram 4 \
--tokenizer nltk
[0.9041149616241455, 1.0, 0.9041149616241455]
The below is an example for corpus-level edit distance.
> cyzil-edit-distance-corpus \
--reference data/ref.en \
--candidate data/can.en \
--tokenizer nltk
[0.5, 0.04545454680919647]
Computing Score for Each Pair
Cyzil also computes the metric of each reference-candidate pair to for in-depth analysis of sequence generation models. The output can be stored in a csv file. Each row of output corresponds to each reference-candidate pair.
Here is an example for BLEU score. The first column of the output is the precision, the second is the brevity penalty and the last column is the BLEU score.
> cyzil-bleu-points \
--reference data/ref.en \
--candidate data/can.en \
--ngram 4 \
--tokenizer nltk \
--output output.csv
Edit distance can be computed as follows. The first column of the output is edit distance and the second column is normalized edit distance.
> cyzil-edit-distance-points \
--reference data/ref.en \
--candidate data/can.en \
--tokenizer nltk \
--output output.csv
For more details, please refer to help of each command, e.g. cyzil-bleu-corpus -h
.
Python API
Cyzil can be imported as a python module into your program. The following shows example of API calls. For more details, please refer to User Guide.
import cyzil
reference = ['this', 'is', 'a', 'test']
candidate = ['this', 'is', 'a', 'test']
cyzil.bleu_sentence(reference, candidate, max_ngram=4)
cyzil.bleu_corpus([reference], [candidate], max_ngram=4)
cyzil.bleu_points([reference], [candidate], max_ngram=4)
cyzil.edit_distance_sentence(reference, candidate)
cyzil.edit_distance_corpus([reference], [candidate])
cyzil.edit_distance_points([reference], [candidate])
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
File details
Details for the file cyzil-0.3.1.tar.gz
.
File metadata
- Download URL: cyzil-0.3.1.tar.gz
- Upload date:
- Size: 98.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a72ee106f9972845375c4e1300d08d7f5a8850ecfd95286c7e4ab0b7c1433a3 |
|
MD5 | 6ca967f3a8ad38bff8eb174653138eb7 |
|
BLAKE2b-256 | a8b2307b590e2ac16c17af414a62426827079bd89d9b04c96ca268b7fdc6c0ee |