File size: 2,418 Bytes
60fb936
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
# For reference on model card metadata, see the spec: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
# Doc / guide: https://huggingface.co/docs/hub/model-cards
license: mit
language:
- cs
---
# Model Card for small-e-czech-binary-online-risks-cs

<!-- Provide a quick summary of what the model is/does. -->

This model is fine-tuned for binary text classification of Online Risks in Instant Messenger dialogs of Adolescents in Czech. 

## Model Description

The model was fine-tuned on a dataset of Czech Instant Messenger dialogs of Adolescents. The classification is binary and the model outputs probablities for labels {0,1}: Online Risks present or not.

- **Developed by:** Anonymous
- **Language(s):** cs
- **Finetuned from:** Seznam/small-e-czech

## Model Sources

<!-- Provide the basic links for the model. -->

- **Repository:** https://github.com/justtherightsize/supportive-interactions-and-risks
- **Paper:** Stay tuned!

## Usage
Here is how to use this model to classify a context-window of a dialogue:

```python
import numpy as np
from transformers import AutoTokenizer, AutoModelForSequenceClassification

# Prepare input texts. This model is fine-tuned for Czech
test_texts = ['Utterance1;Utterance2;Utterance3']

# Load the model and tokenizer
model = AutoModelForSequenceClassification.from_pretrained(
    'justtherightsize/small-e-czech-binary-online-risks-cs', num_labels=2).to("cuda")

tokenizer = AutoTokenizer.from_pretrained(
    'justtherightsize/small-e-czech-binary-online-risks-cs',
    use_fast=False, truncation_side='left')
assert tokenizer.truncation_side == 'left'

# Define helper functions
def get_probs(text, tokenizer, model):
    inputs = tokenizer(text, padding=True, truncation=True, max_length=256,
                       return_tensors="pt").to("cuda")
    outputs = model(**inputs)
    return outputs[0].softmax(1)

def preds2class(probs, threshold=0.5):
    pclasses = np.zeros(probs.shape)
    pclasses[np.where(probs >= threshold)] = 1
    return pclasses.argmax(-1)

def print_predictions(texts):
    probabilities = [get_probs(
        texts[i], tokenizer, model).cpu().detach().numpy()[0]
                     for i in range(len(texts))]
    predicted_classes = preds2class(np.array(probabilities))
    for c, p in zip(predicted_classes, probabilities):
        print(f'{c}: {p}')

# Run the prediction
print_predictions(test_texts)
```