-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d3cacc
commit 107cb9f
Showing
6 changed files
with
79 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
import pytest | ||
from collections import Counter | ||
|
||
from mmeval.metrics.bleu import get_n_gram | ||
|
||
|
||
@pytest.mark.parametrize('n_gram', [2, 4]) | ||
def test_get_n_gram(n_gram): | ||
token = ['a', 'cat', 'is', 'on', 'the', 'mat'] | ||
result = get_n_gram(token, n_gram) | ||
if n_gram == 2: | ||
counter = Counter({ | ||
('a', ): 1, | ||
('cat', ): 1, | ||
('is', ): 1, | ||
('on', ): 1, | ||
('the', ): 1, | ||
('mat', ): 1, | ||
('a', 'cat'): 1, | ||
('cat', 'is'): 1, | ||
('is', 'on'): 1, | ||
('on', 'the'): 1, | ||
('the', 'mat'): 1 | ||
}) | ||
else: | ||
counter = Counter({ | ||
('a', ): 1, | ||
('cat', ): 1, | ||
('is', ): 1, | ||
('on', ): 1, | ||
('the', ): 1, | ||
('mat', ): 1, | ||
('a', 'cat'): 1, | ||
('cat', 'is'): 1, | ||
('is', 'on'): 1, | ||
('on', 'the'): 1, | ||
('the', 'mat'): 1, | ||
('a', 'cat', 'is'): 1, | ||
('cat', 'is', 'on'): 1, | ||
('is', 'on', 'the'): 1, | ||
('on', 'the', 'mat'): 1, | ||
('a', 'cat', 'is', 'on'): 1, | ||
('cat', 'is', 'on', 'the'): 1, | ||
('is', 'on', 'the', 'mat'): 1 | ||
}) | ||
assert result == counter |