File size: 12,192 Bytes
9366995
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# Evaluators Documentation

This directory contains all evaluator implementations for the Therapist Conversation Evaluator tool. Each evaluator measures different aspects of therapeutic conversations.

## Overview

All evaluators follow a consistent interface and return standardized `EvaluationResult` objects. The result type depends on the granularity level:
- **Utterance-level**: Per-utterance scores (`granularity="utterance"`)
- **Segment-level**: Multi-utterance segment scores (`granularity="segment"`)
- **Conversation-level**: Overall conversation scores (`granularity="conversation"`)

## Evaluation Result Types

### Score Types

1. **Categorical Score**: Discrete labels (e.g., "High", "Medium", "Low")
   ```python
   {
       "type": "categorical",
       "label": "High",
       "confidence": 0.85  # Optional: 0-1 confidence score
   }
   ```

2. **Numerical Score**: Continuous values with max bounds (e.g., 1-5 scale)
   ```python
   {
       "type": "numerical",
       "value": 4.0,
       "max_value": 5.0,
       "label": "High"  # Optional: derived label
   }
   ```

### Granularity Levels

- **Utterance-level**: Scores for each individual utterance in the conversation
- **Segment-level**: Aggregate scores for multi-utterance segments
- **Conversation-level**: Overall scores for the entire conversation

---

## Evaluators

### 1. Empathy ER (Emotional Reaction) Evaluator

**File**: `empathy_er_evaluator.py`

**Description**: Measures the emotional reaction component of empathy in therapeutic responses. Evaluates how well the therapist responds to the patient's emotional state.

**Model**: `RyanDDD/empathy-mental-health-reddit-ER`

**Result Type**:
- **Granularity**: Utterance-level
- **Score Type**: Categorical (3 labels)
- **Labels**: `["Low", "Medium", "High"]`
- **Evaluates**: Therapist responses only

**Output Format**:
```python
{
    "granularity": "utterance",
    "per_utterance": [
        {
            "index": 0,
            "metrics": {
                "empathy_er": {
                    "type": "categorical",
                    "label": "High",
                    "confidence": 0.92
                }
            }
        }
    ]
}
```

---

### 2. Empathy IP (Interpretation) Evaluator

**File**: `empathy_ip_evaluator.py`

**Description**: Measures the interpretation component of empathy in therapeutic responses. Evaluates how well the therapist interprets and understands the patient's situation.

**Model**: `RyanDDD/empathy-mental-health-reddit-IP`

**Result Type**:
- **Granularity**: Utterance-level
- **Score Type**: Categorical (3 labels)
- **Labels**: `["Low", "Medium", "High"]`
- **Evaluates**: Therapist responses only

**Output Format**:
```python
{
    "granularity": "utterance",
    "per_utterance": [
        {
            "index": 0,
            "metrics": {
                "empathy_ip": {
                    "type": "categorical",
                    "label": "Medium",
                    "confidence": 0.78
                }
            }
        }
    ]
}
```

---

### 3. Empathy EX (Exploration) Evaluator

**File**: `empathy_ex_evaluator.py`

**Description**: Measures the exploration component of empathy in therapeutic responses. Evaluates how well the therapist explores and deepens understanding of the patient's concerns.

**Model**: `RyanDDD/empathy-mental-health-reddit-EX`

**Result Type**:
- **Granularity**: Utterance-level
- **Score Type**: Categorical (3 labels)
- **Labels**: `["Low", "Medium", "High"]`
- **Evaluates**: Therapist responses only

**Output Format**:
```python
{
    "granularity": "utterance",
    "per_utterance": [
        {
            "index": 0,
            "metrics": {
                "empathy_ex": {
                    "type": "categorical",
                    "label": "High",
                    "confidence": 0.89
                }
            }
        }
    ]
}
```

---

### 4. Talk Type Evaluator

**File**: `talk_type_evaluator.py`

**Description**: Classifies patient utterances into change talk, sustain talk, or neutral. Uses BERT model trained on motivational interviewing data.

**Model**: `RyanDDD/bert-motivational-interviewing`

**Result Type**:
- **Granularity**: Utterance-level
- **Score Type**: Categorical (3 labels)
- **Labels**: `["Change", "Neutral", "Sustain"]`
- **Evaluates**: Patient utterances only

**Output Format**:
```python
{
    "granularity": "utterance",
    "per_utterance": [
        {
            "index": 0,
            "metrics": {
                "talk_type": {
                    "type": "categorical",
                    "label": "Change",
                    "confidence": 0.91
                }
            }
        }
    ]
}
```

---

### 5. Mental Health Factuality Evaluator

**File**: `factuality_evaluator.py`

**Description**: LLM-as-Judge scoring of assistant responses for clinical accuracy, safety, scope appropriateness, evidence-based practice, and overall quality. Uses strict rubric to evaluate mental health chat responses.

**Model**: OpenAI GPT-4o (configurable)

**Result Type**:
- **Granularity**: Utterance-level
- **Score Type**: Numerical (5-point scale: 1-5)
- **Scale**: 1-5 for all dimensions
- **Evaluates**: Assistant/therapist responses only

**Dimensions**:
1. `overall_score` (1-5): Overall factuality and quality
2. `clinical_accuracy` (1-5): Clinical accuracy of information
3. `safety` (1-5): Safety of the response
4. `scope_appropriateness` (1-5): Appropriateness of scope
5. `evidence_based` (1-5): Evidence-based practice alignment
6. `explanation` (text): Reasoning for the scores

**Output Format**:
```python
{
    "granularity": "utterance",
    "per_utterance": [
        {
            "index": 0,
            "metrics": {
                "overall": {
                    "type": "numerical",
                    "value": 4,
                    "max_value": 5
                },
                "clinical_accuracy": {
                    "type": "numerical",
                    "value": 4,
                    "max_value": 5
                },
                "safety": {
                    "type": "numerical",
                    "value": 5,
                    "max_value": 5
                },
                "scope": {
                    "type": "numerical",
                    "value": 4,
                    "max_value": 5
                },
                "evidence": {
                    "type": "numerical",
                    "value": 3,
                    "max_value": 5
                },
                "explanation": {
                    "type": "text",
                    "value": "Response demonstrates good clinical accuracy..."
                }
            }
        }
    ]
}
```

**Scoring Rules**:
- Conservative scoring: Prefers 3 (neutral) for generic responses without clinical claims
- Safety gate: If safety ≤ 2, overall_score is capped at safety level
- Evidence requirement: Avoids 5 unless response references specific evidence-based techniques
- No clinical claims: If response lacks clinical terms, clinical_accuracy and evidence_based are capped at 3

---

### 6. Emotion Analysis Evaluator

**File**: `emotion_evaluator.py`

**Description**: Analyzes user emotions using emotion classification model. Calculates negative emotion sum, joy/neutral shift, and tracks emotion change trends across the conversation.

**Model**: `j-hartmann/emotion-english-distilroberta-base`

**Result Type**:
- **Granularity**: Utterance-level (with overall trend)
- **Score Type**: Numerical (with categorical labels)
- **Evaluates**: User/patient utterances only

**Metrics**:
1. `emotion_sum_negative` (0.0-1.0): Sum of negative emotions (anger, disgust, fear, sadness)
   - Labels: "Low" (< 0.2), "Medium" (0.2-0.5), "High" (> 0.5)
2. `emotion_joy_neutral_shift` (-1.0 to 1.0): Difference between joy and neutral emotions
   - Labels: "Positive" (> 0.2), "Neutral" (-0.2 to 0.2), "Negative" (< -0.2)
3. `emotion_trend_direction` (overall): Trend analysis across conversation
   - Labels: "improving", "declining", "stable", "neutral"

**Emotion Labels**: `["anger", "disgust", "fear", "joy", "neutral", "sadness", "surprise"]`

**Output Format**:
```python
{
    "granularity": "utterance",
    "per_utterance": [
        {
            "index": 0,
            "metrics": {
                "emotion_sum_negative": {
                    "type": "numerical",
                    "value": 0.35,
                    "max_value": 1.0,
                    "label": "Medium"
                },
                "emotion_joy_neutral_shift": {
                    "type": "numerical",
                    "value": -0.15,
                    "max_value": 1.0,
                    "label": "Neutral"
                }
            }
        }
    ],
    "overall": {
        "emotion_avg_sum_negative": {
            "type": "numerical",
            "value": 0.28,
            "max_value": 1.0,
            "label": "improving"
        },
        "emotion_avg_joy_neutral_shift": {
            "type": "numerical",
            "value": 0.12,
            "max_value": 1.0,
            "label": "improving"
        },
        "emotion_trend_direction": {
            "type": "categorical",
            "label": "improving"
        }
    }
}
```

**Trend Analysis**:
- Compares first half vs second half of conversation
- "improving": Negative emotions decrease AND joy/neutral shift increases
- "declining": Negative emotions increase AND joy/neutral shift decreases
- "stable": No significant change
- "neutral": Insufficient data

---

## Summary Table

| Evaluator | Granularity | Score Type | Labels/Scale | Evaluates | Model |
|-----------|-------------|-----------|--------------|-----------|-------|
| Empathy ER | Utterance | Categorical | 3 labels (Low/Medium/High) | Therapist | `RyanDDD/empathy-mental-health-reddit-ER` |
| Empathy IP | Utterance | Categorical | 3 labels (Low/Medium/High) | Therapist | `RyanDDD/empathy-mental-health-reddit-IP` |
| Empathy EX | Utterance | Categorical | 3 labels (Low/Medium/High) | Therapist | `RyanDDD/empathy-mental-health-reddit-EX` |
| Talk Type | Utterance | Categorical | 3 labels (Change/Neutral/Sustain) | Patient | `RyanDDD/bert-motivational-interviewing` |
| Factuality | Utterance | Numerical | 5-point scale (1-5) | Therapist | OpenAI GPT-4o |
| Emotion Analysis | Utterance + Overall | Numerical | 0.0-1.0 (with labels) | Patient | `j-hartmann/emotion-english-distilroberta-base` |

---

## Usage

All evaluators follow the same interface:

```python
from evaluators.impl.empathy_er_evaluator import EmpathyEREvaluator

# Initialize evaluator
evaluator = EmpathyEREvaluator()

# Evaluate conversation
result = evaluator.execute(conversation)

# Access results
for utterance_result in result["per_utterance"]:
    metrics = utterance_result["metrics"]
    if "empathy_er" in metrics:
        score = metrics["empathy_er"]
        print(f"Label: {score['label']}, Confidence: {score['confidence']}")
```

---

## Adding New Evaluators

To add a new evaluator:

1. Create a new file in `impl/` directory
2. Inherit from `Evaluator` base class
3. Register using `@register_evaluator` decorator
4. Implement `execute()` method that returns `EvaluationResult`
5. Use helper functions from `utils.evaluation_helpers`:
   - `create_categorical_score()` for categorical scores
   - `create_numerical_score()` for numerical scores
   - `create_utterance_result()` for utterance-level results
   - `create_conversation_result()` for conversation-level results
   - `create_segment_result()` for segment-level results

Example:
```python
from evaluators.base import Evaluator
from evaluators.registry import register_evaluator
from custom_types import Utterance, EvaluationResult
from utils.evaluation_helpers import create_categorical_score, create_utterance_result

@register_evaluator(
    "my_metric",
    label="My Metric",
    description="Description of what this metric measures",
    category="Category Name"
)
class MyEvaluator(Evaluator):
    METRIC_NAME = "my_metric"

    def execute(self, conversation: List[Utterance], **kwargs) -> EvaluationResult:
        # Implementation
        pass
```