'Compute the BLEU score from a list of predicted sentences and reference sentences
Args:
sents (list): list of predicted sentences
targets (list): list of reference sentences where each element is a list of
multiple references.'

def bleu_score(self, sents, targets):

    num_ref = len(targets[0])
    output_file = (self.path + '/output')
    reference_files = [(self.path + ('/reference%d' % i)) for i in range(num_ref)]
    bleu_script_url = 'https://raw.githubusercontent.com/karpathy/neuraltalk/master/eval/'
    bleu_script = 'multi-bleu.perl'
    neon_logger.display(('Writing    output    and    reference    sents    to    dir    %s' % self.path))
    output_f = open(output_file, 'w+')
    for sent in sents:
        sent = sent.strip(self.end_token).split()
        output_f.write(('    '.join(sent) + '\n'))
    reference_f = [open(f, 'w') for f in reference_files]
    for i in range(num_ref):
        for target_sents in targets:
            reference_f[i].write((target_sents[i] + '\n'))
    output_f.close()
    [x.close() for x in reference_f]
    owd = os.getcwd()
    os.chdir(self.path)
    if (not os.path.exists(bleu_script)):
        Dataset.fetch_dataset(bleu_script_url, bleu_script, bleu_script, 6000000.0)
    bleu_command = 'perl    multi-bleu.perl    reference    <    output'
    neon_logger.display('Executing    bleu    eval    script:    {}'.format(bleu_command))
    os.system(bleu_command)
    os.chdir(owd)
