Python 如何影响NLTK将城市标记为GPE而不是动词

Python 如何影响NLTK将城市标记为GPE而不是动词,python,nlp,nltk,Python,Nlp,Nltk,我正在寻找一种方法来影响Python NLTK的IoB标记行为。 考虑下面的代码: from nltk import word_tokenize, pos_tag, ne_chunk from nltk.stem import PorterStemmer from nltk.tag import untag, str2tuple, tuple2str from nltk.chunk import tree2conllstr, conllstr2tree, conlltags2tree, tre

我正在寻找一种方法来影响Python NLTK的IoB标记行为。 考虑下面的代码:

from nltk import word_tokenize, pos_tag, ne_chunk
from nltk.stem import PorterStemmer 
from nltk.tag import untag, str2tuple, tuple2str
from nltk.chunk import tree2conllstr, conllstr2tree, conlltags2tree, tree2conlltags
import nltk

text = "Drive me from Seattle to Brussels"
# Morphology - tagging the words
tokens = word_tokenize(text)

# Part of speech tagging
tagged_tokens = pos_tag(tokens)

# Create named entity tree of tagged tokens
ner_tree = ne_chunk(tagged_tokens)

# Get tag structure
iob_tagged = tree2conlltags(ner_tree)
print(iob_tagged)
这将输出以下值:

[('Drive','VB','O'),('me','PRP','O'),('from','IN','O'),('sattle','NNP','B-GPE'),('to','to','O'),('brussel','VB','O')]


我是否有办法影响或调整NLTK算法/模型,使最后一个词(布鲁塞尔)被标记为地缘政治实体(GPE),而不是动词?我理解动词在那里,因为它跟在To后面,而To通常在动词之前使用

你试过SpaCy吗?我觉得这样比较好。谢谢@Peyman-我会调查的。然而,这个练习是为了我的学习,手头的任务要求我们使用NLTK。标记者使用隐马尔可夫链训练双图或三图。不能正确区分动词类标记和城市作为位置标记不是您的错,而是取决于NLTK工具包使用的培训数据。如果您的任务是使用nltk,那么您的主管必须接受这一点,因为这根本不是您的错。相反,您可以使用nltk来训练自己的马尔可夫模型,然后使用nltk,但可能会得到更好的结果。此外,您还可以编写某种后处理器来纠正不正确的GPE分类。这可能是更好的主意。