NithyaAla commited on
Commit
3f04f41
·
verified ·
1 Parent(s): 8d823fc

Update skill_extraction.py

Browse files
Files changed (1) hide show
  1. skill_extraction.py +19 -4
skill_extraction.py CHANGED
@@ -27,6 +27,10 @@ skill_embeddings = model.encode(SKILL_VOCAB, convert_to_numpy=True, normalize_em
27
  SKILL_TO_EMB = {skill: emb for skill, emb in zip(SKILL_VOCAB, skill_embeddings)}
28
 
29
  def extract_skills(text, threshold=0.50):
 
 
 
 
30
  doc = nlp(text)
31
  sentences = [sent.text.strip() for sent in doc.sents if sent.text.strip()]
32
 
@@ -35,14 +39,25 @@ def extract_skills(text, threshold=0.50):
35
 
36
  sentence_embeddings = model.encode(sentences, convert_to_numpy=True, normalize_embeddings=True)
37
  skill_confidences = {}
 
38
 
 
39
  for j, skill_emb in enumerate(skill_embeddings):
40
- sims = np.dot(sentence_embeddings, skill_emb)
41
- max_sim = float(np.max(sims))
 
 
42
  if max_sim >= threshold:
43
- skill_confidences[SKILL_VOCAB[j]] = round(max_sim, 2)
 
 
 
 
 
 
 
 
44
 
45
- return sorted(skill_confidences.items(), key=lambda x: x[1], reverse=True)
46
 
47
  # --- NEW FUNCTION ---
48
  def get_skill_embedding(skill_name):
 
27
  SKILL_TO_EMB = {skill: emb for skill, emb in zip(SKILL_VOCAB, skill_embeddings)}
28
 
29
  def extract_skills(text, threshold=0.50):
30
+ """
31
+ Extract skills from text.
32
+ Returns list of (skill, confidence, evidence_sentences)
33
+ """
34
  doc = nlp(text)
35
  sentences = [sent.text.strip() for sent in doc.sents if sent.text.strip()]
36
 
 
39
 
40
  sentence_embeddings = model.encode(sentences, convert_to_numpy=True, normalize_embeddings=True)
41
  skill_confidences = {}
42
+ skill_evidence = {}
43
 
44
+ # Iterate skill-by-skill
45
  for j, skill_emb in enumerate(skill_embeddings):
46
+ sims = np.dot(sentence_embeddings, skill_emb) # similarity across sentences
47
+ max_sim_idx = int(np.argmax(sims))
48
+ max_sim = float(sims[max_sim_idx])
49
+
50
  if max_sim >= threshold:
51
+ skill = SKILL_VOCAB[j]
52
+ skill_confidences[skill] = round(max_sim, 2)
53
+ # Take the sentence with highest similarity as evidence
54
+ skill_evidence[skill] = sentences[max_sim_idx]
55
+
56
+ # Return sorted list of (skill, confidence, evidence)
57
+ results = [(skill, skill_confidences[skill], skill_evidence[skill]) for skill in skill_confidences]
58
+ results.sort(key=lambda x: x[1], reverse=True)
59
+ return results
60
 
 
61
 
62
  # --- NEW FUNCTION ---
63
  def get_skill_embedding(skill_name):