Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nltk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
nltk
Commits
33355f4f
Commit
33355f4f
authored
Oct 31, 2014
by
Steven Bird
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #782 from dimazest/bleu_no_aligment_fix
Bleu no aligment fix
parents
085399ea
5d809f41
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletions
+24
-1
nltk/align/bleu.py
+7
-1
nltk/test/bleu.doctest
+17
-0
No files found.
nltk/align/bleu.py
View file @
33355f4f
...
...
@@ -132,7 +132,13 @@ class BLEU(object):
references
=
[[
r
.
lower
()
for
r
in
reference
]
for
reference
in
references
]
p_ns
=
(
BLEU
.
modified_precision
(
candidate
,
references
,
i
)
for
i
,
_
in
enumerate
(
weights
,
start
=
1
))
s
=
math
.
fsum
(
w
*
math
.
log
(
p_n
)
for
w
,
p_n
in
zip
(
weights
,
p_ns
)
if
p_n
)
p_ns_nonzero
=
list
(
filter
(
None
,
p_ns
))
if
not
p_ns_nonzero
:
# There is zero aliment, so the score is 0
return
0
s
=
math
.
fsum
(
w
*
math
.
log
(
p_n
)
for
w
,
p_n
in
zip
(
weights
,
p_ns_nonzero
))
bp
=
BLEU
.
brevity_penalty
(
candidate
,
references
)
return
bp
*
math
.
exp
(
s
)
...
...
nltk/test/bleu.doctest
0 → 100644
View file @
33355f4f
==========
BLEU tests
==========
>>> from nltk.align.bleu import BLEU
If the candidate has no alignment to any of the references, the BLEU score is
0.
>>> BLEU.compute(
... 'John loves Mary'.split(),
... ['The candidate has no alignment to any of the references'.split()],
... [1],
... )
0
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment