本文整理汇总了Python中spacy.tokens.Doc.similarity方法的典型用法代码示例。如果您正苦于以下问题:Python Doc.similarity方法的具体用法?Python Doc.similarity怎么用?Python Doc.similarity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spacy.tokens.Doc
的用法示例。
在下文中一共展示了Doc.similarity方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_doc_api_similarity_match
# 需要导入模块: from spacy.tokens import Doc [as 别名]
# 或者: from spacy.tokens.Doc import similarity [as 别名]
def test_doc_api_similarity_match():
doc = Doc(Vocab(), words=["a"])
assert doc.similarity(doc[0]) == 1.0
assert doc.similarity(doc.vocab["a"]) == 1.0
doc2 = Doc(doc.vocab, words=["a", "b", "c"])
with pytest.warns(ModelsWarning):
assert doc.similarity(doc2[:1]) == 1.0
assert doc.similarity(doc2) == 0.0
示例2: test_vectors_doc_doc_similarity
# 需要导入模块: from spacy.tokens import Doc [as 别名]
# 或者: from spacy.tokens.Doc import similarity [as 别名]
def test_vectors_doc_doc_similarity(vocab, text1, text2):
doc1 = Doc(vocab, words=text1)
doc2 = Doc(vocab, words=text2)
assert doc1.similarity(doc2) == doc2.similarity(doc1)
assert -1.0 < doc1.similarity(doc2) < 1.0
示例3: test_vectors_span_doc_similarity
# 需要导入模块: from spacy.tokens import Doc [as 别名]
# 或者: from spacy.tokens.Doc import similarity [as 别名]
def test_vectors_span_doc_similarity(vocab, text):
doc = Doc(vocab, words=text)
with pytest.warns(UserWarning):
assert doc[0:2].similarity(doc) == doc.similarity(doc[0:2])
assert -1.0 < doc[0:2].similarity(doc) < 1.0
示例4: test_vectors_lexeme_doc_similarity
# 需要导入模块: from spacy.tokens import Doc [as 别名]
# 或者: from spacy.tokens.Doc import similarity [as 别名]
def test_vectors_lexeme_doc_similarity(vocab, text):
doc = Doc(vocab, words=text)
lex = vocab[text[0]]
assert lex.similarity(doc) == doc.similarity(lex)
assert -1.0 < lex.similarity(doc) < 1.0
示例5: test_vectors_lexeme_span_similarity
# 需要导入模块: from spacy.tokens import Doc [as 别名]
# 或者: from spacy.tokens.Doc import similarity [as 别名]
def test_vectors_lexeme_span_similarity(vocab, text):
doc = Doc(vocab, words=text)
lex = vocab[text[0]]
assert lex.similarity(doc[1:3]) == doc[1:3].similarity(lex)
assert -1.0 < doc.similarity(doc[1:3]) < 1.0
示例6: test_vectors_token_doc_similarity
# 需要导入模块: from spacy.tokens import Doc [as 别名]
# 或者: from spacy.tokens.Doc import similarity [as 别名]
def test_vectors_token_doc_similarity(vocab, text):
doc = Doc(vocab, words=text)
assert doc[0].similarity(doc) == doc.similarity(doc[0])
assert -1.0 < doc[0].similarity(doc) < 1.0