Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: bsd-3-clause
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
pipeline_tag: text-classification
|
6 |
+
tags:
|
7 |
+
- psychology
|
8 |
+
- cognitive distortions
|
9 |
+
widget:
|
10 |
+
- text: "He is my best friend, and we have known each other since childhood."
|
11 |
+
example_title: "No Distortion"
|
12 |
+
- text: "I can't believe I forgot to do that, I'm such an idiot."
|
13 |
+
example_title: "Personalization"
|
14 |
+
- text: "I feel like I'm always disappointing others."
|
15 |
+
example_title: "Emotional Reasoning"
|
16 |
+
- text: "All doctors are arrogant and don't really care about their patients."
|
17 |
+
example_title: "Overgeneralizing"
|
18 |
+
- text: "It's bad for their little baby ear."
|
19 |
+
example_title: "Labeling"
|
20 |
+
- text: "She must never make any mistakes in her work."
|
21 |
+
example_title: "Should Statements"
|
22 |
+
- text: "If I don't finish this project on time, my boss will fire me."
|
23 |
+
example_title: "Catastrophizing"
|
24 |
+
- text: "If I keep working hard, they will eventually give me a raise."
|
25 |
+
example_title: "Reward Fallacy"
|
26 |
+
---
|
27 |
+
|
28 |
+
# Classification of Cognitive Distortions using Bert
|
29 |
+
|
30 |
+
## Problem Description
|
31 |
+
|
32 |
+
**Cognitive distortion** refers to patterns of biased or distorted thinking that can lead to negative emotions, behaviors, and beliefs. These distortions are often automatic and unconscious, and can affect a person's perception of reality and their ability to make sound judgments.
|
33 |
+
|
34 |
+
Some common types of cognitive distortions include:
|
35 |
+
|
36 |
+
1. **Personalization**: Blaming oneself for things that are outside of one's control.
|
37 |
+
|
38 |
+
*Examples:*
|
39 |
+
- *She looked at me funny, she must be judging me.*
|
40 |
+
- *I can't believe I made that mistake, I'm such a screw up.*
|
41 |
+
|
42 |
+
2. **Emotional Reasoning**: Believing that feelings are facts, and letting emotions drive one's behavior.
|
43 |
+
|
44 |
+
*Examples:*
|
45 |
+
- *I feel like I'm not good enough, so I must be inadequate.*
|
46 |
+
- *They never invite me out, so they must not like me.*
|
47 |
+
|
48 |
+
3. **Overgeneralizing**: Drawing broad conclusions based on a single incident or piece of evidence.
|
49 |
+
|
50 |
+
*Examples:*
|
51 |
+
- *He never listens to me, he just talks over me.*
|
52 |
+
- *Everyone always ignores my needs.*
|
53 |
+
|
54 |
+
4. **Labeling**: Attaching negative or extreme labels to oneself or others based on specific behaviors or traits.
|
55 |
+
|
56 |
+
*Examples:*
|
57 |
+
- *I'm such a disappointment.*
|
58 |
+
- *He's a total jerk.*
|
59 |
+
|
60 |
+
5. **Should Statements**: Rigid, inflexible thinking that is based on unrealistic or unattainable expectations of oneself or others.
|
61 |
+
|
62 |
+
*Examples:*
|
63 |
+
- *I must never fail at anything.*
|
64 |
+
- *They have to always put others' needs before their own.*
|
65 |
+
|
66 |
+
6. **Catastrophizing**: Assuming the worst possible outcome in a situation and blowing it out of proportion.
|
67 |
+
|
68 |
+
*Examples:*
|
69 |
+
- *It's all going to be a waste of time, they're never going to succeed.*
|
70 |
+
- *If I don't get the promotion, my entire career is over.*
|
71 |
+
|
72 |
+
7. **Reward Fallacy**: Belief that one should be rewarded or recognized for every positive action or achievement.
|
73 |
+
|
74 |
+
*Examples:*
|
75 |
+
- *If I work hard enough, they will give me the pay raise I want.*
|
76 |
+
- *If they don't appreciate my contributions, I'll start slacking off.*
|
77 |
+
|
78 |
+
## Model Description
|
79 |
+
|
80 |
+
This is one of the smaller BERT variants, pretrained model on English language using a masked language modeling objective. BERT was introduced in [this paper](https://arxiv.org/abs/1810.04805) and first released in [this repository](https://github.com/google-research/bert).
|
81 |
+
|
82 |
+
## Data Description
|
83 |
+
|
84 |
+
[In progress]
|
85 |
+
|
86 |
+
## Using
|
87 |
+
|
88 |
+
Example of single-label classification:
|
89 |
+
|
90 |
+
```python
|
91 |
+
import torch
|
92 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
93 |
+
|
94 |
+
tokenizer = AutoTokenizer.from_pretrained("amedvedev/bert-tiny-cognitive-bias")
|
95 |
+
model = AutoModelForSequenceClassification.from_pretrained("amedvedev/bert-tiny-cognitive-bias")
|
96 |
+
|
97 |
+
inputs = tokenizer("He must never disappoint anyone.", return_tensors="pt")
|
98 |
+
with torch.no_grad():
|
99 |
+
logits = model(**inputs).logits
|
100 |
+
|
101 |
+
predicted_class_id = logits.argmax().item()
|
102 |
+
model.config.id2label[predicted_class_id]
|
103 |
+
```
|
104 |
+
|
105 |
+
## Metrics
|
106 |
+
|
107 |
+
Model accuracy by labels:
|
108 |
+
|
109 |
+
| | Precision | Recall | F1 |
|
110 |
+
|:-------------------:|:---------:|:------:|:----:|
|
111 |
+
| No Distortion | 0.84 | 0.74 | 0.79 |
|
112 |
+
| Personalization | 0.86 | 0.89 | 0.87 |
|
113 |
+
| Emotional Reasoning | 0.88 | 0.96 | 0.92 |
|
114 |
+
| Overgeneralizing | 0.80 | 0.88 | 0.84 |
|
115 |
+
| Labeling | 0.84 | 0.80 | 0.82 |
|
116 |
+
| Should Statements | 0.88 | 0.95 | 0.91 |
|
117 |
+
| Catastrophizing | 0.88 | 0.86 | 0.87 |
|
118 |
+
| Reward Fallacy | 0.87 | 0.95 | 0.91 |
|
119 |
+
|
120 |
+
Average model accuracy:
|
121 |
+
|
122 |
+
Accuracy | Top-3 Accuracy | Top-5 Accuracy | Precision | Recall | F1 |
|
123 |
+
|:-----------:|:--------------:|:--------------:|:-----------:|:-----------:|:-----------:|
|
124 |
+
| 0.86 ± 0.04 | 0.99 ± 0.01 | 0.99 ± 0.01 | 0.86 ± 0.04 | 0.85 ± 0.04 | 0.85 ± 0.04 |
|
125 |
+
|
126 |
+
## References
|
127 |
+
|
128 |
+
[In progress]
|