spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

Italian "po'" word is tokenized incorrectly

Open dvaosta opened this issue 8 years ago • 4 comments

Your Environment

  • spaCy version: 2.0.12
  • Platform: Windows-10-10.0.16299-SP0
  • Python version: 3.6.5
  • Models: it

"Po'" (with the apostrophe) is the truncated form of "poco" (that means "a little") and must be considered as a single word, while currently spacy considers "po" and "'" as two tokens. Notice that "Po", without the apostrophe, is the name of the longhest river in Italy. But in this case it always has the capital P and is never followed by the apostrophe.

dvaosta avatar Oct 04 '18 20:10 dvaosta

If I am not an Italian language speaker, but for this there are two things that you could do:

  1. Add a tokenizer special case.
import spacy
from spacy.symbols import ORTH, LEMMA
nlp = spacy.load('it')
nlp.tokenizer.add_special_case('Po"', [{ORTH: 'Po"', LEMMA: 'poco'}])
  1. Add it globally as a tokenizer exception and submit a pull request for that. As I can see here, there is no tokenizer_exceptions file for the Italian Language. You can create one and add this exception. You can find the template for creating this file here. For your case, it will be something like that:
# coding: utf8
from __future__ import unicode_literals
from ...symbols import ORTH, LEMMA, TAG, NORM, ADP, DET
# Exceptions should be added in the following format:

_exc = {
    'Po"': [{ORTH: 'po"', LEMMA: 'poco'}]
}

TOKENIZER_EXCEPTIONS = _exc

Remember to update accordingly the init file for the italian language as well.

Hope it helps :)

giannisdaras avatar Oct 08 '18 11:10 giannisdaras

Thanks.

dvaosta avatar Oct 09 '18 09:10 dvaosta

Merging this with the master issue in #1642!

ines avatar Jan 07 '19 12:01 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 Feb 06 '19 13:02 lock[bot]