yasserrmd commited on
Commit
8773065
1 Parent(s): 45d8c04

Update career_data.py

Browse files
Files changed (1) hide show
  1. career_data.py +14 -33
career_data.py CHANGED
@@ -1,50 +1,31 @@
1
- from transformers import AutoModel, AutoTokenizer
 
2
  import torch
3
 
4
- # Load model and tokenizer
5
- model_name = "minishlab/M2V_base_output"
6
- tokenizer = AutoTokenizer.from_pretrained(model_name)
7
- model = AutoModel.from_pretrained(model_name)
8
 
9
- # Career options with precomputed skills and interests
10
- career_options = {
11
- "Software Engineer": {
12
- "skills": "programming, problem-solving",
13
- "interests": "technology, innovation"
14
- },
15
- "Graphic Designer": {
16
- "skills": "design, creativity",
17
- "interests": "art, visual communication"
18
- },
19
- "Project Manager": {
20
- "skills": "management, organization",
21
- "interests": "leadership, strategy"
22
- },
23
- # Add more careers as needed
24
- }
25
-
26
- # Generate embeddings for career options
27
- def get_embedding(text):
28
- inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
29
- with torch.no_grad():
30
- embedding = model(**inputs).last_hidden_state.mean(dim=1).squeeze()
31
- return embedding
32
 
 
33
  career_embeddings = {}
34
  for career, attributes in career_options.items():
35
  combined_text = attributes["skills"] + ", " + attributes["interests"]
36
- career_embeddings[career] = get_embedding(combined_text)
37
 
38
- # Function to recommend careers based on skills and interests
39
  def get_career_recommendations(skills: str, interests: str):
40
  user_input = skills + ", " + interests
41
- user_embedding = get_embedding(user_input)
42
-
43
  recommendations = []
44
  for career, career_embedding in career_embeddings.items():
45
- similarity = torch.cosine_similarity(user_embedding, career_embedding, dim=0).item()
46
  recommendations.append((career, similarity))
47
 
 
48
  recommendations.sort(key=lambda x: x[1], reverse=True)
49
 
50
  return [f"{career} (Similarity: {similarity:.2f})" for career, similarity in recommendations[:5]]
 
1
+ import json
2
+ from model2vec import StaticModel
3
  import torch
4
 
5
+ # Load the Model2Vec pretrained model
6
+ model = StaticModel.from_pretrained("minishlab/M2V_base_output")
 
 
7
 
8
+ # Load career options from JSON file
9
+ with open("career_options.json", "r") as file:
10
+ career_options = json.load(file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ # Precompute embeddings for career options
13
  career_embeddings = {}
14
  for career, attributes in career_options.items():
15
  combined_text = attributes["skills"] + ", " + attributes["interests"]
16
+ career_embeddings[career] = model.encode([combined_text])[0]
17
 
18
+ # Function to generate career recommendations
19
  def get_career_recommendations(skills: str, interests: str):
20
  user_input = skills + ", " + interests
21
+ user_embedding = model.encode([user_input])[0]
22
+
23
  recommendations = []
24
  for career, career_embedding in career_embeddings.items():
25
+ similarity = torch.cosine_similarity(torch.tensor(user_embedding), torch.tensor(career_embedding), dim=0).item()
26
  recommendations.append((career, similarity))
27
 
28
+ # Sort by similarity score
29
  recommendations.sort(key=lambda x: x[1], reverse=True)
30
 
31
  return [f"{career} (Similarity: {similarity:.2f})" for career, similarity in recommendations[:5]]