-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkenlm说明文档.txt
326 lines (316 loc) · 10.9 KB
/
kenlm说明文档.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
NAME
kenlm
CLASSES
builtins.object
Config
FullScoreReturn
LoadMethod
Model
LanguageModel
State
class Config(builtins.object)
| Wrapper around lm::ngram::Config.
| Pass this to Model's constructor to set the load_method.
|
| Methods defined here:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| load_method
class FullScoreReturn(builtins.object)
| Wrapper around FullScoreReturn.
|
| Notes:
| `prob` has been renamed to `log_prob`
| `oov` has been added to flag whether the word is OOV
|
| Methods defined here:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| log_prob
|
| ngram_length
|
| oov
class LanguageModel(Model)
| Backwards compatability stub. Use Model.
|
| Method resolution order:
| LanguageModel
| Model
| builtins.object
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Methods inherited from Model:
|
| BaseFullScore(...)
| Wrapper around model.BaseScore(in_state, Index(word), out_state)
|
| :param word: the suffix
| :param state: the context (defaults to NullContext)
| :returns: FullScoreReturn(word|state)
|
| BaseScore(...)
| Return p(word|in_state) and update the output state.
| Wrapper around model.BaseScore(in_state, Index(word), out_state)
|
| :param word: the suffix
| :param state: the context (defaults to NullContext)
| :returns: p(word|state)
|
| BeginSentenceWrite(...)
| Change the given state to a BOS state.
|
| NullContextWrite(...)
| Change the given state to a NULL state.
|
| __contains__(self, key, /)
| Return key in self.
|
| __init__(...)
| Load the language model.
|
| :param path: path to an arpa file or a kenlm binary file.
| :param config: configuration options (see lm/config.hh for documentation)
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| __reduce__(...)
| helper for pickle
|
| __repr__(self, /)
| Return repr(self).
|
| full_scores(...)
| full_scores(sentence, bos = True, eos = Ture) -> generate full scores (prob, ngram length, oov)
| @param sentence is a string (do not use boundary symbols)
| @param bos should kenlm add a bos state
| @param eos should kenlm add an eos state
|
| perplexity(...)
| Compute perplexity of a sentence.
| @param sentence One full sentence to score. Do not include <s> or </s>.
|
| score(...)
| Return the log10 probability of a string. By default, the string is
| treated as a sentence.
| return log10 p(sentence </s> | <s>)
|
| If you do not want to condition on the beginning of sentence, pass
| bos = False
| Never include <s> as part of the string. That would be predicting the
| beginning of sentence. Language models are only supposed to condition
| on it as context.
|
| Similarly, the end of sentence token </s> can be omitted with
| eos = False
| Since language models explicitly predict </s>, it can be part of the
| string.
|
| Examples:
|
| #Good: returns log10 p(this is a sentence . </s> | <s>)
| model.score("this is a sentence .")
| #Good: same as the above but more explicit
| model.score("this is a sentence .", bos = True, eos = True)
|
| #Bad: never include <s>
| model.score("<s> this is a sentence")
| #Bad: never include <s>, even if bos = False.
| model.score("<s> this is a sentence", bos = False)
|
| #Good: returns log10 p(a fragment)
| model.score("a fragment", bos = False, eos = False)
|
| #Good: returns log10 p(a fragment </s>)
| model.score("a fragment", bos = False, eos = True)
|
| #Ok, but bad practice: returns log10 p(a fragment </s>)
| #Unlike <s>, the end of sentence token </s> can appear explicitly.
| model.score("a fragment </s>", bos = False, eos = False)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from Model:
|
| order
|
| path
class LoadMethod(builtins.object)
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| LAZY = 0
|
| PARALLEL_READ = 4
|
| POPULATE_OR_LAZY = 1
|
| POPULATE_OR_READ = 2
|
| READ = 3
class Model(builtins.object)
| Wrapper around lm::ngram::Model.
|
| Methods defined here:
|
| BaseFullScore(...)
| Wrapper around model.BaseScore(in_state, Index(word), out_state)
|
| :param word: the suffix
| :param state: the context (defaults to NullContext)
| :returns: FullScoreReturn(word|state)
|
| BaseScore(...)
| Return p(word|in_state) and update the output state.
| Wrapper around model.BaseScore(in_state, Index(word), out_state)
|
| :param word: the suffix
| :param state: the context (defaults to NullContext)
| :returns: p(word|state)
|
| BeginSentenceWrite(...)
| Change the given state to a BOS state.
|
| NullContextWrite(...)
| Change the given state to a NULL state.
|
| __contains__(self, key, /)
| Return key in self.
|
| __init__(...)
| Load the language model.
|
| :param path: path to an arpa file or a kenlm binary file.
| :param config: configuration options (see lm/config.hh for documentation)
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| __reduce__(...)
| helper for pickle
|
| __repr__(self, /)
| Return repr(self).
|
| full_scores(...)
| full_scores(sentence, bos = True, eos = Ture) -> generate full scores (prob, ngram length, oov)
| @param sentence is a string (do not use boundary symbols)
| @param bos should kenlm add a bos state
| @param eos should kenlm add an eos state
|
| perplexity(...)
| Compute perplexity of a sentence.
| @param sentence One full sentence to score. Do not include <s> or </s>.
|
| score(...)
| Return the log10 probability of a string. By default, the string is
| treated as a sentence.
| return log10 p(sentence </s> | <s>)
|
| If you do not want to condition on the beginning of sentence, pass
| bos = False
| Never include <s> as part of the string. That would be predicting the
| beginning of sentence. Language models are only supposed to condition
| on it as context.
|
| Similarly, the end of sentence token </s> can be omitted with
| eos = False
| Since language models explicitly predict </s>, it can be part of the
| string.
|
| Examples:
|
| #Good: returns log10 p(this is a sentence . </s> | <s>)
| model.score("this is a sentence .")
| #Good: same as the above but more explicit
| model.score("this is a sentence .", bos = True, eos = True)
|
| #Bad: never include <s>
| model.score("<s> this is a sentence")
| #Bad: never include <s>, even if bos = False.
| model.score("<s> this is a sentence", bos = False)
|
| #Good: returns log10 p(a fragment)
| model.score("a fragment", bos = False, eos = False)
|
| #Good: returns log10 p(a fragment </s>)
| model.score("a fragment", bos = False, eos = True)
|
| #Ok, but bad practice: returns log10 p(a fragment </s>)
| #Unlike <s>, the end of sentence token </s> can appear explicitly.
| model.score("a fragment </s>", bos = False, eos = False)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| order
|
| path
class State(builtins.object)
| Wrapper around lm::ngram::State so that python code can make incremental queries.
|
| Notes:
| * rich comparisons
| * hashable
|
| Methods defined here:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
DATA
__test__ = {}
FILE
/opt/algor/gongxf/anaconda3/lib/python3.6/site-packages/kenlm.cpython-36m-x86_64-linux-gnu.so