Repository: mjpost/sacrebleu (language: python)

Issue:
BLEU with max_ngram_order gives IndexError
I think `max_ngram_order` doesn't work yet? Here's what I tried.

```
! pip install sacrebleu
import sacrebleu
sacrebleu.__version__
2.0.0
```

```python
from sacrebleu.metrics import BLEU

refs = [ # First set of references
         ['The dog bit the man.', 'It was not unexpected.', 'The man bit him first.'],
         # Second set of references
         ['The dog had bit the man.', 'No one was surprised.', 'The man had bitten the dog.'],
       ]
cands = ['The dog bit the man.', "It wasn't surprising.", 'The man had just bitten him.']

bleu = BLEU(max_ngram_order=3)
bleu.corpus_score(cands, refs)
```
```
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-56-e670c5110f81> in <module>()
     30 bleu = BLEU(tokenize="none", max_ngram_order=3)
     31 bleu = BLEU(max_ngram_order=3)
---> 32 bleu.corpus_score(cands, refs)

3 frames
/usr/local/lib/python3.7/dist-packages/sacrebleu/metrics/bleu.py in compute_bleu(correct, total, sys_len, ref_len, smooth_method, smooth_value, effective_order, max_ngram_order)
    254         :param ref_streams: A list of one or more reference streams (each a sequence of segments)
    255         :param use_effective_order: Account for references that are shorter than the largest n-gram.
--> 256         :return: a `BLEUScore` object containing everything you'd want
    257         """
    258 

IndexError: list index out of range
```


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/check-build.yml b/.github/workflows/check-build.yml
index f4056f1c..ae92ac08 100644
--- a/.github/workflows/check-build.yml
+++ b/.github/workflows/check-build.yml
@@ -33,7 +33,7 @@ jobs:
       - name: Install python dependencies
         run: |
           python -m pip install --upgrade pip
-          pip install pytest-cov
+          pip install pytest
           pip install .[ja]
       - name: Python pytest test suite
         run: python3 -m pytest
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4594e77c..4bd0c90f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,9 +1,10 @@
 # Release Notes
 
-- 2.0.1 (2021-XX-XX)
+- 2.0.1 (TBD)
   - Handle potential memory usage issues due to LRU caching in tokenizers (#167)
+  - Bugfix: BLEU.corpus_score() now using max_ngram_order (#173)
 
-- 2.0.0 (2021-07-XX)
+- 2.0.0 (2021-07-18)
   - Build: Add Windows and OS X testing to Travis CI.
   - Improve documentation and type annotations.
   - Drop `Python < 3.6` support and migrate to f-strings.
diff --git a/sacrebleu/__init__.py b/sacrebleu/__init__.py
index 638715d2..d379b0b4 100644
--- a/sacrebleu/__init__.py
+++ b/sacrebleu/__init__.py
@@ -14,7 +14,7 @@
 # express or implied. See the License for the specific language governing
 # permissions and limitations under the License.
 
-__version__ = '2.0.0'
+__version__ = '2.0.1'
 __description__ = 'Hassle-free computation of shareable, comparable, and reproducible BLEU, chrF, and TER scores'
 
 
diff --git a/sacrebleu/metrics/bleu.py b/sacrebleu/metrics/bleu.py
index 45b2a266..67ffd66e 100644
--- a/sacrebleu/metrics/bleu.py
+++ b/sacrebleu/metrics/bleu.py
@@ -300,7 +300,9 @@ def _compute_score_from_stats(self, stats: List[int]) -> BLEUScore:
             total=stats[2 + self.max_ngram_order:],
             sys_len=int(stats[0]), ref_len=int(stats[1]),
             smooth_method=self.smooth_method, smooth_value=self.smooth_value,
-            effective_order=self.effective_order)
+            effective_order=self.effective_order,
+            max_ngram_order=self.max_ngram_order
+        )
 
     def _aggregate_and_compute(self, stats: List[List[int]]) -> BLEUScore:
         """Computes the final BLEU score given the pre-computed corpus statistics.


Test patch:
diff --git a/pytest.ini b/pytest.ini
index f79a6c5b..068d9da9 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -1,2 +1,3 @@
 [pytest]
-addopts = --cov test -v
+addopts = -v
+testpaths = test
diff --git a/test/test_api.py b/test/test_api.py
index facc7d90..d9bb30dc 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -28,7 +28,6 @@
 def test_api_get_source(testset, langpair, sentno, source, reference):
     with open(get_source_file(testset, langpair)) as fh:
         line = fh.readlines()[sentno - 1].strip()
-
         assert line == source
 
 
diff --git a/test/test_bleu.py b/test/test_bleu.py
index be245ecb..d8312de6 100644
--- a/test/test_bleu.py
+++ b/test/test_bleu.py
@@ -133,3 +133,19 @@ def test_degenerate_statistics(statistics, offset, expected_score):
         statistics[2],
         smooth_method='floor', smooth_value=offset).score / 100
     assert score == expected_score
+
+
+test_bleu_max_order = [
+    (1, _hyps, _refs, "77.65"),
+    (2, _hyps, _refs, "60.50"),
+    (3, _hyps, _refs, "53.93"),
+    (4, _hyps, _refs, "48.53"),
+    (5, _hyps, _refs, "46.14"),
+    (6, _hyps, _refs, "43.28"),
+]
+
+
+@pytest.mark.parametrize("order, hyps, refs, expected_bleu", test_bleu_max_order)
+def test_max_ngram_order(order, hyps, refs, expected_bleu):
+    bleu = BLEU(max_ngram_order=order).corpus_score(hyps, refs)
+    assert f"{bleu.score:.2f}" == expected_bleu