Update app.py
Browse files
app.py
CHANGED
@@ -6,20 +6,20 @@ pipe_1 = pipeline("text-classification", model="mavinsao/mi-roberta-base-finetun
|
|
6 |
pipe_2 = pipeline("text-classification", model="mavinsao/roberta-mental-finetuned")
|
7 |
|
8 |
|
9 |
-
def ensemble_predict(text):
|
10 |
-
|
|
|
11 |
results_2 = pipe_2(text)
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
ensemble_scores[label] = ensemble_scores.get(label, 0) + score / 2
|
20 |
|
21 |
-
predicted_label = max(ensemble_scores, key=ensemble_scores.get)
|
22 |
-
confidence = ensemble_scores[predicted_label]
|
23 |
|
24 |
return predicted_label, confidence
|
25 |
|
|
|
6 |
pipe_2 = pipeline("text-classification", model="mavinsao/roberta-mental-finetuned")
|
7 |
|
8 |
|
9 |
+
def ensemble_predict(text):
|
10 |
+
# Store results from each model
|
11 |
+
results_1 = pipe_1(text)
|
12 |
results_2 = pipe_2(text)
|
13 |
|
14 |
+
ensemble_scores = {}
|
15 |
+
for results in [results_1, results_2]: # Iterate through predictions
|
16 |
+
for result in results:
|
17 |
+
label = result['label']
|
18 |
+
score = result['score']
|
19 |
+
ensemble_scores[label] = ensemble_scores.get(label, 0) + score / 2
|
|
|
20 |
|
21 |
+
predicted_label = max(ensemble_scores, key=ensemble_scores.get)
|
22 |
+
confidence = ensemble_scores[predicted_label] # Ensemble confidence
|
23 |
|
24 |
return predicted_label, confidence
|
25 |
|