-
Notifications
You must be signed in to change notification settings - Fork 0
/
BetaModelV1.4.py
94 lines (57 loc) · 4.81 KB
/
BetaModelV1.4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from sentence_transformers import SentenceTransformer
from scipy.spatial.distance import cosine
model = SentenceTransformer('distilbert-base-nli-stsb-mean-tokens')
def similarity_score(embedding1, embedding2):
return 1 - cosine(embedding1, embedding2)
def compare_strings_transformer(string1, string2, model):
embeddings = model.encode([string1, string2])
similarity = similarity_score(embeddings[0], embeddings[1])
score = round(similarity * 10, 2)
return score
string1 = "A database management system (or DBMS) is essentially nothing more than a computerized data-keeping system. Users of the system are given facilities to perform several kinds of operations on such a system for either manipulation of the data in the database or the management of the database structure itself."
string2 = "A database management system (or DBMS) is essentially nothing more than a computerized data-keeping system. Users of the system are given facilities to perform several kinds of operations on such a system for either manipulation of the data in the database or the management of the database structure itself."
score = compare_strings_transformer(string1, string2, model)
print(f"Similarity score: {score}/10")
from sentence_transformers import SentenceTransformer
from scipy.spatial.distance import cosine
model = SentenceTransformer('roberta-base-nli-stsb-mean-tokens')
def similarity_score(embedding1, embedding2):
return 1 - cosine(embedding1, embedding2)
def compare_strings_transformer(string1, string2, model):
embeddings = model.encode([string1, string2])
similarity = similarity_score(embeddings[0], embeddings[1])
score = round(similarity * 10, 2)
return score
string1 = "A database management system (or DBMS) is essentially nothing more than a computerized data-keeping system. Users of the system are given facilities to perform several kinds of operations on such a system for either manipulation of the data in the database or the management of the database structure itself."
string2 = "A database management system (or DBMS) is essentially nothing more than a computerized data-keeping system. Users of the system are given facilities to perform several kinds of operations on such a system for either manipulation of the data in the database or the management of the database structure itself."
score = compare_strings_transformer(string1, string2, model)
print(f"Similarity score: {score}/10")
from sentence_transformers import SentenceTransformer
from scipy.spatial.distance import cosine
model = SentenceTransformer('paraphrase-xlm-r-multilingual-v1')
def similarity_score(embedding1, embedding2):
return 1 - cosine(embedding1, embedding2)
def compare_strings_transformer(string1, string2, model):
embeddings = model.encode([string1, string2])
similarity = similarity_score(embeddings[0], embeddings[1])
score = round(similarity * 10, 2)
return score
string1 = "A database management system (or DBMS) is essentially nothing more than a computerized data-keeping system. Users of the system are given facilities to perform several kinds of operations on such a system for either manipulation of the data in the database or the management of the database structure itself."
string2 = "A database management system (or DBMS) is essentially nothing more than a computerized data-keeping system. Users of the system are given facilities to perform several kinds of operations on such a system for either manipulation of the data in the database or the management of the database structure itself."
score = compare_strings_transformer(string1, string2, model)
print(f"Similarity score: {score}/10")
from sentence_transformers import SentenceTransformer
from scipy.spatial.distance import cosine
model = SentenceTransformer('paraphrase-mpnet-base-v2')
def similarity_score(embedding1, embedding2):
return 1 - cosine(embedding1, embedding2)
def compare_strings_transformer(string1, string2, model):
embeddings = model.encode([string1, string2])
similarity = similarity_score(embeddings[0], embeddings[1])
score = round(similarity * 10, 2)
return score
string1 = "A database management system (or DBMS) is essentially nothing more than a computerized data-keeping system. Users of the system are given facilities to perform several kinds of operations on such a system for either manipulation of the data in the database or the management of the database structure itself."
string2 = "A database management system (or DBMS) is essentially nothing more than a computerized data-keeping system. Users of the system are given facilities to perform several kinds of operations on such a system for either manipulation of the data in the database or the management of the database structure itself."
score = compare_strings_transformer(string1, string2, model)
print(f"Similarity score: {score}/10")
# %%