Skip to content

Instantly share code, notes, and snippets.

View ahmetalsan's full-sized avatar
🎯
Focusing

Ahmet Alsan ahmetalsan

🎯
Focusing
View GitHub Profile
@ahmetalsan
ahmetalsan / cosine.py
Last active May 29, 2024 23:44
python cosine similarity algorithm between two strings
import re
import math
from collections import Counter
def get_cosine(vec1, vec2):
intersection = set(vec1.keys()) & set(vec2.keys())
numerator = sum([vec1[x] * vec2[x] for x in intersection])
sum1 = sum([vec1[x]**2 for x in vec1.keys()])