CareerPath / career_data.py
yasserrmd's picture
Update career_data.py
c6e7c0e verified
raw
history blame
1.82 kB
from transformers import AutoModel, AutoTokenizer
import torch
# Load model and tokenizer
model_name = "minishlab/M2V_base_output"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(model_name)
# Career options with precomputed skills and interests
career_options = {
"Software Engineer": {
"skills": "programming, problem-solving",
"interests": "technology, innovation"
},
"Graphic Designer": {
"skills": "design, creativity",
"interests": "art, visual communication"
},
"Project Manager": {
"skills": "management, organization",
"interests": "leadership, strategy"
},
# Add more careers as needed
}
# Generate embeddings for career options
def get_embedding(text):
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
with torch.no_grad():
embedding = model(**inputs).last_hidden_state.mean(dim=1).squeeze()
return embedding
career_embeddings = {}
for career, attributes in career_options.items():
combined_text = attributes["skills"] + ", " + attributes["interests"]
career_embeddings[career] = get_embedding(combined_text)
# Function to recommend careers based on skills and interests
def get_career_recommendations(skills: str, interests: str):
user_input = skills + ", " + interests
user_embedding = get_embedding(user_input)
recommendations = []
for career, career_embedding in career_embeddings.items():
similarity = torch.cosine_similarity(user_embedding, career_embedding, dim=0).item()
recommendations.append((career, similarity))
recommendations.sort(key=lambda x: x[1], reverse=True)
return [f"{career} (Similarity: {similarity:.2f})" for career, similarity in recommendations[:5]]