Skip to main content

This is Python port of original algorithm by Hang Lifeng

Project description

Library to calculate hLEPOR score (harmonic mean of enhanced Length Penalty, Precision, n-gram Position difference Penalty and Recall) has been created as port from Perl on materials of the following atricle by Aaron Li-Feng Han, Derek F. Wong, Lidia S. Chao, Liangye He Yi Lu, Junwen Xing, and Xiaodong Zeng. 2013. "Language-independent Model for Machine Translation Evaluation with Reinforced Factors". In Proceedings of the XIV Machine Translation Summit.

All hLepor score calculation functions take mandatory and optional parameters for input; mandatory parameters are: reference (ideal translation), hypothesis - new translation which has to be compared with reference.

Optional parameters are:

  • preprocess is a function to preprocess strings, default is str.lower().

  • separate_punctuation allows different tokenization options: by default standard word_tokenize() function from nltk.tokenize is used, for this option you can specify the language (default is English), if separate_punctuation = False, sentence is tikenized by spaces.

Other optional parameters control hLepor algorithm:

  • alpha and beta -- recall and precision weights, respectively, to calculate weighted Harmonic mean of precision and recall;
  • n -- number of words in vicinity of current word in N-gram word alignment algorithm;
  • weight_elp, weight_pos, weight_pr -- weigths for enhanced length penalty, N-gram Position Difference Penalty and weighted Harmonic mean of precision and recall for hLepor calculation.

Main functions:

  1. To calculate hLepor on one pair of sentences you need to pass these strings to single_hlepor_score function:
reference = 'It is a guide to action that ensures that the military will forever heed Party commands'
hypothesis = 'It is a guide to action which ensures that the military always obeys the commands of the party'
hLepor_value = single_hlepor_score(reference, hypothesis)
round(hLepor_value, 4)

The result if 0.7842.

  1. To calculate hLepor on a set of sentences they need to be passed to hLepor as a list of strings:
reference = ['It is a guide to action that ensures that the military will forever heed Party commands',
             'It is the practical guide for the army always to heed the directions of the party']
hypothesis = ['It is a guide to action which ensures that the military always obeys the commands of the party',
              'It is to insure the troops forever hearing the activity guidebook that party direct']
hLepor_value = hlepor_score(reference, hypothesis)
round(hLepor_value, 4)

This code will calculate hLepor on each pair of sentences and mean value will be calculated, the result should be 0.6214.

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

hLepor-0.0.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

hLepor-0.0.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file hLepor-0.0.1.tar.gz.

File metadata

  • Download URL: hLepor-0.0.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.3

File hashes

Hashes for hLepor-0.0.1.tar.gz
Algorithm Hash digest
SHA256 891154e2418a122d939c4f0a848696a5388f922742e69cd19acc1753a30fad2f
MD5 8d5533560bb0f705560cfd21fce4825b
BLAKE2b-256 50d468d463e68e9c9921a77a7d493dbffc26354317d7839290628528d994ac2f

See more details on using hashes here.

File details

Details for the file hLepor-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: hLepor-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.3

File hashes

Hashes for hLepor-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 248c4c83ac27399da46fbd5e0d640df16f900e37271808cf20f673c270442492
MD5 5f81bf79458cd7c89b44c58e1a6bbc0f
BLAKE2b-256 55ed855fafb076ae44a7a5508f7ebbfc827b680bd0fdc30de73fc9acba0c93d5

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