Spaces:
Sleeping
Sleeping
Create embeddings.py
Browse files- embeddings.py +26 -0
embeddings.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Requires transformers>=4.51.0
|
| 2 |
+
import torch
|
| 3 |
+
from sentence_transformers import SentenceTransformer
|
| 4 |
+
|
| 5 |
+
model = SentenceTransformer("Qwen/Qwen3-Embedding-0.6B")
|
| 6 |
+
|
| 7 |
+
# queries = "hey"
|
| 8 |
+
# documents = [
|
| 9 |
+
# "The capital of China is Beijing.",
|
| 10 |
+
# "Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun.",
|
| 11 |
+
# ]
|
| 12 |
+
|
| 13 |
+
def rank_resume(job_description, resumes):
|
| 14 |
+
task = "Given a resume, retrieve relevant job description that is suitable for the resume"
|
| 15 |
+
|
| 16 |
+
queries = resumes
|
| 17 |
+
documents = job_description
|
| 18 |
+
|
| 19 |
+
print("[QUERIES]", query)
|
| 20 |
+
print("[DOCUMENTS]", documents)
|
| 21 |
+
|
| 22 |
+
query_embeddings = model.encode(queries, prompt=task)
|
| 23 |
+
document_embeddings = model.encode(documents)
|
| 24 |
+
similarity = model.similarity(query_embeddings, document_embeddings)
|
| 25 |
+
|
| 26 |
+
return documents, similarity[0].tolist()
|