Spaces:
Sleeping
Sleeping
Update skill_extraction.py
Browse files- skill_extraction.py +10 -7
skill_extraction.py
CHANGED
|
@@ -22,10 +22,6 @@ with open("skills_vocab.json", "r", encoding="utf-8") as f:
|
|
| 22 |
skill_embeddings = model.encode(SKILL_VOCAB, convert_to_numpy=True, normalize_embeddings=True)
|
| 23 |
|
| 24 |
def extract_skills(text, threshold=0.50):
|
| 25 |
-
"""
|
| 26 |
-
Extract skills by comparing each skill embedding to all sentence embeddings.
|
| 27 |
-
For each skill, take max similarity across sentences.
|
| 28 |
-
"""
|
| 29 |
doc = nlp(text)
|
| 30 |
sentences = [sent.text.strip() for sent in doc.sents if sent.text.strip()]
|
| 31 |
|
|
@@ -36,14 +32,21 @@ def extract_skills(text, threshold=0.50):
|
|
| 36 |
|
| 37 |
skill_confidences = {}
|
| 38 |
|
| 39 |
-
# Iterate skill-by-skill (improved recall)
|
| 40 |
for j, skill_emb in enumerate(skill_embeddings):
|
| 41 |
-
sims = np.dot(sentence_embeddings, skill_emb) # similarity
|
| 42 |
max_sim = float(np.max(sims))
|
| 43 |
|
| 44 |
if max_sim >= threshold:
|
| 45 |
skill_confidences[SKILL_VOCAB[j]] = round(max_sim, 2)
|
| 46 |
|
| 47 |
-
# Sort highest-confidence first
|
| 48 |
return sorted(skill_confidences.items(), key=lambda x: x[1], reverse=True)
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
skill_embeddings = model.encode(SKILL_VOCAB, convert_to_numpy=True, normalize_embeddings=True)
|
| 23 |
|
| 24 |
def extract_skills(text, threshold=0.50):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
doc = nlp(text)
|
| 26 |
sentences = [sent.text.strip() for sent in doc.sents if sent.text.strip()]
|
| 27 |
|
|
|
|
| 32 |
|
| 33 |
skill_confidences = {}
|
| 34 |
|
|
|
|
| 35 |
for j, skill_emb in enumerate(skill_embeddings):
|
| 36 |
+
sims = np.dot(sentence_embeddings, skill_emb) # similarity to sentences
|
| 37 |
max_sim = float(np.max(sims))
|
| 38 |
|
| 39 |
if max_sim >= threshold:
|
| 40 |
skill_confidences[SKILL_VOCAB[j]] = round(max_sim, 2)
|
| 41 |
|
|
|
|
| 42 |
return sorted(skill_confidences.items(), key=lambda x: x[1], reverse=True)
|
| 43 |
|
| 44 |
+
|
| 45 |
+
def get_skill_embedding(skill_name):
|
| 46 |
+
"""
|
| 47 |
+
Return embedding for a skill stored in SKILL_VOCAB
|
| 48 |
+
"""
|
| 49 |
+
if skill_name not in SKILL_VOCAB:
|
| 50 |
+
return None
|
| 51 |
+
idx = SKILL_VOCAB.index(skill_name)
|
| 52 |
+
return skill_embeddings[idx]
|