(self, words, N)
| 88 | self.n_tokens = len(vocab) if vocab is not None else len(tokens) |
| 89 | |
| 90 | def log_prob(self, words, N): |
| 91 | assert N in self.counts, "You do not have counts for {}-grams".format(N) |
| 92 | |
| 93 | if N > len(words): |
| 94 | err = "Not enough words for a gram-size of {}: {}".format(N, len(words)) |
| 95 | raise ValueError(err) |
| 96 | |
| 97 | total_prob = 0 |
| 98 | for ngram in nltk.ngrams(words, N): |
| 99 | total_prob += self._log_ngram_prob(ngram) |
| 100 | return total_prob |
| 101 | |
| 102 | def _log_ngram_prob(self, ngram): |
| 103 | N = len(ngram) |
no test coverage detected