我正在学习第1 部分和第2 部分提供的教程.不幸的是,作者没有时间进行涉及使用余弦相似性的最后一节实际找到两个文档之间的距离.我在文章的示例中借助stackoverflow中的以下链接,包括上面链接中提到的代码(只是为了让生活更轻松)
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from nltk.corpus import stopwords
import numpy as np
import numpy.linalg as LA
train_set = ["The sky is blue.", "The sun is bright."] # Documents
test_set = ["The sun in the sky is bright."] # Query
stopWords = stopwords.words('english')
vectorizer = CountVectorizer(stop_words = stopWords)
#print vectorizer
transformer = TfidfTransformer()
#print transformer
trainVectorizerArray = vectorizer.fit_transform(train_set).toarray()
testVectorizerArray = vectorizer.transform(test_set).toarray()
print 'Fit Vectorizer to train set', trainVectorizerArray …Run Code Online (Sandbox Code Playgroud) 我有两个单词,我想计算它们之间的相似度,以便对它们是否重复进行排名。
如何使用深度学习/NLP 方法实现这一目标?
我正在寻找的不仅仅是两个文本之间的简单相似度分数。但是字符串中子字符串的相似度得分。说:
text1 = 'cat is sleeping on the mat'.
text2 = 'The cat is sleeping on the red mat in the living room'.
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,所有的词text1都存在于text2完全中,因此相似度应该是 100%。
如果text1缺少某些单词,则得分会更低。
我正在处理一个不同段落大小的大型数据集,因此在具有这种相似性得分的较大段落中找到较小的段落至关重要。
我只发现了比较两个字符串的字符串相似性,例如余弦相似性、difflib 相似性等。但不是关于另一个字符串中的子字符串分数。
我有一个带有系列字幕的文件夹.我希望每集从文件夹中获取一个字幕文件.我的问题是,有些字幕在同一集中,但名称不同
/data/netfilx/reality_subtitle/Top Chef/Top.Chef-Texas.S09E02.720p.HDTV.x264-MOMENTUM.HI.srt
/data/netfilx/reality_subtitle/Top Chef/Top.Chef-Texas.902.720p.HDTV.x264.MOMENTUM.srt
/data/netfilx/reality_subtitle/Top Chef/Top.Chef-Texas.9X02.HDTV.XviD-MOMENTUM.HI.srt
/data/netfilx/reality_subtitle/Top Chef/Top.Chef-Texas.S09E02.HDTV.XviD-MOMENTUM.srt
Run Code Online (Sandbox Code Playgroud)
所以他们非常相似,但不是100%相同.
如何删除重复文档并保留仅使用不同的剧集字幕?
我会附上我尝试的但不幸的是我很无能......