mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-11 04:08:09 +03:00
Add get_cosine util function
This commit is contained in:
parent
51ef75f629
commit
bd20ec0a6a
|
@ -4,6 +4,8 @@ from __future__ import unicode_literals
|
|||
from ..tokens import Doc
|
||||
from ..attrs import ORTH, POS, HEAD, DEP
|
||||
|
||||
import numpy
|
||||
|
||||
|
||||
def get_doc(vocab, words=[], pos=None, heads=None, deps=None, tags=None, ents=None):
|
||||
"""Create Doc object from given vocab, words and annotations."""
|
||||
|
@ -36,3 +38,8 @@ def apply_transition_sequence(parser, doc, sequence):
|
|||
with parser.step_through(doc) as stepwise:
|
||||
for transition in sequence:
|
||||
stepwise.transition(transition)
|
||||
|
||||
|
||||
def get_cosine(vec1, vec2):
|
||||
"""Get cosine for two given vectors"""
|
||||
return numpy.dot(vec1, vec2) / (numpy.linalg.norm(vec1) * numpy.linalg.norm(vec2))
|
||||
|
|
Loading…
Reference in New Issue
Block a user