QuentinL52 commited on
Commit
8e8b435
·
verified ·
1 Parent(s): 90c84b7

Create deep_learning_analyzer.py

Browse files
Files changed (1) hide show
  1. src/core/deep_learning_analyzer.py +56 -0
src/core/deep_learning_analyzer.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import pipeline
3
+ from sentence_transformers import SentenceTransformer, util
4
+ from typing import List, Dict, Any
5
+
6
+ class MultiModelInterviewAnalyzer:
7
+ def __init__(self):
8
+ self.sentiment_analyzer = pipeline(
9
+ "text-classification",
10
+ model="astrosbd/french_emotion_camembert",
11
+ return_all_scores=True,
12
+ device=0 if torch.cuda.is_available() else -1,
13
+ )
14
+ self.similarity_model = SentenceTransformer('all-MiniLM-L6-v2')
15
+ self.intent_classifier = pipeline(
16
+ "zero-shot-classification",
17
+ model="joeddav/xlm-roberta-large-xnli"
18
+ )
19
+
20
+ def analyze_sentiment(self, messages: List[Dict[str, str]]) -> List[List[Dict[str, Any]]]:
21
+ user_messages = [msg['content'] for msg in messages if msg['role'] == 'user']
22
+ if not user_messages:
23
+ return []
24
+ return self.sentiment_analyzer(user_messages)
25
+
26
+ def compute_semantic_similarity(self, messages: List[Dict[str, str]], job_requirements: str) -> float:
27
+ user_answers = " ".join([msg['content'] for msg in messages if msg['role'] == 'user'])
28
+ embedding_answers = self.similarity_model.encode(user_answers, convert_to_tensor=True)
29
+ embedding_requirements = self.similarity_model.encode(job_requirements, convert_to_tensor=True)
30
+ cosine_score = util.cos_sim(embedding_answers, embedding_requirements)
31
+ return cosine_score.item()
32
+
33
+ def classify_candidate_intent(self, messages: List[Dict[str, str]]) -> List[Dict[str, Any]]:
34
+ user_answers = [msg['content'] for msg in messages if msg['role'] == 'user']
35
+ if not user_answers:
36
+ return []
37
+
38
+ candidate_labels = [
39
+ "parle de son expérience technique",
40
+ "exprime sa motivation",
41
+ "pose une question",
42
+ "exprime de l'incertitude ou du stress"
43
+ ]
44
+ return self.intent_classifier(user_answers, candidate_labels, multi_label=False)
45
+
46
+ def run_full_analysis(self, conversation_history: List[Dict[str, str]], job_requirements: str) -> Dict[str, Any]:
47
+ sentiment_results = self.analyze_sentiment(conversation_history)
48
+ similarity_score = self.compute_semantic_similarity(conversation_history, job_requirements)
49
+ intent_results = self.classify_candidate_intent(conversation_history)
50
+
51
+ return {
52
+ "overall_similarity_score": round(similarity_score, 2),
53
+ "sentiment_analysis": sentiment_results,
54
+ "intent_analysis": intent_results,
55
+ "raw_transcript": conversation_history
56
+ }