Skip to content

Instantly share code, notes, and snippets.

@gideonite
Created August 6, 2017 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gideonite/38f1148d27f685414dc0f32e43a1be27 to your computer and use it in GitHub Desktop.
Save gideonite/38f1148d27f685414dc0f32e43a1be27 to your computer and use it in GitHub Desktop.
import itertools
from spacy.en import English
def gen_items():
print("Yield 0")
yield (0, 'Text 0')
print("Yield 1")
yield (1, 'Text 1')
print("Yield 2")
yield (2, 'Text 2')
nlp = English()
gen1, gen2 = itertools.tee(gen_items())
ids = (id_ for (id_, text) in gen1)
texts = (text for (id_, text) in gen2)
docs = nlp.pipe(texts)
for id_, doc in itertools.izip(ids, docs):
print(id_, doc.text)
@gideonite
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment