Views
No views yet
1#!pip install transformers
2
3from transformers import AutoModelForSequenceClassification, AutoTokenizer, TextClassificationPipeline
4
5model_path = "ankekat1000/toxic-bert-german"
6tokenizer = AutoTokenizer.from_pretrained(model_path)
7model = AutoModelForSequenceClassification.from_pretrained(model_path)
8
9pipeline = TextClassificationPipeline(model=model, tokenizer=tokenizer)
10print(pipeline('du bist blöd.'))1
2df['result'] = df['comment_text'].apply(lambda x: pipeline(x[:512])) #Cuts after max. legth of tokens for this model, which is 512 for this model.
3# Afterwards, you can make two new columns out of the column "result", one including the label, one including the score.
4df['toxic_label'] = df['result'].str[0].str['label']
5df['score'] = df['result'].str[0].str['score']| Label | Precision | Recall | F1 | Nr. comments in test set |
|---|---|---|---|---|
| not toxic | 0.94 | 0.94 | 0.91 | 1094 |
| toxic | 0.68 | 0.53 | 0.59 | 274 |