spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

Enhance language.py to allow pipe() to work with Doc iterator

Open hodsonjames opened this issue 9 years ago • 3 comments

Given the improvement that comes from using pipe() over nlp(), would it be possible to enhance language.py::pipe() to take an argument as_docs=False, which, if set to True, would use an iterator over Doc objects instead of strings?

This would allow the use of pre-tokenized text, and arbitrary pre-processing, while retaining the batch advantages of the core NLP models.

hodsonjames avatar Nov 09 '17 20:11 hodsonjames

Nah, just set the tokenizer to a noop:

nlp = Language(make_doc=lambda doc: doc)

Or if you've already created the object:

nlp.tokenizer = lambda doc: doc

What might be nice would be to have a context manager with_tokenizer, where such a replacement could be block-scoped.

honnibal avatar Nov 09 '17 22:11 honnibal

Fair enough--I hadn't thought about that. Elegant, if a little implicit :) This solves my issue--feeding pre-tokenized docs to the pipe... Thanks.

hodsonjames avatar Nov 10 '17 03:11 hodsonjames

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar May 08 '18 08:05 lock[bot]