Skip to content

Commit

Permalink
Format files with black
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivieFranklova committed Sep 18, 2024
1 parent 7d410a5 commit ac79a77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
10 changes: 6 additions & 4 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class TrainedModel:
"""

configure()
__model = SentenceTransformer("paraphrase-multilingual-mpnet-base-v2",
tokenizer_kwargs={
"clean_up_tokenization_spaces": True,
})
__model = SentenceTransformer(
"paraphrase-multilingual-mpnet-base-v2",
tokenizer_kwargs={
"clean_up_tokenization_spaces": True,
},
)

def set_module(self, model: SentenceTransformer):
"""
Expand Down
20 changes: 10 additions & 10 deletions test/test_column2Vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# MODEL = 'all-mpnet-base-v2' # bert-base-nli-mean-tokens
MODEL = 'bert-base-nli-mean-tokens' #
THIS_DIR = os.path.dirname(os.path.abspath(__file__))

TRANSFORMER = SentenceTransformer(MODEL)

def vectors_are_same(vec1, vec2):
for i, j in zip(vec1, vec2):
Expand All @@ -33,7 +33,7 @@ def get_vectors(function, data):
count = 1
for key in data:
# print("Processing column: " + key + " " + str(round((count / len(data)) * 100, 2)) + "%")
result[key] = function(data[key], SentenceTransformer(MODEL), key)
result[key] = function(data[key], TRANSFORMER, key)
count += 1
end = time.time()
print(f"ELAPSED TIME :{end - start}")
Expand All @@ -60,7 +60,7 @@ def get_data(files):
class TestSimilarityOfVectors(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.model = SentenceTransformer(MODEL)
cls.model = TRANSFORMER
file_m2 = os.path.join(THIS_DIR, os.pardir, 'data/netflix_titles.csv')
# make an array of all the files
files = [file_m2]
Expand All @@ -76,7 +76,7 @@ def setUpClass(cls):
stop += 1

def test_column2vec_as_sentence(self):
model = SentenceTransformer(MODEL)
model = TRANSFORMER
self.assertTrue(
vectors_are_same(column2vec_as_sentence(self.first, model, "a"),
column2vec_as_sentence(self.first, self.model, "b")))
Expand All @@ -87,7 +87,7 @@ def test_column2vec_as_sentence(self):
column2vec_as_sentence(self.third, self.model, "f")))

def test_column2vec_as_sentence_clean(self):
model = SentenceTransformer(MODEL)
model = TRANSFORMER
self.assertTrue(vectors_are_same(column2vec_as_sentence_clean(self.first, model, "g"),
column2vec_as_sentence_clean(self.first, self.model, "h")))
self.assertTrue(vectors_are_same(column2vec_as_sentence_clean(self.second, model, "i"),
Expand All @@ -96,7 +96,7 @@ def test_column2vec_as_sentence_clean(self):
column2vec_as_sentence_clean(self.third, self.model, "l")))

def test_column2vec_as_sentence_clean_uniq(self):
model = SentenceTransformer(MODEL)
model = TRANSFORMER
self.assertTrue(vectors_are_same(column2vec_as_sentence_clean_uniq(self.first, model, "m"),
column2vec_as_sentence_clean_uniq(self.first, self.model, "n")))
self.assertTrue(vectors_are_same(column2vec_as_sentence_clean_uniq(self.second, model, "o"),
Expand All @@ -105,14 +105,14 @@ def test_column2vec_as_sentence_clean_uniq(self):
column2vec_as_sentence_clean_uniq(self.third, self.model, "r")))

def test_column2vec_avg(self):
model = SentenceTransformer(MODEL)
model = TRANSFORMER
self.assertTrue(vectors_are_same(column2vec_avg(self.first, model, "v"),
column2vec_avg(self.first, self.model, "s")))
# self.assertTrue(vectors_are_same(column2vec_avg(self.second, model), column2vec_avg(self.second, self.model)))
# self.assertTrue(vectors_are_same(column2vec_avg(self.third, model), column2vec_avg(self.third, self.model)))

def test_column2vec_weighted_avg(self):
model = SentenceTransformer(MODEL)
model = TRANSFORMER
self.assertTrue(vectors_are_same(column2vec_weighted_avg(self.first, model, "u"),
column2vec_weighted_avg(self.first, self.model, "w")))
# self.assertTrue(vectors_are_same(column2vec_weighted_avg(self.second, model),
Expand All @@ -121,12 +121,12 @@ def test_column2vec_weighted_avg(self):
# column2vec_weighted_avg(self.third, self.model)))

def test_column2vec_sum(self):
model = SentenceTransformer(MODEL)
model = TRANSFORMER
self.assertTrue(vectors_are_same(column2vec_sum(self.first, model, "x"),
column2vec_sum(self.first, self.model, "y")))

def test_column2vec_weighted_sum(self):
model = SentenceTransformer(MODEL)
model = TRANSFORMER
self.assertTrue(vectors_are_same(column2vec_weighted_sum(self.first, model, "z"),
column2vec_weighted_sum(self.first, self.model, "ab")))

Expand Down

0 comments on commit ac79a77

Please sign in to comment.