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
d9ab3f17
Commit
d9ab3f17
authored
Apr 19, 2015
by
Steven Bird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolved merge conflicts
parent
98c2476a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
19 deletions
+0
-19
nltk/model/ngram.py
+0
-19
No files found.
nltk/model/ngram.py
View file @
d9ab3f17
...
...
@@ -234,12 +234,7 @@ class NgramModel(ModelI):
return
text
def
_generate_one
(
self
,
context
):
<<<<<<<
HEAD
context
=
(
self
.
_lpad
+
tuple
(
context
))[
-
self
.
_n
+
1
:]
=======
context
=
(
self
.
_lpad
+
tuple
(
context
))[
-
self
.
_n
+
1
:]
>>>>>>>
c54edec6856b877dd049cea5ef4a75b842af6c28
if
context
in
self
:
return
self
[
context
]
.
generate
()
elif
self
.
_n
>
1
:
...
...
@@ -260,17 +255,10 @@ class NgramModel(ModelI):
H
=
0.0
# entropy is conventionally denoted by "H"
text
=
list
(
self
.
_lpad
)
+
text
+
list
(
self
.
_rpad
)
for
i
in
range
(
self
.
_n
-
1
,
len
(
text
)):
<<<<<<<
HEAD
context
=
tuple
(
text
[
i
-
self
.
_n
+
1
:
i
])
token
=
text
[
i
]
e
+=
self
.
logprob
(
token
,
context
)
return
e
/
float
(
len
(
text
)
-
(
self
.
_n
-
1
))
=======
context
=
tuple
(
text
[(
i
-
self
.
_n
+
1
):
i
])
token
=
text
[
i
]
H
+=
self
.
logprob
(
token
,
context
)
return
H
/
float
(
len
(
text
)
-
(
self
.
_n
-
1
))
>>>>>>>
c54edec6856b877dd049cea5ef4a75b842af6c28
def
perplexity
(
self
,
text
):
"""
...
...
@@ -284,12 +272,6 @@ class NgramModel(ModelI):
return
pow
(
2.0
,
self
.
entropy
(
text
))
def
__contains__
(
self
,
item
):
<<<<<<<
HEAD
return
tuple
(
item
)
in
self
.
_probdist
.
freqdist
def
__getitem__
(
self
,
item
):
return
self
.
_probdist
[
tuple
(
item
)]
=======
if
not
isinstance
(
item
,
tuple
):
item
=
(
item
,)
return
item
in
self
.
_model
...
...
@@ -298,7 +280,6 @@ class NgramModel(ModelI):
if
not
isinstance
(
item
,
tuple
):
item
=
(
item
,)
return
self
.
_model
[
item
]
>>>>>>>
c54edec6856b877dd049cea5ef4a75b842af6c28
def
__repr__
(
self
):
return
'<NgramModel with
%
d
%
d-grams>'
%
(
len
(
self
.
_ngrams
),
self
.
_n
)
...
...
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