【问题标题】:Named Entity Recognition using Vowpal Wabbit appears to memorise training data使用 Vowpal Wabbit 的命名实体识别似乎可以记住训练数据
【发布时间】:2017-09-15 08:54:12
【问题描述】:

我正在使用 Vowpal Wabbit 的 python API 来训练命名实体识别分类器,以从短句中检测人名、组织和位置。我整理了一个IPython Notebook,其中包含有关数据的详细信息、模型的训练方式以及评估语句中识别的实体。训练数据来自ATISCONLL 2003 数据集。

我的 Vowpal Wabbit SearchTask 类的设置(基于this tutorial):

class SequenceLabeler(pyvw.SearchTask):
    def __init__(self, vw, sch, num_actions):
        pyvw.SearchTask.__init__(self, vw, sch, num_actions)

        sch.set_options( sch.AUTO_HAMMING_LOSS | sch.AUTO_CONDITION_FEATURES )

    def _run(self, sentence):
        output = []
        for n in range(len(sentence)):
            pos,word = sentence[n]
            with self.vw.example({'w': [word]}) as ex:
                pred = self.sch.predict(examples=ex, my_tag=n+1, oracle=pos, condition=[(n,'p'), (n-1, 'q')])
                output.append(pred)
        return output

模型训练:

vw = pyvw.vw(search=num_labels, search_task='hook', ring_size=1024)
#num_labels = 3 ('B'eginning entity, 'I'nside entity, 'O'ther)

sequenceLabeler = vw.init_search_task(SequenceLabeler)    
sequenceLabeler.learn(training_set)

该模型在训练数据中存在的命名实体(精确字符串匹配)上表现良好,但对使用相同结构的新示例的泛化能力很差。也就是说,分类器会从训练数据中识别句子中存在的实体,但是当我只更改名称时,它们的效果很差。

sample_sentences = ['new york to las vegas on sunday afternoon', 
                    'chennai to mumbai on sunday afternoon',
                    'lima to ascuncion on sunday afternoon']

运行分类器时的输出:

new york to las vegas on sunday afternoon
locations - ['new york', 'las vegas']

chennai to mumbai on sunday afternoon
locations - []

lima to ascuncion on sunday afternoon
locations - []

这表明即使句子保持不变:'a to b on sunday下午',模型也无法识别新位置,可能是因为它已经记住了训练示例?

organisationperson 分类器的结果相似。这些可以在我的Github 中找到。

我的问题是 -

  1. 我在这里做错了什么?
  2. 我可以改变模型的其他参数吗?或者我可以更好地使用现有的,例如ring_sizesearch_task
  3. 您有什么建议可以提高模型的通用性吗?

【问题讨论】:

    标签: python named-entity-recognition vowpalwabbit named-entity-extraction


    【解决方案1】:
    1. 您不使用地名词典,不使用正交特征(例如 --spelling--affix),您的数据都是小写的,因此唯一可以提供帮助的特征是一元和二元身份。过度拟合训练数据也就不足为奇了。从理论上讲,您可以使用遵循模式的人工命名实体(周日从 x 到 y)来提升您的训练数据,但如果这有帮助,那么构建基于规则的分类器会更容易。

    2. 有很多参数,例如-l(学习率)和--passes。请参阅 tutoriallist of options。 请注意,ring_size 不会影响预测质量,您只需将其设置得足够高,以免收到任何警告(即高于最长序列)。

    3. 见 1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-12
      • 2015-05-24
      • 1970-01-01
      • 1970-01-01
      • 2014-01-25
      • 2021-10-13
      • 2021-10-03
      • 2011-10-20
      相关资源
      最近更新 更多