Spaces:
Running
Running
zhangxiyi.amos
commited on
Commit
·
b8bd956
1
Parent(s):
21edaab
feat: 添加不同query对比
Browse files
app.py
CHANGED
@@ -13,65 +13,35 @@ model4 = SentenceTransformer("aspire/acge_text_embedding")
|
|
13 |
model5 = SentenceTransformer("intfloat/multilingual-e5-large")
|
14 |
|
15 |
@spaces.GPU
|
16 |
-
def generate(
|
17 |
-
if len(
|
18 |
-
|
19 |
-
if len(
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
]
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
input1,
|
33 |
-
input2,
|
34 |
-
]
|
35 |
-
)
|
36 |
-
score2 = cos_sim(embeddings2[0], embeddings2[1])
|
37 |
-
|
38 |
-
embeddings3 = model3.encode(
|
39 |
-
[
|
40 |
-
input1,
|
41 |
-
input2,
|
42 |
-
]
|
43 |
-
)
|
44 |
-
score3 = cos_sim(embeddings3[0], embeddings3[1])
|
45 |
-
|
46 |
-
embeddings4 = model4.encode(
|
47 |
-
[
|
48 |
-
input1,
|
49 |
-
input2,
|
50 |
-
]
|
51 |
-
)
|
52 |
-
score4 = cos_sim(embeddings4[0], embeddings4[1])
|
53 |
-
|
54 |
-
embeddings5 = model5.encode(
|
55 |
-
[
|
56 |
-
input1,
|
57 |
-
input2,
|
58 |
-
]
|
59 |
-
)
|
60 |
-
score5 = cos_sim(embeddings5[0], embeddings5[1])
|
61 |
-
|
62 |
-
return score1, score2, score3, score4, score5
|
63 |
|
64 |
gr.Interface(
|
65 |
fn=generate,
|
66 |
inputs=[
|
67 |
-
gr.Text(label="
|
68 |
-
gr.Text(label="
|
|
|
69 |
],
|
70 |
outputs=[
|
71 |
-
gr.
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
],
|
77 |
).launch()
|
|
|
13 |
model5 = SentenceTransformer("intfloat/multilingual-e5-large")
|
14 |
|
15 |
@spaces.GPU
|
16 |
+
def generate(query1, query2, source_code):
|
17 |
+
if len(query1) < 1:
|
18 |
+
query1 = "How do I access the index while iterating over a sequence with a for loop?"
|
19 |
+
if len(query2) < 1:
|
20 |
+
query2 = "get a list of all the keys in a dictionary"
|
21 |
+
if len(source_code) < 1:
|
22 |
+
source_code = "# Use the built-in enumerator\nfor idx, x in enumerate(xs):\n print(idx, x)"
|
23 |
+
|
24 |
+
results = []
|
25 |
+
for model in [model1, model2, model3, model4, model5]:
|
26 |
+
embeddings = model.encode([query1, query2, source_code])
|
27 |
+
score1 = cos_sim(embeddings[0], embeddings[2])
|
28 |
+
score2 = cos_sim(embeddings[1], embeddings[2])
|
29 |
+
results.append((float(score1), float(score2)))
|
30 |
+
|
31 |
+
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
gr.Interface(
|
34 |
fn=generate,
|
35 |
inputs=[
|
36 |
+
gr.Text(label="query1", placeholder="How do I access the index while iterating over a sequence with a for loop?"),
|
37 |
+
gr.Text(label="query2", placeholder="get a list of all the keys in a dictionary"),
|
38 |
+
gr.Text(label="code", placeholder="# Use the built-in enumerator\nfor idx, x in enumerate(xs):\n print(idx, x)"),
|
39 |
],
|
40 |
outputs=[
|
41 |
+
gr.Dataframe(
|
42 |
+
headers=["Query1 Score", "Query2 Score"],
|
43 |
+
label="Similarity Scores",
|
44 |
+
row_labels=["jinaai/jina-embeddings-v2-base-code", "jinaai/jina-embeddings-v2-base-en", "jinaai/jina-embeddings-v2-base-zh", "aspire/acge_text_embedding", "intfloat/multilingual-e5-large"]
|
45 |
+
)
|
46 |
],
|
47 |
).launch()
|