This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --------------------------------------------------------------------- # | |
# Chunking Mechanism # | |
import numpy as np | |
from transformers import BertTokenizer, BertModel | |
from sklearn.metrics.pairwise import cosine_similarity | |
def calculate_embedding_difference(embeddings): | |
return [1 - cosine_similarity(embeddings[i].reshape(1, -1), embeddings[i + 1].reshape(1, -1))[0][0] for i in range(len(embeddings) - 1)] |