Wie zu verwenden pos_tag in NLTK?

Also habe ich versucht-tag ein paar Worte in einer Liste (POS-tagging, um genau zu sein) wie so:

pos = [nltk.pos_tag(i,tagset='universal') for i in lw]

wo lw ist eine Liste von Wörtern (es ist wirklich lange oder ich hätte es gepostet, aber es ist wie [['hello'],['world']] (aka eine Liste von Listen, jede Liste mit einem Wort), aber wenn ich versuche es auszuführen bekomme ich:

Traceback (most recent call last):
  File "<pyshell#183>", line 1, in <module>
    pos = [nltk.pos_tag(i,tagset='universal') for i in lw]
  File "<pyshell#183>", line 1, in <listcomp>
    pos = [nltk.pos_tag(i,tagset='universal') for i in lw]
  File "C:\Users\my system\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\tag\__init__.py", line 134, in pos_tag
    return _pos_tag(tokens, tagset, tagger)
  File "C:\Users\my system\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\tag\__init__.py", line 102, in _pos_tag
    tagged_tokens = tagger.tag(tokens)
  File "C:\Users\my system\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\tag\perceptron.py", line 152, in tag
    context = self.START + [self.normalize(w) for w in tokens] + self.END
  File "C:\Users\my system\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\tag\perceptron.py", line 152, in <listcomp>
    context = self.START + [self.normalize(w) for w in tokens] + self.END
  File "C:\Users\my system\AppData\Local\Programs\Python\Python35\lib\site-packages\nltk\tag\perceptron.py", line 240, in normalize
    elif word[0].isdigit():
IndexError: string index out of range

Kann mir jemand sagen warum und wie ich diesen Fehler bekommen und wie es zu lösen ist? Vielen Dank.

Schreibe einen Kommentar