src/python/evaluation_metrics.py
def bleu(self,candidate, references, weights):
	    """Calculate BLEU score (Bilingual Evaluation Understudy)

	    :param candidate: a candidate sentence
	    :type candidate: list(str)
	    :param references: reference sentences
	    :type references: list(list(str))
	    :param weights: weights for unigrams, bigrams, trigrams and so on
	    :type weights: list(float)

	    >>> weights = [0.25, 0.25, 0.25, 0.25]
	    >>> candidate1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'which',
	    ...               'ensures', 'that', 'the', 'military', 'always',
	    ...               'obeys', 'the', 'commands', 'of', 'the', 'party']

	    >>> candidate2 = ['It', 'is', 'to', 'insure', 'the', 'troops',
	    ...               'forever', 'hearing', 'the', 'activity', 'guidebook',
	    ...               'that', 'party', 'direct']

	    >>> reference1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'that',
	    ...               'ensures', 'that', 'the', 'military', 'will', 'forever',
	    ...               'heed', 'Party', 'commands']

	    >>> reference2 = ['It', 'is', 'the', 'guiding', 'principle', 'which',
	    ...               'guarantees', 'the', 'military', 'forces', 'always',
	    ...               'being', 'under', 'the', 'command', 'of', 'the',
	    ...               'Party']

	    >>> reference3 = ['It', 'is', 'the', 'practical', 'guide', 'for', 'the',
	    ...               'army', 'always', 'to', 'heed', 'the', 'directions',
	    ...               'of', 'the', 'party']

	    >>> bleu(candidate1, [reference1, reference2, reference3], weights)
	    0.504...

	    >>> bleu(candidate2, [reference1, reference2, reference3], weights)
	    0

	    Papineni, Kishore, et al. "BLEU: A method for automatic evaluation of
	    machine translation." Proceedings of the 40th annual meeting on association for
	    computational linguistics. Association for Computational Linguistics, 2002.
	    http://www.aclweb.org/anthology/P02-1040.pdf

	    """
	    p_ns = (
	        self._modified_precision(candidate, references, i)
	        for i, _ in enumerate(weights, start=1)
	    )

	    try:
	        s = math.fsum(w * math.log(p_n) for w, p_n in zip(weights, p_ns))
	    except ValueError:
	        # some p_ns is 0
	        return 0

	    bp = self._brevity_penalty(candidate, references)
	    return bp * math.exp(s)
Calculate BLEU score (Bilingual Evaluation Understudy)

	    :param candidate: a candidate sentence
	    :type candidate: list(str)
	    :param references: reference sentences
	    :type references: list(list(str))
	    :param weights: weights for unigrams, bigrams, trigrams and so on
	    :type weights: list(float)

	    >>> weights = [0.25, 0.25, 0.25, 0.25]
	    >>> candidate1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'which',
	    ...               'ensures', 'that', 'the', 'military', 'always',
	    ...               'obeys', 'the', 'commands', 'of', 'the', 'party']

	    >>> candidate2 = ['It', 'is', 'to', 'insure', 'the', 'troops',
	    ...               'forever', 'hearing', 'the', 'activity', 'guidebook',
	    ...               'that', 'party', 'direct']

	    >>> reference1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'that',
	    ...               'ensures', 'that', 'the', 'military', 'will', 'forever',
	    ...               'heed', 'Party', 'commands']

	    >>> reference2 = ['It', 'is', 'the', 'guiding', 'principle', 'which',
	    ...               'guarantees', 'the', 'military', 'forces', 'always',
	    ...               'being', 'under', 'the', 'command', 'of', 'the',
	    ...               'Party']

	    >>> reference3 = ['It', 'is', 'the', 'practical', 'guide', 'for', 'the',
	    ...               'army', 'always', 'to', 'heed', 'the', 'directions',
	    ...               'of', 'the', 'party']

	    >>> bleu(candidate1, [reference1, reference2, reference3], weights)
	    0.504...

	    >>> bleu(candidate2, [reference1, reference2, reference3], weights)
	    0

	    Papineni, Kishore, et al. "BLEU: A method for automatic evaluation of
	    machine translation." Proceedings of the 40th annual meeting on association for
	    computational linguistics. Association for Computational Linguistics, 2002.
	    http://www.aclweb.org/anthology/P02-1040.pdf

	    
Calculate BLEU score (Bilingual Evaluation Understudy)
Calculate BLEU score ( Bilingual Evaluation Understudy )
def bleu(self,candidate, references, weights):
	    p_ns = (
	        self._modified_precision(candidate, references, i)
	        for i, _ in enumerate(weights, start=1)
	    )
	    try:
	        s = math.fsum(w * math.log(p_n) for w, p_n in zip(weights, p_ns))
	    except ValueError:
	        return 0
	    bp = self._brevity_penalty(candidate, references)
	    return bp * math.exp(s)
def bleu ( self , candidate , references , weights ) : p_ns = ( self . _modified_precision ( candidate , references , i ) for i , _ in enumerate ( weights , start = 1 ) ) try : s = math . fsum ( w * math . log ( p_n ) for w , p_n in zip ( weights , p_ns ) ) except ValueError : return 0 bp = self . _brevity_penalty ( candidate , references ) return bp * math . exp ( s )
Calculate BLEU score (Bilingual Evaluation Understudy)
Calculate BLEU score ( Bilingual Evaluation Understudy )
"""Calculate BLEU score (Bilingual Evaluation Understudy)

	    :param candidate: a candidate sentence
	    :type candidate: list(str)
	    :param references: reference sentences
	    :type references: list(list(str))
	    :param weights: weights for unigrams, bigrams, trigrams and so on
	    :type weights: list(float)

	    >>> weights = [0.25, 0.25, 0.25, 0.25]
	    >>> candidate1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'which',
	    ...               'ensures', 'that', 'the', 'military', 'always',
	    ...               'obeys', 'the', 'commands', 'of', 'the', 'party']

	    >>> candidate2 = ['It', 'is', 'to', 'insure', 'the', 'troops',
	    ...               'forever', 'hearing', 'the', 'activity', 'guidebook',
	    ...               'that', 'party', 'direct']

	    >>> reference1 = ['It', 'is', 'a', 'guide', 'to', 'action', 'that',
	    ...               'ensures', 'that', 'the', 'military', 'will', 'forever',
	    ...               'heed', 'Party', 'commands']

	    >>> reference2 = ['It', 'is', 'the', 'guiding', 'principle', 'which',
	    ...               'guarantees', 'the', 'military', 'forces', 'always',
	    ...               'being', 'under', 'the', 'command', 'of', 'the',
	    ...               'Party']

	    >>> reference3 = ['It', 'is', 'the', 'practical', 'guide', 'for', 'the',
	    ...               'army', 'always', 'to', 'heed', 'the', 'directions',
	    ...               'of', 'the', 'party']

	    >>> bleu(candidate1, [reference1, reference2, reference3], weights)
	    0.504...

	    >>> bleu(candidate2, [reference1, reference2, reference3], weights)
	    0

	    Papineni, Kishore, et al. "BLEU: A method for automatic evaluation of
	    machine translation." Proceedings of the 40th annual meeting on association for
	    computational linguistics. Association for Computational Linguistics, 2002.
	    http://www.aclweb.org/anthology/P02-1040.pdf

	    """ # some p_ns is 0
self
candidate
a candidate sentence
a candidate sentence
references
None
weights
weights for unigrams, bigrams, trigrams and so on
weights for unigrams bigrams trigrams and so on