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 isstr.lower()
. -
separate_punctuation
allows different tokenization options: by default standardword_tokenize()
function fromnltk.tokenize
is used, for this option you can specify the language (default is English), ifseparate_punctuation = False
, sentence is tikenized by spaces.
Other optional parameters control hLepor algorithm:
alpha
andbeta
-- 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:
- 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.
- 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.