spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

Consider changing multiple infix tokenization behavior (custom tokenization)

Open hodsonjames opened this issue 9 years ago • 4 comments

Info about spaCy

  • Python version: 2.7.13
  • Platform: Linux-4.10.0-38-generic-x86_64-with-debian-stretch-sid
  • spaCy version: 1.9.0
  • Installed models: en

https://github.com/explosion/spaCy/blob/cf2da695e861b96fb0bd6b3c856d5fc571d21fa4/spacy/tokenizer.pyx#L299

The infix iterator assumes that multiple infixes should not be recursively split. For example:

u"Football-players/-fans"

with infix_finditer as the following re: infix_re = re.compile(r'''[-/]''').finditer

Leads to the following tokenization:

[Football, -, players, /, -fans] For consistency, I would hope the behavior to yield:

[Football, -, players, /, -, fans]

An alternative solution would be to apply prefix/suffix/infix and check for token matching within the same loop, until convergence, though I can see why you chose to first remove prefixes/suffixes. Admittedly this is a corner case...

hodsonjames avatar Nov 07 '17 19:11 hodsonjames

I think it's a little easier to reason about if the prefix and suffix rules are applied first. I'm already a little unhappy with the regex performance, so I'm disinclined to make the loop more complicated :)

Is there a way to work around this and get the behaviour you want by customising the infix expression?

Interesting case though!

honnibal avatar Nov 07 '17 20:11 honnibal

Why not just remove the check on line 299 above? Then multiple infixes next to each other would be added. I don't see the downside of doing this, but perhaps I'm missing something?

hodsonjames avatar Nov 07 '17 20:11 hodsonjames

Merging this with the master issue #1642!

ines avatar Mar 27 '18 23:03 ines

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 07 '18 18:05 lock[bot]