Skip to content

BLEU

from nltk.translate.bleu_score import SmoothingFunction, sentence_bleu

기준 문장

reference = '''
    It is the guiding principle which guarantees the military forces always being 
    under the command of the Party
'''.strip().split()

생성된 문장

hypothesis = '''
    It is a guide to action which ensures that 
    the military always obeys the commands of the Party
'''.strip().split()    

4단어가 겹치는 경우가 없음

sentence_bleu([reference], hypothesis) 
c:\Users\eupho\anaconda3\lib\site-packages\nltk\translate\bleu_score.py:552: UserWarning: 
The hypothesis contains 0 counts of 4-gram overlaps.
Therefore the BLEU score evaluates to 0, independently of
how many N-gram overlaps of lower order it contains.
Consider using lower n-gram order or use SmoothingFunction()
  warnings.warn(_msg)
3.6718992240469637e-78

3-gram까지만 계산

sentence_bleu([reference], hypothesis, weights=(1/3, 1/3, 1/3)) 
0.20140621167558334

smoothing

sentence_bleu([reference], hypothesis, smoothing_function=SmoothingFunction().method2)
0.18353610946423723