File size: 2,596 Bytes
e72d0f2 |
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 71 72 73 74 75 76 |
---
# 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-2stage-supportive-interactions-cs
<!-- Provide a quick summary of what the model is/does. -->
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.
## Model Description
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}:
0. Informational Support
1. Emotional Support
2. Social Companionship
3. Appraisal
4. Instrumental Support
- **Developed by:** Anonymous
- **Language(s):** cs
- **Finetuned from:** 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
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
# Prepare input texts. This model is pretrained on multi-lingual data
# and fine-tuned on English
test_texts = ['Utterance1;Utterance2;Utterance3']
# Load the model and tokenizer
model = AutoModelForSequenceClassification.from_pretrained(
'justtherightsize/small-e-czech-2stage-supportive-interactions-cs', num_labels=5).to("cuda")
tokenizer = AutoTokenizer.from_pretrained(
'justtherightsize/small-e-czech-2stage-supportive-interactions-cs',
use_fast=False, truncation_side='left')
assert tokenizer.truncation_side == 'left'
# Define helper functions
def predict_one(text: str, tok, mod, threshold=0.5):
encoding = tok(text, return_tensors="pt", truncation=True, padding=True,
max_length=256)
encoding = {k: v.to(mod.device) for k, v in encoding.items()}
outputs = mod(**encoding)
logits = outputs.logits
sigmoid = torch.nn.Sigmoid()
probs = sigmoid(logits.squeeze().cpu())
predictions = np.zeros(probs.shape)
predictions[np.where(probs >= threshold)] = 1
return predictions, probs
def print_predictions(texts):
preds = [predict_one(tt, tokenizer, model) for tt in texts]
for c, p in preds:
print(f'{c}: {p.tolist():.4f}')
# Run the prediction
print_predictions(test_texts)
``` |