zlf18 commited on
Commit
e7d22d9
·
verified ·
1 Parent(s): 64702cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -41,7 +41,8 @@ SKILL_WHITELIST = {
41
  'strategy', 'stakeholder management', 'risk management', 'compliance', 'aml', 'kyc', 'reinsurance', 'finance',
42
  'financial modeling', 'financial analysis', 'due diligence', 'sourcing', 'procurement', 'negotiation', 'supply chain',
43
  'business analysis', 'business intelligence', 'presentations', 'public speaking', 'time management', 'critical thinking',
44
- 'design thinking', 'innovation', 'adaptability', 'supervisory', 'pmp', 'cpsm', 'cips', 'microsoft office',
 
45
  # Soft & Other
46
  'leadership', 'stakeholder communication', 'client communication', 'teamwork', 'collaboration', 'problem solving',
47
  'ui/ux design', 'figma', 'sketch', 'adobe xd', 'graphic design', 'autocad', 'solidworks', 'sales', 'marketing',
@@ -154,11 +155,12 @@ def score_jobs_by_skills(user_skills: list[str], df_to_rank: pd.DataFrame) -> pd
154
  job_skill_embeddings = model.encode(all_job_skills, convert_to_tensor=True)
155
  similarity_matrix = util.cos_sim(user_skill_embeddings, job_skill_embeddings)
156
 
157
- def calculate_averaged_semantic_match(row):
158
  job_skills_list = row.get('Skills', [])
159
  if not job_skills_list:
160
  return 0.0
161
-
 
162
  sum_of_max_similarities = 0.0
163
  for job_skill in job_skills_list:
164
  try:
@@ -168,15 +170,18 @@ def score_jobs_by_skills(user_skills: list[str], df_to_rank: pd.DataFrame) -> pd
168
  except (ValueError, IndexError):
169
  continue
170
 
171
- total_required = len(job_skills_list)
172
- return sum_of_max_similarities / total_required if total_required > 0 else 0.0
 
 
 
 
 
173
 
174
- ranked_df['Skill Match Score'] = ranked_df.apply(calculate_averaged_semantic_match, axis=1)
175
 
176
- # --- ADJUSTED: New 80/20 weighting for the blended Final Score ---
177
  ranked_df['Final Score'] = (0.8 * ranked_df['Similarity Score']) + (0.2 * ranked_df['Skill Match Score'])
178
 
179
- # Sort by the new blended score
180
  ranked_df = ranked_df.sort_values(by='Final Score', ascending=False).reset_index(drop=True)
181
  return ranked_df.set_index('Job ID', drop=False).rename_axis(None)
182
 
@@ -376,8 +381,12 @@ def on_select_job(job_id, skills_text):
376
  similarity_matrix = util.cos_sim(user_skill_embeddings, job_skill_embeddings)
377
 
378
  sum_of_max_similarities = torch.sum(torch.max(similarity_matrix, dim=0).values)
379
- score_val = (sum_of_max_similarities / len(job_skills)).item() if len(job_skills) > 0 else 0
380
 
 
 
 
 
381
  matched_job_skills_mask = torch.any(similarity_matrix > 0.58, dim=0)
382
  all_missing_skills = [skill for i, skill in enumerate(job_skills) if not matched_job_skills_mask[i]]
383
 
 
41
  'strategy', 'stakeholder management', 'risk management', 'compliance', 'aml', 'kyc', 'reinsurance', 'finance',
42
  'financial modeling', 'financial analysis', 'due diligence', 'sourcing', 'procurement', 'negotiation', 'supply chain',
43
  'business analysis', 'business intelligence', 'presentations', 'public speaking', 'time management', 'critical thinking',
44
+ 'design thinking', 'innovation', 'adaptability', 'supervisory', 'pmp', 'cpsm', 'cips', 'microsoft office', 'communication',
45
+ 'organizational skills',
46
  # Soft & Other
47
  'leadership', 'stakeholder communication', 'client communication', 'teamwork', 'collaboration', 'problem solving',
48
  'ui/ux design', 'figma', 'sketch', 'adobe xd', 'graphic design', 'autocad', 'solidworks', 'sales', 'marketing',
 
155
  job_skill_embeddings = model.encode(all_job_skills, convert_to_tensor=True)
156
  similarity_matrix = util.cos_sim(user_skill_embeddings, job_skill_embeddings)
157
 
158
+ def calculate_confidence_adjusted_score(row):
159
  job_skills_list = row.get('Skills', [])
160
  if not job_skills_list:
161
  return 0.0
162
+
163
+ total_required = len(job_skills_list)
164
  sum_of_max_similarities = 0.0
165
  for job_skill in job_skills_list:
166
  try:
 
170
  except (ValueError, IndexError):
171
  continue
172
 
173
+ avg_score = sum_of_max_similarities / total_required if total_required > 0 else 0.0
174
+
175
+ # --- NEW: Confidence Factor ---
176
+ # This penalizes scores from jobs with very few extracted skills.
177
+ skill_count_factor = min(1.0, total_required / 5.0)
178
+
179
+ return avg_score * skill_count_factor
180
 
181
+ ranked_df['Skill Match Score'] = ranked_df.apply(calculate_confidence_adjusted_score, axis=1)
182
 
 
183
  ranked_df['Final Score'] = (0.8 * ranked_df['Similarity Score']) + (0.2 * ranked_df['Skill Match Score'])
184
 
 
185
  ranked_df = ranked_df.sort_values(by='Final Score', ascending=False).reset_index(drop=True)
186
  return ranked_df.set_index('Job ID', drop=False).rename_axis(None)
187
 
 
381
  similarity_matrix = util.cos_sim(user_skill_embeddings, job_skill_embeddings)
382
 
383
  sum_of_max_similarities = torch.sum(torch.max(similarity_matrix, dim=0).values)
384
+ avg_score = (sum_of_max_similarities / len(job_skills)).item() if len(job_skills) > 0 else 0
385
 
386
+ # Apply the same confidence factor here for consistency
387
+ skill_count_factor = min(1.0, len(job_skills) / 5.0)
388
+ score_val = avg_score * skill_count_factor
389
+
390
  matched_job_skills_mask = torch.any(similarity_matrix > 0.58, dim=0)
391
  all_missing_skills = [skill for i, skill in enumerate(job_skills) if not matched_job_skills_mask[i]]
392