spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

Wrong tokenization of text with quotes separated only by coma

Open serzh opened this issue 7 years ago • 2 comments

How to reproduce the behaviour

Spacy do wrong tokenization of the text that has quotes in it that are seprated only with coma, without the space. For example:

   > list(map(print(nlp.tokenizer('"high","low"'))))
   "
   high","low
   "

With space everything works as expected:

   > list(map(print(nlp.tokenizer('"high", "low"'))))
   "
   high
   "
   ,
   "
   low
   "

This whole is a little bit confusing, because documentation says that Tokenizer works "recursively", however in the code we see that infix_finditer is called only once at the end of suffix-prefix iterations. As a fix I've added spacy.lang.char_classes.LIST_QUOTES to the lisft of Tokenizer infixes and overrided infix_finditer, but I think it is better to fix it in the spacy itself.

Your Environment

  • spaCy version: 2.1.6
  • Platform: Darwin-17.7.0-x86_64-i386-64bit
  • Python version: 3.6.6

serzh avatar Jul 17 '19 14:07 serzh

Thanks for the report! If you think your edits to the tokenizer are general enough and wouldn't negatively impact speed/accuracy, please feel free to open a pull request with your contributions (see here for general guidelines).

You could also add a unit test here for this specific issue to ensure regressions don't pop up in later developments. Note that statistical models should not be used in these texts, but you can easily rely on the en_tokenizer, for an example see https://github.com/explosion/spaCy/blob/master/spacy/tests/regression/test_issue3521.py.

svlandeg avatar Oct 04 '19 13:10 svlandeg

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.

github-actions[bot] avatar Nov 04 '21 00:11 github-actions[bot]