CounselReflect commited on
Commit
29111a1
·
verified ·
1 Parent(s): ede452d

Upload AnnoMI BERT model for Motivational Interviewing talk classification

Browse files
README.md ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ library_name: transformers
5
+ pipeline_tag: text-classification
6
+ tags:
7
+ - text-classification
8
+ - motivational-interviewing
9
+ - bert
10
+ - mental-health
11
+ - counseling
12
+ - psychology
13
+ - transformers
14
+ - pytorch
15
+ datasets:
16
+ - AnnoMI
17
+ metrics:
18
+ - accuracy
19
+ - f1
20
+ - precision
21
+ - recall
22
+ model-index:
23
+ - name: bert-motivational-interviewing
24
+ results:
25
+ - task:
26
+ type: text-classification
27
+ name: Text Classification
28
+ dataset:
29
+ name: AnnoMI
30
+ type: AnnoMI
31
+ metrics:
32
+ - type: accuracy
33
+ value: 0.701
34
+ name: Accuracy
35
+ - type: f1
36
+ value: 0.579
37
+ name: F1 Score (macro)
38
+ widget:
39
+ - text: "I really want to quit smoking."
40
+ example_title: "Change Talk"
41
+ - text: "I don't know if I can do this."
42
+ example_title: "Neutral"
43
+ - text: "I like smoking, it helps me relax."
44
+ example_title: "Sustain Talk"
45
+ ---
46
+
47
+ # BERT for Motivational Interviewing Client Talk Classification
48
+
49
+ ## Model Description
50
+
51
+ This model is a fine-tuned **BERT-base-uncased** model for classifying client utterances in **Motivational Interviewing (MI)** conversations.
52
+
53
+ Motivational Interviewing is a counseling approach used to help individuals overcome ambivalence and make positive behavioral changes. This model identifies different types of client talk that indicate their readiness for change.
54
+
55
+ ## Intended Use
56
+
57
+ - **Primary Use**: Classify client statements in motivational interviewing dialogues
58
+ - **Applications**:
59
+ - Counselor training and feedback
60
+ - MI session analysis
61
+ - Automated dialogue systems
62
+ - Mental health research
63
+
64
+ ## Training Data
65
+
66
+ The model was trained on the **AnnoMI dataset** (Annotated Motivational Interviewing), which contains expert-annotated counseling dialogues.
67
+
68
+ - **Training samples**: ~2,400 utterances
69
+ - **Validation samples**: ~500 utterances
70
+ - **Test samples**: ~700 utterances
71
+
72
+ ## Labels
73
+
74
+ The model classifies client talk into three categories:
75
+
76
+ - **0**: change
77
+ - **1**: neutral
78
+ - **2**: sustain
79
+
80
+ ### Label Definitions
81
+
82
+ - **Change Talk**: Client statements expressing desire, ability, reasons, or need for change
83
+ - Example: "I really want to quit smoking" or "I think I can do it"
84
+
85
+ - **Neutral**: General responses without clear indication of change or sustain
86
+ - Example: "I don't know" or "Maybe"
87
+
88
+ - **Sustain Talk**: Client statements expressing reasons for maintaining current behavior
89
+ - Example: "I like smoking, it helps me relax"
90
+
91
+ ## Performance
92
+
93
+ ### Test Set Metrics
94
+
95
+ - **Accuracy**: 70.1%
96
+ - **Macro F1**: 57.9%
97
+ - **Macro Precision**: 59.3%
98
+ - **Macro Recall**: 57.3%
99
+
100
+ ### Confusion Matrix
101
+
102
+ ```
103
+ Predicted
104
+ change neutral sustain
105
+ Actual change 75 78 23
106
+ neutral 43 396 27
107
+ sustain 11 34 36
108
+ ```
109
+
110
+ **Note**: The model performs best on the "neutral" class (most frequent), and has room for improvement on "change" and "sustain" classes.
111
+
112
+ ## Usage
113
+
114
+ ### Quick Start
115
+
116
+ ```python
117
+ from transformers import BertTokenizer, BertForSequenceClassification
118
+ import torch
119
+
120
+ # Load model and tokenizer
121
+ model_name = "RyanDDD/bert-motivational-interviewing"
122
+ tokenizer = BertTokenizer.from_pretrained(model_name)
123
+ model = BertForSequenceClassification.from_pretrained(model_name)
124
+
125
+ # Predict
126
+ text = "I really want to quit smoking. It's been affecting my health."
127
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
128
+
129
+ with torch.no_grad():
130
+ outputs = model(**inputs)
131
+ probs = torch.softmax(outputs.logits, dim=1)
132
+ pred = torch.argmax(probs, dim=1)
133
+
134
+ label_map = model.config.id2label
135
+ print(f"Talk type: {label_map[pred.item()]}")
136
+ print(f"Confidence: {probs[0][pred].item():.2%}")
137
+ ```
138
+
139
+ ### Batch Prediction
140
+
141
+ ```python
142
+ texts = [
143
+ "I want to stop drinking.",
144
+ "I don't think I have a problem.",
145
+ "I like drinking with my friends."
146
+ ]
147
+
148
+ inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True, max_length=128)
149
+
150
+ with torch.no_grad():
151
+ outputs = model(**inputs)
152
+ probs = torch.softmax(outputs.logits, dim=1)
153
+ preds = torch.argmax(probs, dim=1)
154
+
155
+ for text, pred, prob in zip(texts, preds, probs):
156
+ label = model.config.id2label[pred.item()]
157
+ confidence = prob[pred].item()
158
+ print(f"Text: {text}")
159
+ print(f"Type: {label} ({confidence:.1%})")
160
+ print()
161
+ ```
162
+
163
+ ## Training Details
164
+
165
+ ### Hyperparameters
166
+
167
+ - **Base model**: `bert-base-uncased`
168
+ - **Max sequence length**: 128 tokens
169
+ - **Batch size**: 16
170
+ - **Learning rate**: 2e-5
171
+ - **Epochs**: 5
172
+ - **Optimizer**: AdamW
173
+ - **Loss**: Cross-entropy
174
+
175
+ ### Hardware
176
+
177
+ Trained on a single GPU (NVIDIA GPU recommended).
178
+
179
+ ## Limitations
180
+
181
+ 1. **Class Imbalance**: The model performs better on "neutral" (majority class) than "change" and "sustain"
182
+ 2. **Context**: The model classifies single utterances without conversation context
183
+ 3. **Domain**: Trained specifically on MI conversations; may not generalize to other counseling types
184
+ 4. **Language**: English only
185
+
186
+ ## Ethical Considerations
187
+
188
+ - This model is intended to **assist**, not replace, human counselors
189
+ - Predictions should be reviewed by qualified professionals
190
+ - Privacy and confidentiality must be maintained when processing real counseling data
191
+ - Be aware of potential biases in training data
192
+
193
+ ## Citation
194
+
195
+ If you use this model, please cite:
196
+
197
+ ```bibtex
198
+ @misc{bert-mi-classifier-2024,
199
+ author = {Ryan},
200
+ title = {BERT for Motivational Interviewing Client Talk Classification},
201
+ year = {2024},
202
+ publisher = {HuggingFace},
203
+ howpublished = {\url{https://huggingface.co/RyanDDD/bert-motivational-interviewing}}
204
+ }
205
+ ```
206
+
207
+ ## References
208
+
209
+ - **AnnoMI Dataset**: [GitHub](https://github.com/uccollab/AnnoMI)
210
+ - **BERT Paper**: [Devlin et al., 2019](https://arxiv.org/abs/1810.04805)
211
+ - **Motivational Interviewing**: [Miller & Rollnick, 2012](https://motivationalinterviewing.org/)
212
+
213
+ ## Model Card Contact
214
+
215
+ For questions or feedback, please open an issue in the model repository.
config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "bert-base-uncased",
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "gradient_checkpointing": false,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "id2label": {
13
+ "0": "change",
14
+ "1": "neutral",
15
+ "2": "sustain"
16
+ },
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 3072,
19
+ "label2id": {
20
+ "change": 0,
21
+ "neutral": 1,
22
+ "sustain": 2
23
+ },
24
+ "layer_norm_eps": 1e-12,
25
+ "max_position_embeddings": 512,
26
+ "model_type": "bert",
27
+ "num_attention_heads": 12,
28
+ "num_hidden_layers": 12,
29
+ "pad_token_id": 0,
30
+ "position_embedding_type": "absolute",
31
+ "problem_type": "single_label_classification",
32
+ "torch_dtype": "float32",
33
+ "transformers_version": "4.44.2",
34
+ "type_vocab_size": 2,
35
+ "use_cache": true,
36
+ "vocab_size": 30522
37
+ }
example_usage.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Example usage of the Motivational Interviewing BERT classifier
3
+ """
4
+
5
+ from transformers import BertTokenizer, BertForSequenceClassification, RobertaTokenizer, RobertaForSequenceClassification
6
+
7
+ import torch
8
+
9
+ def predict_talk_type(text, model, tokenizer):
10
+ """Predict the talk type for a given text"""
11
+ inputs = tokenizer(
12
+ text,
13
+ return_tensors="pt",
14
+ padding=True,
15
+ truncation=True,
16
+ max_length=128
17
+ )
18
+
19
+ with torch.no_grad():
20
+ outputs = model(**inputs)
21
+ probs = torch.softmax(outputs.logits, dim=1)
22
+ pred = torch.argmax(probs, dim=1)
23
+
24
+ label = model.config.id2label[pred.item()]
25
+ confidence = probs[0][pred].item()
26
+
27
+ return {
28
+ 'label': label,
29
+ 'confidence': confidence,
30
+ 'all_probs': {
31
+ model.config.id2label[i]: probs[0][i].item()
32
+ for i in range(len(probs[0]))
33
+ }
34
+ }
35
+
36
+ def main():
37
+ # Load model and tokenizer
38
+ model_name = "RyanDDD/bert-motivational-interviewing"
39
+ print(f"Loading model: {model_name}")
40
+
41
+ tokenizer = BertTokenizer.from_pretrained(model_name)
42
+ model = BertForSequenceClassification.from_pretrained(model_name)
43
+
44
+ # Example texts
45
+ examples = [
46
+ "I really want to quit smoking for my health.",
47
+ "I'm not sure if I can do this.",
48
+ "Smoking helps me deal with stress.",
49
+ "Maybe I should try cutting down.",
50
+ "I've been thinking about quitting.",
51
+ "I like smoking, it's part of who I am."
52
+ ]
53
+
54
+ print("\nPredictions:\n" + "="*60)
55
+
56
+ for text in examples:
57
+ result = predict_talk_type(text, model, tokenizer)
58
+
59
+ print(f"\nText: {text}")
60
+ print(f"Type: {result['label']} ({result['confidence']:.1%} confidence)")
61
+ print(f"All probabilities:")
62
+ for label, prob in result['all_probs'].items():
63
+ print(f" {label:8s}: {prob:.1%}")
64
+
65
+ print("\n" + "="*60)
66
+
67
+ if __name__ == "__main__":
68
+ main()
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:67ca5c56c69fbfdf560aa932f6e6fc29ee86006e81ba2e839e86a28337f36034
3
+ size 437961724
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "mask_token": "[MASK]",
49
+ "model_max_length": 512,
50
+ "never_split": null,
51
+ "pad_token": "[PAD]",
52
+ "sep_token": "[SEP]",
53
+ "strip_accents": null,
54
+ "tokenize_chinese_chars": true,
55
+ "tokenizer_class": "BertTokenizer",
56
+ "unk_token": "[UNK]"
57
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff