Giter VIP home page Giter VIP logo

bleu4python's Introduction

BLEU4Python

A light-weight python version of moses BLEU.

Use Python Now

Moses version of BLEU calculation is widely used in academic researches and well accepted by scholarly community. As python seems to be the main force of deep learning development language, people may want the python version of this algorithm, which performs exactly the same way with the perl one.

Here is what you are looking for. A python code to work the same way as the moses' multi-bleu.perl. What's more, it can also be used as a module of python. Just import bleu and use bleu.corpus_bleu, etc. to do your work in detail.

Features

  • Can be used like moses BLEU
  • Perform well in python 2&3
  • Easily extend to BLEU-n score
  • Call it in python code without creating files
  • A fast realization of timestep-concerned sentence bleu

How to Use

  • If there are files you want to test:
    • python multi_bleu.py [-h] [-hyp PATH_OF_HYPOTHESIS][-ref PATH_OF_REFERENCES [REFERENCES_1, REFERENCES_2, REFERENCES_3 ...]]
    • There should be only ONE hypothesis file and MORE THAN ZERO reference file(s).
    • This will print to screen the BLEU scores like BLEU = 48.39, 76.9/56.0/42.1/32.0 (BP=0.986, ratio=0.986, hyp_len=19588, ref_len=19865). Just same as moses.
  • If you want to use in python code:
    • import bleu
    • If not specified, all the hypothesis should be a 1-dimension string list, and all the references should be a 2-dimension string list.
    • bleu.bleu_count(hypothesis, references, max_n=4) does the most important count work for BLEU. It returns clip_count (correct), count (total), len_hyp, len_ref(sum of closest_length)
    • bleu.corpus_bleu(hypothesis, references, max_n=4) does the complete BLEU calculation. It returns BLEU([final bleu, p_1, p_2, ..., p_max_n]), additional message([BP, ratio, hyp_len, ref_len])
    • bleu.incremental_bleu_count(hypothesis, references, max_n=4) does an incremental count for BLEU, which means it will return the correct count for every timestep(prefix) of every hypothesis.
    • bleu.incremental_sent_bleu(hypothesis, references, max_n=4) does the bleu calculation work according to the result of bleu.incremental_bleu_count. And return all the bleu scores according to the timestep(prefix). ATTENTION: In this function, hypothesis should be a string and references should be a string list.
    • bleu.incremental_test_corpus_bleu(hypothesis, references, max_n=4) is just a test function for bleu.incremental_bleu_count. However, it behaves the same way as bleu.corpus_bleu, except for more time(a little) and memories.

Something Wrong?

  • Make sure your files are UTF-8 formatted. And you should convert all your strings to unicode before calling any of the above functions.
  • If there is any Error (Exception) Message, Read it.
  • Contact the author via Issues or E-mail.

Note: ALL distributions and uses should refer to this repository.

bleu4python's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.