splits / subspace /symbolic.py
Eylon Caplan
Deploy app code targeting HF Storage Bucket
ddb7b62
raw
history blame contribute delete
878 Bytes
def symbolic_johnson(x, y):
"""
Classical Johnson similarity measure between two sets
:param x: list of words (strings) for the first sentence
:param y: list of words (strings) for the second sentence
:return: similarity score between two sentences
"""
if len(x) == 0 or len(y) == 0:
return 0.0
xs = set(x)
ys = set(y)
inter = xs & ys
return len(inter) / len(xs) + len(inter) / len(ys)
def symbolic_jaccard(x, y):
"""
Classical Jaccard similarity measure between two sets
:param x: list of words (strings) for the first sentence
:param y: list of words (strings) for the second sentence
:return: similarity score between two sentences
"""
if len(x) == 0 or len(y) == 0:
return 0.0
xs = set(x)
ys = set(y)
inter = xs & ys
union = xs | ys
return len(inter) / len(union)