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

Function ngrams

numpy_ml/preprocessing/nlp.py:58–61  ·  view source on GitHub ↗

Return all `N`-grams of the elements in `sequence`

(sequence, N)

Source from the content-addressed store, hash-verified

56
57
58def ngrams(sequence, N):
59 """Return all `N`-grams of the elements in `sequence`"""
60 assert N >= 1
61 return list(zip(*[sequence[i:] for i in range(N)]))
62
63
64def tokenize_whitespace(

Callers 4

_trainMethod · 0.90
cross_entropyMethod · 0.90
_log_probMethod · 0.90
_get_countsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected