webapp1 commited on
Commit
7b50c79
·
verified ·
1 Parent(s): 972beef

Upload 28 files

Browse files
models_bin/text_transformer/config.json CHANGED
@@ -1,45 +1,51 @@
1
- {
2
- "add_cross_attention": false,
3
- "architectures": [
4
- "BertForSequenceClassification"
5
- ],
6
- "attention_probs_dropout_prob": 0.1,
7
- "bos_token_id": null,
8
- "classifier_dropout": null,
9
- "dtype": "float32",
10
- "eos_token_id": null,
11
- "gradient_checkpointing": false,
12
- "hidden_act": "gelu",
13
- "hidden_dropout_prob": 0.1,
14
- "hidden_size": 768,
15
- "id2label": {
16
- "0": "LABEL_0",
17
- "1": "LABEL_1",
18
- "2": "LABEL_2",
19
- "3": "LABEL_3",
20
- "4": "LABEL_4"
21
- },
22
- "initializer_range": 0.02,
23
- "intermediate_size": 3072,
24
- "is_decoder": false,
25
- "label2id": {
26
- "LABEL_0": 0,
27
- "LABEL_1": 1,
28
- "LABEL_2": 2,
29
- "LABEL_3": 3,
30
- "LABEL_4": 4
31
- },
32
- "layer_norm_eps": 1e-12,
33
- "max_position_embeddings": 512,
34
- "model_type": "bert",
35
- "num_attention_heads": 12,
36
- "num_hidden_layers": 12,
37
- "pad_token_id": 0,
38
- "position_embedding_type": "absolute",
39
- "problem_type": "single_label_classification",
40
- "tie_word_embeddings": true,
41
- "transformers_version": "5.13.1",
42
- "type_vocab_size": 2,
43
- "use_cache": false,
44
- "vocab_size": 30522
45
- }
 
 
 
 
 
 
 
1
+ {
2
+ "add_cross_attention": false,
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": null,
8
+ "classifier_dropout": null,
9
+ "dtype": "float32",
10
+ "eos_token_id": null,
11
+ "gradient_checkpointing": false,
12
+ "hidden_act": "gelu",
13
+ "hidden_dropout_prob": 0.1,
14
+ "hidden_size": 768,
15
+ "id2label": {
16
+ "0": "Normal",
17
+ "1": "Stress",
18
+ "2": "Depression",
19
+ "3": "Anxiety",
20
+ "4": "Emotional Distress"
21
+ },
22
+ "initializer_range": 0.02,
23
+ "intermediate_size": 3072,
24
+ "is_decoder": false,
25
+ "label2id": {
26
+ "Normal": 0,
27
+ "Stress": 1,
28
+ "Depression": 2,
29
+ "Anxiety": 3,
30
+ "Emotional Distress": 4
31
+ },
32
+
33
+
34
+
35
+
36
+
37
+ },
38
+ "layer_norm_eps": 1e-12,
39
+ "max_position_embeddings": 512,
40
+ "model_type": "bert",
41
+ "num_attention_heads": 12,
42
+ "num_hidden_layers": 12,
43
+ "pad_token_id": 0,
44
+ "position_embedding_type": "absolute",
45
+ "problem_type": "single_label_classification",
46
+ "tie_word_embeddings": true,
47
+ "transformers_version": "5.13.1",
48
+ "type_vocab_size": 2,
49
+ "use_cache": false,
50
+ "vocab_size": 30522
51
+ }
src/models/text_classifier.py CHANGED
@@ -177,37 +177,13 @@ class LinguisticStressClassifier:
177
 
178
  prob_dict = {res['label']: round(float(res['score']), 4) for res in results}
179
 
180
- # FIX: The transformer was only trained on "Normal" and "Stress".
181
- # Its outputs for Depression, Anxiety, and Emotional Distress are random noise.
182
- # We use heuristic logic to accurately detect these missing classes.
183
- heuristic_res = self._heuristic_predict(text)
184
- h_cat = heuristic_res["predicted_category"]
185
 
186
- if h_cat in ["Depression", "Anxiety", "Emotional Distress"]:
187
- # Override transformer noise with our accurate heuristic
188
- prob_dict = heuristic_res["probabilities"]
189
- pred_category = h_cat
190
- confidence = heuristic_res["confidence"]
191
- stress_score = heuristic_res["linguistic_stress_score"]
192
- else:
193
- # Zero out the noise for untrained classes
194
- prob_dict["Depression"] = 0.0
195
- prob_dict["Anxiety"] = 0.0
196
- prob_dict["Emotional Distress"] = 0.0
197
-
198
- # Re-normalize Normal and Stress
199
- total_valid = prob_dict.get("Normal", 0.0) + prob_dict.get("Stress", 0.0)
200
- if total_valid > 0:
201
- prob_dict["Normal"] = round(prob_dict["Normal"] / total_valid, 4)
202
- prob_dict["Stress"] = round(prob_dict["Stress"] / total_valid, 4)
203
-
204
- pred_category = max(prob_dict, key=prob_dict.get)
205
- confidence = prob_dict[pred_category]
206
-
207
- calm_prob = prob_dict.get("Normal", 0.0)
208
- stress_prob = 1.0 - calm_prob
209
- neg_density = calculate_negative_word_density(text)
210
- stress_score = round(min(100.0, max(0.0, (stress_prob * 80.0) + (neg_density * 100.0))), 2)
211
 
212
  return {
213
  "predicted_category": pred_category,
 
177
 
178
  prob_dict = {res['label']: round(float(res['score']), 4) for res in results}
179
 
180
+ pred_category = max(prob_dict, key=prob_dict.get)
181
+ confidence = prob_dict[pred_category]
 
 
 
182
 
183
+ calm_prob = prob_dict.get("Normal", 0.0)
184
+ stress_prob = 1.0 - calm_prob
185
+ neg_density = calculate_negative_word_density(text)
186
+ stress_score = round(min(100.0, max(0.0, (stress_prob * 80.0) + (neg_density * 100.0))), 2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
  return {
189
  "predicted_category": pred_category,