File size: 4,779 Bytes
0bff77d
 
 
 
 
 
 
 
 
 
 
775ea8e
 
0bff77d
 
 
 
 
 
 
775ea8e
0bff77d
775ea8e
0bff77d
 
775ea8e
ac0d5f8
775ea8e
ac0d5f8
775ea8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ac0d5f8
 
 
775ea8e
 
 
 
 
 
ac0d5f8
775ea8e
ac0d5f8
 
 
 
 
775ea8e
 
46a6d24
ac0d5f8
 
 
3163779
 
 
 
 
 
 
 
ac0d5f8
 
 
 
 
775ea8e
ac0d5f8
 
 
 
 
 
775ea8e
ac0d5f8
 
 
 
 
775ea8e
ac0d5f8
 
 
775ea8e
ac0d5f8
775ea8e
 
 
 
 
ac0d5f8
 
 
1409325
 
 
 
 
 
 
 
 
 
775ea8e
ac0d5f8
775ea8e
 
 
 
 
 
ac0d5f8
775ea8e
ac0d5f8
 
775ea8e
ac0d5f8
775ea8e
 
 
 
 
 
 
 
ac0d5f8
775ea8e
ac0d5f8
775ea8e
ac0d5f8
775ea8e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
---
language:
  - en
license: apache-2.0
library_name: transformers
tags:
  - emotion-classification
  - healthcare
  - distilbert
  - patient-doctor-conversations
  - text-classification
  - clinical-AI
  - mental-health
model_index:
  - name: patient-emotion-classifier
    results:
      - task:
          type: text-classification
        metrics:
          - type: accuracy
            value: 0.713
          - type: f1
            value: 0.722
---

<div align="center">

# πŸ€– Patient Emotion Classifier

**Advanced AI-Powered Emotion Recognition for Healthcare Dialogues**

*Part of the Blended AI+X Initiative β€” Bridging Artificial Intelligence and Healthcare*

---

[![Model](https://img.shields.io/badge/Model-DistilBERT-blue)](https://huggingface.co/distilbert/distilbert-base-uncased)
[![License](https://img.shields.io/badge/License-Apache--2.0-green)](LICENSE)
[![Performance](https://img.shields.io/badge/F1--Score-72.2%25-orange)]()

</div>

## πŸ”¬ Overview

We are thrilled to introduce **Patient Emotion Classifier**, a state-of-the-art NLP model engineered to understand emotional nuances in patient-doctor conversations. 

This model represents our commitment to advancing **AI for Healthcare (AI+X)**, leveraging cutting-edge transformer architectures to bridge the gap between artificial intelligence and compassionate care.

### Key Capabilities

- **Multiclass Emotion Recognition** β€” Identifies 6 distinct emotional states in clinical dialogues
- **Healthcare-Optimized** β€” Specifically trained on medical conversation data
- **Production-Ready** β€” Deployable via REST API for real-time inference
- **Lightweight & Efficient** β€” Built on DistilBERT for fast inference

## 🎯 Emotion Categories

Our model classifies emotional states into **6 clinically-relevant categories**:

| Category | Description |
|----------|-------------|
| 😐 **Neutral** | Objective, non-emotional statements |
| 😰 **Anxiety/Fear** | Patient expresses worry, concern, or fear |
| 😠 **Anger/Frustration** | Patient shows frustration or displeasure |
| 😒 **Sadness/Helplessness** | Patient feels down or hopeless |
| πŸ€” **Confusion/Doubt** | Patient expresses uncertainty or questions |
| πŸ™ **Gratitude/Relief** | Patient conveys thanks or relief |

## πŸ“Š Model Performance

### Overall Metrics

| Metric | Value |
|--------|-------|
| **Accuracy** | **71.3%** |
| **Macro F1** | **0.722** |
| Weighted F1 | 0.72 |

### Per-Class Performance

| Emotion | Precision | Recall | F1-Score |
|---------|-----------|--------|----------|
| Neutral | 0.75 | 0.78 | 0.76 |
| Anxiety/Fear | 0.52 | 0.63 | 0.57 |
| Anger/Frustration | 0.80 | 0.73 | 0.76 |
| Sadness/Helplessness | 0.65 | 0.55 | 0.60 |
| Confusion/Doubt | 0.60 | 0.58 | 0.59 |
| Gratitude/Relief | 0.72 | 0.75 | 0.73 |

### Label Distribution

![Label Distribution](data/label_distribution.png)

## πŸš€ Quick Start

### 1. Install Dependencies

```bash
pip install -r requirements.txt

### 2. Launch the Service

```bash
cd see
python app.py

### 3. Access the Interface

http://localhost:8002

## πŸ“š Dataset

This model was trained on a meticulously curated subset of medical dialogues:

- **Original Source**: [Chinese MedDialog Dataset](https://tianchi.aliyun.com/dataset/92110) β€” Alibaba Cloud Tianchi
- **Post-Processing**: Carefully filtered, translated, and annotated for emotion classification
- **Total Samples**: 28,280 annotated dialogues
- **Categories**: 6 emotion labels
- **Language**: English

## πŸ“š References

1. **MedDialog Dataset**  
   Chinese Medical Dialogue Dataset. Alibaba Cloud Tianchi.  
   https://tianchi.aliyun.com/dataset/92110

2. **DistilBERT**  
   Sanh, V., Debut, L., Chaumond, J., & Wolf, T. (2019). *DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter*. arXiv preprint arXiv:1910.01108.  
   https://arxiv.org/abs/1910.01108

## πŸ—οΈ Technical Specifications

| Component | Details |
|-----------|---------|
| **Base Architecture** | [DistilBERT](https://huggingface.co/distilbert/distilbert-base-uncased) |
| **Task Type** | 6-class emotion classification |
| **Max Sequence Length** | 512 tokens |
| **Framework** | PyTorch + Transformers |

## πŸ“ Project Structure

patient-emotion-analysis/
β”œβ”€β”€ best_model/          # Fine-tuned model weights
β”œβ”€β”€ see/                 # Inference service
β”‚   β”œβ”€β”€ app.py          # Web application
β”‚   β”œβ”€β”€ inference.py    # Core inference logic
β”‚   └── templates/      # UI templates
β”œβ”€β”€ data/               # Training & evaluation data
β”œβ”€β”€ requirements.txt    # Dependencies
└── README.md           # This file

---

<div align="center">

**Blended AI+X Initiative** β€” *Advancing Healthcare Through Intelligence*

</div>