Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -362,8 +362,8 @@ model_ids = [
|
|
| 362 |
"sentence-transformers/distiluse-base-multilingual-cased-v2",
|
| 363 |
"Alibaba-NLP/gte-multilingual-base",
|
| 364 |
"sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
|
|
|
|
| 365 |
"BAAI/bge-reranker-v2-m3",
|
| 366 |
-
"jinaai/jina-reranker-v2-base-multilingual"
|
| 367 |
]
|
| 368 |
# model_id = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
|
| 369 |
# model_id = "Alibaba-NLP/gte-multilingual-base"
|
|
@@ -373,20 +373,28 @@ model_ids = [
|
|
| 373 |
# model_id = "sentence-transformers/distiluse-base-multilingual-cased-v2"
|
| 374 |
|
| 375 |
model_id = model_ids[-1]
|
|
|
|
|
|
|
| 376 |
|
| 377 |
-
|
| 378 |
-
model
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
|
| 387 |
-
# codes_emb = model.encode([x[6:] for x in codes])
|
| 388 |
-
codes_emb = model.encode([x["examples"] for x in examples])#.mean(axis=1)
|
| 389 |
-
# codes_emb = np.mean([model.encode(x["examples"]) for x in examples], axis=1)
|
| 390 |
# for x in examples:
|
| 391 |
# codes_emb.append(model.encode(x["examples"]))
|
| 392 |
# codes_emb = np.mean(codes_emb, axis=1)
|
|
@@ -690,10 +698,11 @@ def reload(chosen_model_id):
|
|
| 690 |
global codes_emb
|
| 691 |
|
| 692 |
if chosen_model_id != model_id:
|
| 693 |
-
|
| 694 |
-
|
|
|
|
| 695 |
# codes_emb = model.encode([x[6:] for x in codes])
|
| 696 |
-
codes_emb = model.encode([x["examples"] for x in examples])#.mean(axis=1)
|
| 697 |
# codes_emb = np.mean([model.encode(x["examples"]) for x in examples], axis=1)
|
| 698 |
return f"Model {chosen_model_id} has been succesfully loaded!"
|
| 699 |
return f"Model {chosen_model_id} is ready!"
|
|
|
|
| 362 |
"sentence-transformers/distiluse-base-multilingual-cased-v2",
|
| 363 |
"Alibaba-NLP/gte-multilingual-base",
|
| 364 |
"sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
|
| 365 |
+
"jinaai/jina-reranker-v2-base-multilingual",
|
| 366 |
"BAAI/bge-reranker-v2-m3",
|
|
|
|
| 367 |
]
|
| 368 |
# model_id = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
|
| 369 |
# model_id = "Alibaba-NLP/gte-multilingual-base"
|
|
|
|
| 373 |
# model_id = "sentence-transformers/distiluse-base-multilingual-cased-v2"
|
| 374 |
|
| 375 |
model_id = model_ids[-1]
|
| 376 |
+
model = None
|
| 377 |
+
codes_emb = None
|
| 378 |
|
| 379 |
+
def load_model(model_id):
|
| 380 |
+
global model
|
| 381 |
+
global codes_emb
|
| 382 |
+
if model_id in model_ids[-2:]:
|
| 383 |
+
model = CrossEncoder(
|
| 384 |
+
# "jinaai/jina-reranker-v2-base-multilingual",
|
| 385 |
+
# "BAAI/bge-reranker-v2-m3",
|
| 386 |
+
model_id,
|
| 387 |
+
automodel_args={"torch_dtype": "auto"},
|
| 388 |
+
trust_remote_code=True,
|
| 389 |
+
)
|
| 390 |
+
else:
|
| 391 |
+
model = SentenceTransformer(model_id, trust_remote_code=True)
|
| 392 |
+
# codes_emb = model.encode([x[6:] for x in codes])
|
| 393 |
+
codes_emb = model.encode([x["examples"] for x in examples])#.mean(axis=1)
|
| 394 |
+
# codes_emb = np.mean([model.encode(x["examples"]) for x in examples], axis=1)
|
| 395 |
+
|
| 396 |
+
load_model(model_id)
|
| 397 |
|
|
|
|
|
|
|
|
|
|
| 398 |
# for x in examples:
|
| 399 |
# codes_emb.append(model.encode(x["examples"]))
|
| 400 |
# codes_emb = np.mean(codes_emb, axis=1)
|
|
|
|
| 698 |
global codes_emb
|
| 699 |
|
| 700 |
if chosen_model_id != model_id:
|
| 701 |
+
load_model(model_id)
|
| 702 |
+
# model = SentenceTransformer(chosen_model_id, trust_remote_code=True)
|
| 703 |
+
# model_id = chosen_model_id
|
| 704 |
# codes_emb = model.encode([x[6:] for x in codes])
|
| 705 |
+
# codes_emb = model.encode([x["examples"] for x in examples])#.mean(axis=1)
|
| 706 |
# codes_emb = np.mean([model.encode(x["examples"]) for x in examples], axis=1)
|
| 707 |
return f"Model {chosen_model_id} has been succesfully loaded!"
|
| 708 |
return f"Model {chosen_model_id} is ready!"
|