mavinsao commited on
Commit
3f7ec6a
1 Parent(s): 0d00d6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
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
- results_1 = pipe_1(text)
 
11
  results_2 = pipe_2(text)
12
 
13
- # Implement your chosen ensemble strategy here.
14
- # Example with simple averaging:
15
- ensemble_scores = {}
16
- for result in results_1 + results_2:
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]
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