MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / form_ngrams

Function form_ngrams

test/general/lm_eval/decontamination/janitor.py:22–36  ·  view source on GitHub ↗
(sequence, n)

Source from the content-addressed store, hash-verified

20# Implementation from nltk source
21# https://www.nltk.org/_modules/nltk/util.html
22def form_ngrams(sequence, n):
23 history = []
24 while n > 1:
25 # PEP 479, prevent RuntimeError from being raised when StopIteration bubbles out of generator
26 try:
27 next_item = next(sequence)
28 except StopIteration:
29 # no more data, terminate the generator
30 return
31 history.append(next_item)
32 n -= 1
33 for item in sequence:
34 history.append(item)
35 yield tuple(history)
36 del history[0]
37
38
39def word_ngrams(s, n):

Callers 2

word_ngramsFunction · 0.85
word_ngrams_indicesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected