(self, words, N)
| 183 | self.n_tokens = len(vocab) if vocab is not None else len(tokens) |
| 184 | |
| 185 | def log_prob(self, words, N): |
| 186 | assert N in self.counts, "You do not have counts for {}-grams".format(N) |
| 187 | |
| 188 | if N > len(words): |
| 189 | err = "Not enough words for a gram-size of {}: {}".format(N, len(words)) |
| 190 | raise ValueError(err) |
| 191 | |
| 192 | total_prob = 0 |
| 193 | for ngram in nltk.ngrams(words, N): |
| 194 | total_prob += self._log_ngram_prob(ngram) |
| 195 | return total_prob |
| 196 | |
| 197 | def _log_ngram_prob(self, ngram): |
| 198 | N = len(ngram) |
no test coverage detected