Canstralian commited on
Commit
27745fe
·
verified ·
1 Parent(s): a106517

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -1,6 +1,26 @@
1
- import gradio as gr
2
- from datasets import load_dataset
 
3
 
4
- ds = load_dataset("b-mc2/sql-create-context")
 
5
 
6
- gr.load("models/sentence-transformers/all-MiniLM-L6-v2").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sentence_transformers import SentenceTransformer
2
+ from sklearn.metrics.pairwise import cosine_similarity
3
+ import numpy as np
4
 
5
+ # Load the model
6
+ model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
7
 
8
+ # Define your sentences
9
+ sentences = [
10
+ "That is a happy person",
11
+ "That is a happy dog",
12
+ "That is a very happy person",
13
+ "Today is a sunny day"
14
+ ]
15
+
16
+ # Encode the sentences to get their embeddings
17
+ embeddings = model.encode(sentences)
18
+
19
+ # Compute the cosine similarity matrix
20
+ similarities = cosine_similarity(embeddings)
21
+
22
+ # Print the shape of the similarity matrix
23
+ print(similarities.shape) # Output: (4, 4)
24
+
25
+ # Optionally, print the similarity matrix
26
+ print(similarities)