Skip to main content

This is Python port of original algorithm by Aaron Li-Feng Han

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 = 'Rising urban populations around the world have ushered in the concept of Smart Cities, in which digital innovations are used to address long-standing urban challenges.'
hypothesis = 'Rising urban populations around the world introduced the concept of Smart Cities, where long-standing urban challenges are addressed with digital innovations.'
hLepor_value = single_hlepor_score(reference, hypothesis)
round(hLepor_value, 4)

The result is 0.7550.

  1. To calculate hLepor on a set of sentences they need to be passed to hLepor as a list of strings:
reference = ['Rising urban populations around the world have ushered in the concept of Smart Cities, in which digital innovations are used to address long-standing urban challenges.', 'The related construction boom has put increasing demands on builders to erect structures and systems beautifully and efficiently.']
hypothesis = ['Rising urban populations around the world introduced the concept of Smart Cities, where long-standing urban challenges are addressed with digital innovations.', 'The related construction boom has put increasing demands on teams to build structures and systems beautifully and efficiently.']
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.8395.

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.4.tar.gz (10.5 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.4-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hLepor-0.0.4.tar.gz
  • Upload date:
  • Size: 10.5 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.4.tar.gz
Algorithm Hash digest
SHA256 b63f20c7618f915947a67eb95268da1de3cf88d4300b02be6f948d4efdb6d3de
MD5 f899c2d0e459308ff983e5c704bb454d
BLAKE2b-256 bbc886a57259311eb927564ebab39725c8b069a6ce6d05f4c84f61047582c800

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hLepor-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 11.3 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 820d50502ff56882186019f4b5b3577bb4043bb262a422612dda176d3c2c7a16
MD5 0c18859dd9f44d1df69f40ac955cb23f
BLAKE2b-256 f2b3439f1ce0a2e2ac8d17969bf76023125da9803d80a94b738a8d0e04874486

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