use*_*085 5 nlp machine-learning
即:"大学","学校"和"学院"属于同一群,"论文","奖学金","钱"等词也属于同一群.这是ML还是NLP问题?
Wes*_*ugh 15
这取决于你对类似的定义有多严格.
正如其他人所指出的那样,你可以使用潜在的语义分析或相关的潜在Dirichlet分配.
正如所指出的,您可能希望将现有资源用于此类事务.
许多研究论文(例子)使用术语语义相似性.计算的基本思想通常是通过查找图表上两个单词之间的距离来完成的,如果单词是其父类型,则单词是子单词.例如:"鸣鸟"将是"鸟"的孩子.如果您愿意,语义相似性可以用作创建聚类的距离度量.
另外,如果你对一些语义相似性度量的值设置一个阈值,你可以得到一个布尔值True或False.这是我创建的一个Gist(word_similarity.py),它使用NLTK的语料库阅读器进行WordNet.希望这会指向正确的方向,并为您提供更多搜索条件.
def sim(word1, word2, lch_threshold=2.15, verbose=False):
"""Determine if two (already lemmatized) words are similar or not.
Call with verbose=True to print the WordNet senses from each word
that are considered similar.
The documentation for the NLTK WordNet Interface is available here:
http://nltk.googlecode.com/svn/trunk/doc/howto/wordnet.html
"""
from nltk.corpus import wordnet as wn
results = []
for net1 in wn.synsets(word1):
for net2 in wn.synsets(word2):
try:
lch = net1.lch_similarity(net2)
except:
continue
# The value to compare the LCH to was found empirically.
# (The value is very application dependent. Experiment!)
if lch >= lch_threshold:
results.append((net1, net2))
if not results:
return False
if verbose:
for net1, net2 in results:
print net1
print net1.definition
print net2
print net2.definition
print 'path similarity:'
print net1.path_similarity(net2)
print 'lch similarity:'
print net1.lch_similarity(net2)
print 'wup similarity:'
print net1.wup_similarity(net2)
print '-' * 79
return True
Run Code Online (Sandbox Code Playgroud)
示例输出
>>> sim('college', 'academy')
True
>>> sim('essay', 'schoolwork')
False
>>> sim('essay', 'schoolwork', lch_threshold=1.5)
True
>>> sim('human', 'man')
True
>>> sim('human', 'car')
False
>>> sim('fare', 'food')
True
>>> sim('fare', 'food', verbose=True)
Synset('fare.n.04')
the food and drink that are regularly served or consumed
Synset('food.n.01')
any substance that can be metabolized by an animal to give energy and build tissue
path similarity:
0.5
lch similarity:
2.94443897917
wup similarity:
0.909090909091
-------------------------------------------------------------------------------
True
>>> sim('bird', 'songbird', verbose=True)
Synset('bird.n.01')
warm-blooded egg-laying vertebrates characterized by feathers and forelimbs modified as wings
Synset('songbird.n.01')
any bird having a musical call
path similarity:
0.25
lch similarity:
2.25129179861
wup similarity:
0.869565217391
-------------------------------------------------------------------------------
True
>>> sim('happen', 'cause', verbose=True)
Synset('happen.v.01')
come to pass
Synset('induce.v.02')
cause to do; cause to act in a specified manner
path similarity:
0.333333333333
lch similarity:
2.15948424935
wup similarity:
0.5
-------------------------------------------------------------------------------
Synset('find.v.01')
come upon, as if by accident; meet with
Synset('induce.v.02')
cause to do; cause to act in a specified manner
path similarity:
0.333333333333
lch similarity:
2.15948424935
wup similarity:
0.5
-------------------------------------------------------------------------------
True
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4763 次 |
| 最近记录: |