justtherightsize
commited on
Commit
·
e72d0f2
1
Parent(s):
e3b1f67
Upload README.md
Browse files
README.md
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
# For reference on model card metadata, see the spec: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
|
3 |
+
# Doc / guide: https://huggingface.co/docs/hub/model-cards
|
4 |
+
license: mit
|
5 |
+
language:
|
6 |
+
- cs
|
7 |
+
---
|
8 |
+
# Model Card for small-e-czech-2stage-supportive-interactions-cs
|
9 |
+
|
10 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
11 |
+
|
12 |
+
This model is fine-tuned for 2nd stage multi-label text classification of Supportive Interactions in Instant Messenger dialogs of Adolescents - it expects inputs where at least one of the classes appears.
|
13 |
+
|
14 |
+
## Model Description
|
15 |
+
|
16 |
+
The model was fine-tuned on a dataset of Instant Messenger dialogs of Adolescents. The classification is 2stage and the model outputs probablities for labels {0,1,2,3,4}:
|
17 |
+
|
18 |
+
0. Informational Support
|
19 |
+
1. Emotional Support
|
20 |
+
2. Social Companionship
|
21 |
+
3. Appraisal
|
22 |
+
4. Instrumental Support
|
23 |
+
|
24 |
+
- **Developed by:** Anonymous
|
25 |
+
- **Language(s):** cs
|
26 |
+
- **Finetuned from:** small-e-czech
|
27 |
+
|
28 |
+
## Model Sources
|
29 |
+
|
30 |
+
<!-- Provide the basic links for the model. -->
|
31 |
+
|
32 |
+
- **Repository:** https://github.com/justtherightsize/supportive-interactions-and-risks
|
33 |
+
- **Paper:** Stay tuned!
|
34 |
+
|
35 |
+
## Usage
|
36 |
+
Here is how to use this model to classify a context-window of a dialogue:
|
37 |
+
|
38 |
+
```python
|
39 |
+
import numpy as np
|
40 |
+
import torch
|
41 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
42 |
+
|
43 |
+
# Prepare input texts. This model is pretrained on multi-lingual data
|
44 |
+
# and fine-tuned on English
|
45 |
+
test_texts = ['Utterance1;Utterance2;Utterance3']
|
46 |
+
|
47 |
+
# Load the model and tokenizer
|
48 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
49 |
+
'justtherightsize/small-e-czech-2stage-supportive-interactions-cs', num_labels=5).to("cuda")
|
50 |
+
|
51 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
52 |
+
'justtherightsize/small-e-czech-2stage-supportive-interactions-cs',
|
53 |
+
use_fast=False, truncation_side='left')
|
54 |
+
assert tokenizer.truncation_side == 'left'
|
55 |
+
|
56 |
+
# Define helper functions
|
57 |
+
def predict_one(text: str, tok, mod, threshold=0.5):
|
58 |
+
encoding = tok(text, return_tensors="pt", truncation=True, padding=True,
|
59 |
+
max_length=256)
|
60 |
+
encoding = {k: v.to(mod.device) for k, v in encoding.items()}
|
61 |
+
outputs = mod(**encoding)
|
62 |
+
logits = outputs.logits
|
63 |
+
sigmoid = torch.nn.Sigmoid()
|
64 |
+
probs = sigmoid(logits.squeeze().cpu())
|
65 |
+
predictions = np.zeros(probs.shape)
|
66 |
+
predictions[np.where(probs >= threshold)] = 1
|
67 |
+
return predictions, probs
|
68 |
+
|
69 |
+
def print_predictions(texts):
|
70 |
+
preds = [predict_one(tt, tokenizer, model) for tt in texts]
|
71 |
+
for c, p in preds:
|
72 |
+
print(f'{c}: {p.tolist():.4f}')
|
73 |
+
|
74 |
+
# Run the prediction
|
75 |
+
print_predictions(test_texts)
|
76 |
+
```
|