Canstralian
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -20,31 +20,30 @@ dataset_names = [
|
|
20 |
datasets = {name: load_dataset(name) for name in dataset_names}
|
21 |
|
22 |
# Load SentenceTransformer model
|
23 |
-
|
24 |
|
25 |
# Define sentences
|
26 |
sentences = [
|
27 |
"The firewall successfully blocked unauthorized access attempts.",
|
28 |
"The system detected a potential phishing attack targeting users.",
|
29 |
"Regular software updates are essential to patch known vulnerabilities.",
|
30 |
-
"Implementing multi-factor authentication enhances account security."
|
31 |
"The function returns the sum of two numbers.",
|
32 |
"A list comprehension provides a concise way to create lists.",
|
33 |
"The 'try' block is used to handle exceptions in Python.",
|
34 |
"Using 'lambda' allows for the creation of anonymous functions."
|
35 |
]
|
36 |
|
37 |
-
|
38 |
# Compute sentence embeddings
|
39 |
-
embeddings =
|
40 |
|
41 |
# Calculate cosine similarity between sentence embeddings
|
42 |
similarities = cosine_similarity(embeddings)
|
43 |
|
44 |
# Print similarity matrix shape and values
|
45 |
-
print(similarities.shape) # Expected output: (
|
46 |
print(similarities)
|
47 |
|
48 |
# Load transformer model for Seq2Seq tasks
|
49 |
tokenizer = AutoTokenizer.from_pretrained("cssupport/t5-small-awesome-text-to-sql")
|
50 |
-
|
|
|
20 |
datasets = {name: load_dataset(name) for name in dataset_names}
|
21 |
|
22 |
# Load SentenceTransformer model
|
23 |
+
sentence_model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
24 |
|
25 |
# Define sentences
|
26 |
sentences = [
|
27 |
"The firewall successfully blocked unauthorized access attempts.",
|
28 |
"The system detected a potential phishing attack targeting users.",
|
29 |
"Regular software updates are essential to patch known vulnerabilities.",
|
30 |
+
"Implementing multi-factor authentication enhances account security.",
|
31 |
"The function returns the sum of two numbers.",
|
32 |
"A list comprehension provides a concise way to create lists.",
|
33 |
"The 'try' block is used to handle exceptions in Python.",
|
34 |
"Using 'lambda' allows for the creation of anonymous functions."
|
35 |
]
|
36 |
|
|
|
37 |
# Compute sentence embeddings
|
38 |
+
embeddings = sentence_model.encode(sentences)
|
39 |
|
40 |
# Calculate cosine similarity between sentence embeddings
|
41 |
similarities = cosine_similarity(embeddings)
|
42 |
|
43 |
# Print similarity matrix shape and values
|
44 |
+
print(similarities.shape) # Expected output: (8, 8)
|
45 |
print(similarities)
|
46 |
|
47 |
# Load transformer model for Seq2Seq tasks
|
48 |
tokenizer = AutoTokenizer.from_pretrained("cssupport/t5-small-awesome-text-to-sql")
|
49 |
+
seq2seq_model = AutoModelForSeq2SeqLM.from_pretrained("cssupport/t5-small-awesome-text-to-sql")
|