MCPcopy Index your code
hub / github.com/ddbourgin/numpy-ml / _get_counts

Method _get_counts

numpy_ml/preprocessing/nlp.py:264–271  ·  view source on GitHub ↗

Collect bigram counts for the tokens in vocab

(self, vocab)

Source from the content-addressed store, hash-verified

262 return self
263
264 def _get_counts(self, vocab):
265 """Collect bigram counts for the tokens in vocab"""
266 pair_counts = defaultdict(int)
267 for word, count in vocab.items():
268 pairs = ngrams(word.split(" "), 2)
269 for p in pairs:
270 pair_counts[p] += count
271 return pair_counts
272
273 def _merge(self, bigram, vocab):
274 """Replace `bigram` with a single token and update vocab accordingly"""

Callers 1

fitMethod · 0.95

Calls 1

ngramsFunction · 0.85

Tested by

no test coverage detected