Commit ·
edb5051
1
Parent(s): 38dc201
Upload README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-multi-label-online-risks-cs
|
| 9 |
+
|
| 10 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
| 11 |
+
|
| 12 |
+
This model is fine-tuned for multi-label text classification of Online Risks in Instant Messenger dialogs of Adolescents.
|
| 13 |
+
|
| 14 |
+
## Model Description
|
| 15 |
+
|
| 16 |
+
The model was fine-tuned on a dataset of Instant Messenger dialogs of Adolescents. The classification is multi-label and the model outputs probablities for labels {0,1,2,3,4,5}:
|
| 17 |
+
|
| 18 |
+
0. None
|
| 19 |
+
1. Aggression, Harassing, Hate
|
| 20 |
+
2. Mental Health Problems
|
| 21 |
+
3. Alcohol, Drugs
|
| 22 |
+
4. Weight Loss, Diets
|
| 23 |
+
5. Sexual Content
|
| 24 |
+
|
| 25 |
+
- **Developed by:** Anonymous
|
| 26 |
+
- **Language(s):** cs
|
| 27 |
+
- **Finetuned from:** small-e-czech
|
| 28 |
+
|
| 29 |
+
## Model Sources
|
| 30 |
+
|
| 31 |
+
<!-- Provide the basic links for the model. -->
|
| 32 |
+
|
| 33 |
+
- **Repository:** https://github.com/justtherightsize/supportive-interactions-and-risks
|
| 34 |
+
- **Paper:** Stay tuned!
|
| 35 |
+
|
| 36 |
+
## Usage
|
| 37 |
+
Here is how to use this model to classify a context-window of a dialogue:
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
import numpy as np
|
| 41 |
+
import torch
|
| 42 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 43 |
+
|
| 44 |
+
# Prepare input texts. This model is pretrained on multi-lingual data
|
| 45 |
+
# and fine-tuned on English
|
| 46 |
+
test_texts = ['Utterance1;Utterance2;Utterance3']
|
| 47 |
+
|
| 48 |
+
# Load the model and tokenizer
|
| 49 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 50 |
+
'justtherightsize/small-e-czech-multi-label-online-risks-cs', num_labels=6).to("cuda")
|
| 51 |
+
|
| 52 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 53 |
+
'justtherightsize/small-e-czech-multi-label-online-risks-cs',
|
| 54 |
+
use_fast=False, truncation_side='left')
|
| 55 |
+
assert tokenizer.truncation_side == 'left'
|
| 56 |
+
|
| 57 |
+
# Define helper functions
|
| 58 |
+
def predict_one(text: str, tok, mod, threshold=0.5):
|
| 59 |
+
encoding = tok(text, return_tensors="pt", truncation=True, padding=True,
|
| 60 |
+
max_length=256)
|
| 61 |
+
encoding = {k: v.to(mod.device) for k, v in encoding.items()}
|
| 62 |
+
outputs = mod(**encoding)
|
| 63 |
+
logits = outputs.logits
|
| 64 |
+
sigmoid = torch.nn.Sigmoid()
|
| 65 |
+
probs = sigmoid(logits.squeeze().cpu())
|
| 66 |
+
predictions = np.zeros(probs.shape)
|
| 67 |
+
predictions[np.where(probs >= threshold)] = 1
|
| 68 |
+
return predictions, probs
|
| 69 |
+
|
| 70 |
+
def print_predictions(texts):
|
| 71 |
+
preds = [predict_one(tt, tokenizer, model) for tt in texts]
|
| 72 |
+
for c, p in preds:
|
| 73 |
+
print(f'{c}: {p.tolist():.4f}')
|
| 74 |
+
|
| 75 |
+
# Run the prediction
|
| 76 |
+
print_predictions(test_texts)
|
| 77 |
+
```
|