zayanomar5 commited on
Commit
9a4e129
·
verified ·
1 Parent(s): f7cd617

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +4 -4
main.py CHANGED
@@ -63,7 +63,7 @@ def compare():
63
 
64
  # Encode job skills
65
  job_embeddings = [model.encode(skill) for skill in jobs_skills]
66
- job_embeddings_tensor = torch.tensor(job_embeddings)
67
 
68
  # Initialize a dictionary to store similarities for each employee
69
  all_similarities = {}
@@ -71,7 +71,7 @@ def compare():
71
  for idx, employee_skills in enumerate(employees_skills):
72
  # Encode employee skills
73
  employee_embedding = model.encode(employee_skills)
74
- employee_embedding_tensor = torch.tensor(employee_embedding).unsqueeze(0)
75
 
76
  # Calculate cosine similarity
77
  similarities = cosine_similarity(employee_embedding_tensor, job_embeddings_tensor)[0]
@@ -80,8 +80,8 @@ def compare():
80
  max_similarity_index = similarities.argmax()
81
  max_similarity_job = jobs_skills[max_similarity_index]
82
 
83
- # Store similarities in the dictionary
84
- similarities_dict = {job: similarity for job, similarity in zip(jobs_skills, similarities)}
85
  all_similarities[f'employee_{idx+1}'] = {
86
  'job': max_similarity_job,
87
  'similarities': similarities_dict
 
63
 
64
  # Encode job skills
65
  job_embeddings = [model.encode(skill) for skill in jobs_skills]
66
+ job_embeddings_tensor = torch.tensor(job_embeddings, dtype=torch.float32)
67
 
68
  # Initialize a dictionary to store similarities for each employee
69
  all_similarities = {}
 
71
  for idx, employee_skills in enumerate(employees_skills):
72
  # Encode employee skills
73
  employee_embedding = model.encode(employee_skills)
74
+ employee_embedding_tensor = torch.tensor(employee_embedding, dtype=torch.float32).unsqueeze(0)
75
 
76
  # Calculate cosine similarity
77
  similarities = cosine_similarity(employee_embedding_tensor, job_embeddings_tensor)[0]
 
80
  max_similarity_index = similarities.argmax()
81
  max_similarity_job = jobs_skills[max_similarity_index]
82
 
83
+ # Convert similarities to float for JSON serialization
84
+ similarities_dict = {job: float(similarity) for job, similarity in zip(jobs_skills, similarities)}
85
  all_similarities[f'employee_{idx+1}'] = {
86
  'job': max_similarity_job,
87
  'similarities': similarities_dict