Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,15 +4,16 @@ from sentence_transformers import SentenceTransformer
|
|
| 4 |
texts1 = ["胡子长得太快怎么办?", "在香港哪里买手表好"]
|
| 5 |
texts2 = ["胡子长得快怎么办?", "怎样使胡子不浓密!", "香港买手表哪里好", "在杭州手机到哪里买"]
|
| 6 |
|
|
|
|
|
|
|
| 7 |
model = SentenceTransformer('DMetaSoul/Dmeta-embedding')
|
| 8 |
embs1 = model.encode(texts1, normalize_embeddings=True)
|
| 9 |
embs2 = model.encode(texts2, normalize_embeddings=True)
|
| 10 |
|
| 11 |
similarity = embs1 @ embs2.T
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
print(similarity)
|
| 16 |
|
| 17 |
for i in range(len(texts1)):
|
| 18 |
scores = []
|
|
@@ -21,8 +22,15 @@ for i in range(len(texts1)):
|
|
| 21 |
scores = sorted(scores, key=lambda x:x[1], reverse=True)
|
| 22 |
|
| 23 |
print(f"查询文本:{texts1[i]}")
|
|
|
|
|
|
|
| 24 |
for text2, score in scores:
|
| 25 |
print(f"相似文本:{text2},打分:{score}")
|
|
|
|
|
|
|
| 26 |
print()
|
| 27 |
|
| 28 |
-
gr.load("models/DMetaSoul/Dmeta-embedding-zh").launch()
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
texts1 = ["胡子长得太快怎么办?", "在香港哪里买手表好"]
|
| 5 |
texts2 = ["胡子长得快怎么办?", "怎样使胡子不浓密!", "香港买手表哪里好", "在杭州手机到哪里买"]
|
| 6 |
|
| 7 |
+
demo_text = ""
|
| 8 |
+
|
| 9 |
model = SentenceTransformer('DMetaSoul/Dmeta-embedding')
|
| 10 |
embs1 = model.encode(texts1, normalize_embeddings=True)
|
| 11 |
embs2 = model.encode(texts2, normalize_embeddings=True)
|
| 12 |
|
| 13 |
similarity = embs1 @ embs2.T
|
| 14 |
|
| 15 |
+
demo_text += similarity
|
| 16 |
+
demo_text += "\n"
|
|
|
|
| 17 |
|
| 18 |
for i in range(len(texts1)):
|
| 19 |
scores = []
|
|
|
|
| 22 |
scores = sorted(scores, key=lambda x:x[1], reverse=True)
|
| 23 |
|
| 24 |
print(f"查询文本:{texts1[i]}")
|
| 25 |
+
demo_text += f"查询文本:{texts1[i]}"
|
| 26 |
+
demo_text += "\n"
|
| 27 |
for text2, score in scores:
|
| 28 |
print(f"相似文本:{text2},打分:{score}")
|
| 29 |
+
demo_text += f"相似文本:{text2},打分:{score}"
|
| 30 |
+
demo_text += "\n"
|
| 31 |
print()
|
| 32 |
|
| 33 |
+
# gr.load("models/DMetaSoul/Dmeta-embedding-zh").launch()
|
| 34 |
+
with gr.Row():
|
| 35 |
+
gr.Markdown(demo_text)
|
| 36 |
+
|