【发布时间】:2011-12-22 03:49:36
【问题描述】:
我正在做一些语义网络/nlp 研究,我有一组稀疏记录,其中包含数字和非数字数据的混合,表示用从简单英语句子中提取的各种特征标记的实体。
例如
uid|features
87w39423|speaker=432, session=43242, sentence=34, obj_called=bob,favorite_color_is=blue
4535k3l535|speaker=512, session=2384, sentence=7, obj_called=tree,isa=plant,located_on=wilson_street
23432424|speaker=997, session=8945305, sentence=32, obj_called=salty,isa=cat,eats=mice
09834502|speaker=876, session=43242, sentence=56, obj_called=the monkey,ate=the banana
928374923|speaker=876, session=43242, sentence=57, obj_called=it,was=delicious
294234234|speaker=876, session=43243, sentence=58, obj_called=the monkey,ate=the banana
sd09f8098|speaker=876, session=43243, sentence=59, obj_called=it,was=hungry
...
单个实体可能出现多次(但每次使用不同的 UID),并且可能与其他实体具有重叠的特征。第二个数据集表示上述 UID 中哪些是绝对相同的。
例如
uid|sameas
87w39423|234k2j,234l24jlsd,dsdf9887s
4535k3l535|09d8fgdg0d9,l2jk34kl,sd9f08sf
23432424|io43po5,2l3jk42,sdf90s8df
09834502|294234234,sd09f8098
...
我将使用什么算法增量训练一个分类器,该分类器可以采用一组特征,并立即推荐 N 个最相似的 UID 以及这些 UID 是否实际代表相同实体?或者,我还想获得缺失特征的建议以进行填充,然后重新分类以获得更确定的匹配。
我研究了传统的近似最近邻算法。例如FLANN 和ANN,我认为这些都不合适,因为它们不可训练(在监督学习的意义上),它们通常也不是为稀疏的非数字输入而设计的。
作为一个非常天真的第一次尝试,我正在考虑使用一个天真的贝叶斯分类器,将每个 SameAs 关系转换为一组训练样本。因此,对于每个具有 B 相同关系的实体 A,我将遍历每个实体并训练分类器,如下所示:
classifier = Classifier()
for entity,sameas_entities in sameas_dataset:
entity_features = get_features(entity)
for other_entity in sameas_entities:
other_entity_features = get_features(other_entity)
classifier.train(cls=entity, ['left_'+f for f in entity_features] + ['right_'+f for f in other_entity_features])
classifier.train(cls=other_entity, ['left_'+f for f in other_entity_features] + ['right_'+f for f in entity_features])
然后像这样使用它:
>>> print classifier.findSameAs(dict(speaker=997, session=8945305, sentence=32, obj_called='salty',isa='cat',eats='mice'), n=7)
[(1.0, '23432424'),(0.999, 'io43po5', (1.0, '2l3jk42'), (1.0, 'sdf90s8df'), (0.76, 'jerwljk'), (0.34, 'rlekwj32424'), (0.08, '09843jlk')]
>>> print classifier.findSameAs(dict(isa='cat',eats='mice'), n=7)
[(0.09, '23432424'), (0.06, 'jerwljk'), (0.03, 'rlekwj32424'), (0.001, '09843jlk')]
>>> print classifier.findMissingFeatures(dict(isa='cat',eats='mice'), n=4)
['obj_called','has_fur','has_claws','lives_at_zoo']
这种方法的可行性如何?最初的批量训练会非常慢,至少 O(N^2),但增量训练支持可以让更新更快地发生。
什么是更好的方法?
【问题讨论】:
-
有趣的问题,一如既往的 Cerin。当你说你想要增量训练时,这是否意味着你获得更多的实体数据、更多的“相同”数据或两者兼而有之?
标签: nlp machine-learning classification semantic-web