RyanDDD commited on
Commit
1a1073f
·
verified ·
1 Parent(s): 59c78a2

Upload AnnoMI BERT model for Motivational Interviewing talk classification

Browse files
README.md ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ tags:
5
+ - text-classification
6
+ - motivational-interviewing
7
+ - bert
8
+ - mental-health
9
+ - counseling
10
+ - psychology
11
+ datasets:
12
+ - AnnoMI
13
+ metrics:
14
+ - accuracy
15
+ - f1
16
+ - precision
17
+ - recall
18
+ widget:
19
+ - text: "I really want to quit smoking."
20
+ example_title: "Change Talk"
21
+ - text: "I don't know if I can do this."
22
+ example_title: "Neutral"
23
+ - text: "I like smoking, it helps me relax."
24
+ example_title: "Sustain Talk"
25
+ ---
26
+
27
+ # BERT for Motivational Interviewing Client Talk Classification
28
+
29
+ ## Model Description
30
+
31
+ This model is a fine-tuned **BERT-base-uncased** model for classifying client utterances in **Motivational Interviewing (MI)** conversations.
32
+
33
+ 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.
34
+
35
+ ## Intended Use
36
+
37
+ - **Primary Use**: Classify client statements in motivational interviewing dialogues
38
+ - **Applications**:
39
+ - Counselor training and feedback
40
+ - MI session analysis
41
+ - Automated dialogue systems
42
+ - Mental health research
43
+
44
+ ## Training Data
45
+
46
+ The model was trained on the **AnnoMI dataset** (Annotated Motivational Interviewing), which contains expert-annotated counseling dialogues.
47
+
48
+ - **Training samples**: ~2,400 utterances
49
+ - **Validation samples**: ~500 utterances
50
+ - **Test samples**: ~700 utterances
51
+
52
+ ## Labels
53
+
54
+ The model classifies client talk into three categories:
55
+
56
+ - **0**: change
57
+ - **1**: neutral
58
+ - **2**: sustain
59
+
60
+ ### Label Definitions
61
+
62
+ - **Change Talk**: Client statements expressing desire, ability, reasons, or need for change
63
+ - Example: "I really want to quit smoking" or "I think I can do it"
64
+
65
+ - **Neutral**: General responses without clear indication of change or sustain
66
+ - Example: "I don't know" or "Maybe"
67
+
68
+ - **Sustain Talk**: Client statements expressing reasons for maintaining current behavior
69
+ - Example: "I like smoking, it helps me relax"
70
+
71
+ ## Performance
72
+
73
+ ### Test Set Metrics
74
+
75
+ - **Accuracy**: 70.1%
76
+ - **Macro F1**: 57.9%
77
+ - **Macro Precision**: 59.3%
78
+ - **Macro Recall**: 57.3%
79
+
80
+ ### Confusion Matrix
81
+
82
+ ```
83
+ Predicted
84
+ change neutral sustain
85
+ Actual change 75 78 23
86
+ neutral 43 396 27
87
+ sustain 11 34 36
88
+ ```
89
+
90
+ **Note**: The model performs best on the "neutral" class (most frequent), and has room for improvement on "change" and "sustain" classes.
91
+
92
+ ## Usage
93
+
94
+ ### Quick Start
95
+
96
+ ```python
97
+ from transformers import BertTokenizer, BertForSequenceClassification
98
+ import torch
99
+
100
+ # Load model and tokenizer
101
+ model_name = "RyanDDD/bert-motivational-interviewing"
102
+ tokenizer = BertTokenizer.from_pretrained(model_name)
103
+ model = BertForSequenceClassification.from_pretrained(model_name)
104
+
105
+ # Predict
106
+ text = "I really want to quit smoking. It's been affecting my health."
107
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
108
+
109
+ with torch.no_grad():
110
+ outputs = model(**inputs)
111
+ probs = torch.softmax(outputs.logits, dim=1)
112
+ pred = torch.argmax(probs, dim=1)
113
+
114
+ label_map = model.config.id2label
115
+ print(f"Talk type: {label_map[pred.item()]}")
116
+ print(f"Confidence: {probs[0][pred].item():.2%}")
117
+ ```
118
+
119
+ ### Batch Prediction
120
+
121
+ ```python
122
+ texts = [
123
+ "I want to stop drinking.",
124
+ "I don't think I have a problem.",
125
+ "I like drinking with my friends."
126
+ ]
127
+
128
+ inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True, max_length=128)
129
+
130
+ with torch.no_grad():
131
+ outputs = model(**inputs)
132
+ probs = torch.softmax(outputs.logits, dim=1)
133
+ preds = torch.argmax(probs, dim=1)
134
+
135
+ for text, pred, prob in zip(texts, preds, probs):
136
+ label = model.config.id2label[pred.item()]
137
+ confidence = prob[pred].item()
138
+ print(f"Text: {text}")
139
+ print(f"Type: {label} ({confidence:.1%})")
140
+ print()
141
+ ```
142
+
143
+ ## Training Details
144
+
145
+ ### Hyperparameters
146
+
147
+ - **Base model**: `bert-base-uncased`
148
+ - **Max sequence length**: 128 tokens
149
+ - **Batch size**: 16
150
+ - **Learning rate**: 2e-5
151
+ - **Epochs**: 5
152
+ - **Optimizer**: AdamW
153
+ - **Loss**: Cross-entropy
154
+
155
+ ### Hardware
156
+
157
+ Trained on a single GPU (NVIDIA GPU recommended).
158
+
159
+ ## Limitations
160
+
161
+ 1. **Class Imbalance**: The model performs better on "neutral" (majority class) than "change" and "sustain"
162
+ 2. **Context**: The model classifies single utterances without conversation context
163
+ 3. **Domain**: Trained specifically on MI conversations; may not generalize to other counseling types
164
+ 4. **Language**: English only
165
+
166
+ ## Ethical Considerations
167
+
168
+ - This model is intended to **assist**, not replace, human counselors
169
+ - Predictions should be reviewed by qualified professionals
170
+ - Privacy and confidentiality must be maintained when processing real counseling data
171
+ - Be aware of potential biases in training data
172
+
173
+ ## Citation
174
+
175
+ If you use this model, please cite:
176
+
177
+ ```bibtex
178
+ @misc{bert-mi-classifier-2024,
179
+ author = {Ryan},
180
+ title = {BERT for Motivational Interviewing Client Talk Classification},
181
+ year = {2024},
182
+ publisher = {HuggingFace},
183
+ howpublished = {\url{https://huggingface.co/RyanDDD/bert-motivational-interviewing}}
184
+ }
185
+ ```
186
+
187
+ ## References
188
+
189
+ - **AnnoMI Dataset**: [GitHub](https://github.com/uccollab/AnnoMI)
190
+ - **BERT Paper**: [Devlin et al., 2019](https://arxiv.org/abs/1810.04805)
191
+ - **Motivational Interviewing**: [Miller & Rollnick, 2012](https://motivationalinterviewing.org/)
192
+
193
+ ## Model Card Contact
194
+
195
+ 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,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Example usage of the Motivational Interviewing BERT classifier
3
+ """
4
+
5
+ from transformers import BertTokenizer, BertForSequenceClassification
6
+ import torch
7
+
8
+ def predict_talk_type(text, model, tokenizer):
9
+ """Predict the talk type for a given text"""
10
+ inputs = tokenizer(
11
+ text,
12
+ return_tensors="pt",
13
+ padding=True,
14
+ truncation=True,
15
+ max_length=128
16
+ )
17
+
18
+ with torch.no_grad():
19
+ outputs = model(**inputs)
20
+ probs = torch.softmax(outputs.logits, dim=1)
21
+ pred = torch.argmax(probs, dim=1)
22
+
23
+ label = model.config.id2label[pred.item()]
24
+ confidence = probs[0][pred].item()
25
+
26
+ return {
27
+ 'label': label,
28
+ 'confidence': confidence,
29
+ 'all_probs': {
30
+ model.config.id2label[i]: probs[0][i].item()
31
+ for i in range(len(probs[0]))
32
+ }
33
+ }
34
+
35
+ def main():
36
+ # Load model and tokenizer
37
+ model_name = "RyanDDD/bert-motivational-interviewing"
38
+ print(f"Loading model: {model_name}")
39
+
40
+ tokenizer = BertTokenizer.from_pretrained(model_name)
41
+ model = BertForSequenceClassification.from_pretrained(model_name)
42
+
43
+ # Example texts
44
+ examples = [
45
+ "I really want to quit smoking for my health.",
46
+ "I'm not sure if I can do this.",
47
+ "Smoking helps me deal with stress.",
48
+ "Maybe I should try cutting down.",
49
+ "I've been thinking about quitting.",
50
+ "I like smoking, it's part of who I am."
51
+ ]
52
+
53
+ print("\nPredictions:\n" + "="*60)
54
+
55
+ for text in examples:
56
+ result = predict_talk_type(text, model, tokenizer)
57
+
58
+ print(f"\nText: {text}")
59
+ print(f"Type: {result['label']} ({result['confidence']:.1%} confidence)")
60
+ print(f"All probabilities:")
61
+ for label, prob in result['all_probs'].items():
62
+ print(f" {label:8s}: {prob:.1%}")
63
+
64
+ print("\n" + "="*60)
65
+
66
+ if __name__ == "__main__":
67
+ 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