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
d13caba2
Commit
d13caba2
authored
Oct 31, 2014
by
Steven Bird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stylistic changes
parent
33355f4f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
+9
-9
nltk/align/bleu.py
+9
-9
No files found.
nltk/align/bleu.py
View file @
d13caba2
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# Natural Language Toolkit: BLEU
# Natural Language Toolkit: BLEU
#
#
# Copyright (C) 2001-201
3
NLTK Project
# Copyright (C) 2001-201
4
NLTK Project
# Authors: Chin Yee Lee, Hengfeng Li, Ruxin Hou, Calvin Tanujaya Lim
# Authors: Chin Yee Lee, Hengfeng Li, Ruxin Hou, Calvin Tanujaya Lim
# Contributors: Dmitrijs Milajevs
# URL: <http://nltk.org/>
# URL: <http://nltk.org/>
# For license information, see LICENSE.TXT
# For license information, see LICENSE.TXT
...
@@ -131,18 +132,17 @@ class BLEU(object):
...
@@ -131,18 +132,17 @@ class BLEU(object):
candidate
=
[
c
.
lower
()
for
c
in
candidate
]
candidate
=
[
c
.
lower
()
for
c
in
candidate
]
references
=
[[
r
.
lower
()
for
r
in
reference
]
for
reference
in
references
]
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
))
p_ns
=
(
BLEU
.
modified_precision
(
candidate
,
references
,
i
)
for
i
,
_
in
enumerate
(
weights
,
start
=
1
))
p_ns_nonzero
=
list
(
filter
(
None
,
p_ns
))
p_ns_nonzero
=
list
(
filter
(
None
,
p_ns
))
if
not
p_ns_nonzero
:
if
p_ns_nonzero
:
# There is zero aliment, so the score is 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
)
else
:
# no alignments
return
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
)
@staticmethod
@staticmethod
def
modified_precision
(
candidate
,
references
,
n
):
def
modified_precision
(
candidate
,
references
,
n
):
""" Calculate modified ngram precision.
""" Calculate modified ngram precision.
...
...
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