Spacy vs Word2Vec中的文档相似性(Document similarity in Spacy vs Word2Vec)
我有一个约12k文档的利基语料库,并且我想测试具有类似含义的近乎重复的文档 - 思考关于由不同新闻机构覆盖的同一事件的文章。
我曾尝试过gensim的Word2Vec,即使测试文档位于语料库中,它也会给我带来可怕的相似性分数(<0.3),并且我尝试了SpaCy,它给了我> 5k个文档的相似度> 0.9。 我测试了SpaCy最相似的文档,而且它几乎没有用处。
这是相关的代码。
tfidf = models.TfidfModel(corpus) corpus_tfidf = tfidf[corpus] lsi = models.LsiModel(corpus, id2word=dictionary, num_topics=40) doc = preprocess(query) vec_bow = dictionary.doc2bow(doc) vec_lsi_tfidf = lsi[tfidf[vec_bow]] # convert the query to LSI space index = similarities.Similarity(corpus = corpus, num_features = len(dictionary), output_prefix = "pqr") sims = index[vec_lsi_tfidf] # perform a similarity query against the corpus most_similar = sorted(list(enumerate(sims)), key = lambda x:x[1]) for mid in most_similar[-100:]: print(mid, file_list[mid[0]])
使用gensim我已经找到了一个体面的方法,进行了一些预处理,但相似性分数仍然很低。 有没有人遇到过这样的问题,并且有一些可能有用的资源或建议?
I have a niche corpus of ~12k docs, and I want to test near-duplicate documents with similar meanings across it - think article about the same event covered by different news organisations.
I have tried gensim's Word2Vec, which gives me terrible similarity score(<0.3) even when the test document is within the corpus, and I have tried SpaCy, which gives me >5k documents with similarity > 0.9. I tested SpaCy's most similar documents, and it was mostly useless.
This is the relevant code.
tfidf = models.TfidfModel(corpus) corpus_tfidf = tfidf[corpus] lsi = models.LsiModel(corpus, id2word=dictionary, num_topics=40) doc = preprocess(query) vec_bow = dictionary.doc2bow(doc) vec_lsi_tfidf = lsi[tfidf[vec_bow]] # convert the query to LSI space index = similarities.Similarity(corpus = corpus, num_features = len(dictionary), output_prefix = "pqr") sims = index[vec_lsi_tfidf] # perform a similarity query against the corpus most_similar = sorted(list(enumerate(sims)), key = lambda x:x[1]) for mid in most_similar[-100:]: print(mid, file_list[mid[0]])
Using gensim I have found a decent approach, with some preprocessing, but the similarity score is still quite low. Has anyone faced such a problem, and are there are some resources or suggestions that could be useful?
原文:https://stackoverflow.com/questions/49767270
最满意答案
$ []是v3.6的新功能。
为了使其工作,您需要mongodb v3.6, 并将 FeatureCompatibilityVersion设置为“3.6”。
$更新数组中的单个元素。
对于它的工作,你的查询应该包含数组中元素的过滤器,例如
const query = {'_id': new ObjectID(currentPrediction._id), "predictions.status" : "FT"};
$
是第一个匹配的元素,没有过滤器就没有匹配。$[] is a new feature of v3.6.
For it to work you need mongodb v3.6, and set FeatureCompatibilityVersion to "3.6".
$ updates a single element in the array.
For it to work your query should include a filter for elements in the array, e.g.
const query = {'_id': new ObjectID(currentPrediction._id), "predictions.status" : "FT"};
The
$
refers to the first matching element, and without filter there are no matches.
相关问答
更多-
根据您的查询,它存储为整数而不是数组的事实可能并不重要。 考虑该集合: /* 1 */ { "_id" : ObjectId("56faeabd4e7309356aa1a0ba"), "arr" : [ 1, 2, 3 ] } /* 2 */ { "_id" : ObjectId("56faeac74e7309356aa1a0bb"), "arr" : 2 } 包含类型查询仍然按预期工作,例如: db.coll ...
-
Mongodb位置运算符$或$ []不适用于数组元素(Mongodb positional operators $ or $[] do not work for array elements)[2022-04-22]
$ []是v3.6的新功能。 为了使其工作,您需要mongodb v3.6, 并将 FeatureCompatibilityVersion设置为“3.6”。 $更新数组中的单个元素。 对于它的工作,你的查询应该包含数组中元素的过滤器,例如 const query = {'_id': new ObjectID(currentPrediction._id), "predictions.status" : "FT"}; $是第一个匹配的元素,没有过滤器就没有匹配。 $[] is a new feature of ... -
如何使用带过滤位置运算符和arrayFilters来应用更新(How to apply update using Filtered positional operator with arrayFilters)[2022-04-26]
这应该是: WriteResult wr = getMongoTemplate().updateMulti( new Query(where("rates.rateCardId").is(1234)), new Update().set("rates.$[item].rate", 200), new UpdateOptions() .arrayFilters( Arrays.asList( Filters.in("item.rateCardId",Arrays.asList( ... -
您可以使用mongo shell中的cursor.forEach()游标方法来实现此目的: db.organizations.find({"name" : "Paul", "a.b" : {$exists: true}}).forEach(function(doc) { array = doc.a.b; array.forEach(function(elem) { elem.lastname="no_lastname" }); db.organizatio ...
-
位移运算符(Bit shift operators)[2024-01-02]
这真是一个非常简单的面试问题。 因为您知道第一组中最多有1025个不同的整数,所以您可以使用该位数来表示在输入集中是否找到每个数字。 因此,如果您希望答案只打印一次不同的数字,那么逻辑是: 将bitset A中的所有1025位归零 对于第一组中的每个数字,在A中设置相应的位 将位集B中的所有1025位置零 对于第二组中的每个数字int,在B中设置相应的位 对于i从0到1024:如果在A和B中都设置了该位,则输出i作为答案的一部分 现在,创建一个1025位的bitset可能不会被你的语言直接支持,所以你有时需 ... -
MongoDB官方Perl驱动程序支持在使用位置($)运算符时进行更新。 以下将更新嵌入在特定文档中的数组的子文档中的字段: my $oid = MongoDB::OID->new("..."); $self->collection->update( {_id => $oid, 'grades.grade' => 85}, {'$set' => {'grade.$.new_field' => 'test'}} ); Updating while making use of the position ...
-
您的addressDetails对象没有字段streetAddress ,因此addressDetails.streetAddress返回undefined 。 在更新中使用addressDetails.address.streetAddress 。 而且,就像Joshua指出的那样,使用一个对象作为{ _id: currUserId }选择器。 所以整个功能应该是: Meteor.users.update( { _id: currentUserId }, {$addToSet: { ...
-
与哈希码有关的任何事情都应使用GetHashCode和Equals (无论是通过直接在候选值上调用它们还是通过IEqualityComparer
调用它们)。 哈希码不保证是唯一的:它们只是一个有效的初始过滤器。 如果两个对象相等,那么它们的哈希码必须相同......但是因为哈希码是相同的并不意味着它们肯定是相等的。 哈希码用于非常快速地将大量可能的匹配缩小到具有相同哈希码的非常小的候选集合。 (哈希集会记住这两个元素及其哈希码,这样就可以检查哈希码而不必每次重新计算它们。)然后,每个候选者必须用Equ ... -
您正尝试在初始化时动态地将值分配给JavaScript对象的键。 只需单独创建它,然后在以后的步骤中分配密钥。 var cursor = db.coll.find(); cursor.forEach(function(x){ if(x.arr) { x.arr.forEach(function(y,i){ if(y.field1) { var setStmt = {}; setStmt['arr.'+i+'.field1'] = 'x' + y.fie ...
-
你不能使用简单的查找查询来做这些。 解决方法 {$inc: {'products.0.quantity': -1,'products.1.quantity': -1,'products.2.quantity': -1}} 或者您可以使用聚合框架来$unwind您的数组, $match documnet,更新documnets并再次$push其$push送到数组中 You cant do these using simple find query. A workaround {$inc: {'product ...