Hate-speech-CNERG/hatexplain
Updated • 2.87k • 22
How to use tum-nlp/bert-hateXplain with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="tum-nlp/bert-hateXplain") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("tum-nlp/bert-hateXplain")
model = AutoModelForSequenceClassification.from_pretrained("tum-nlp/bert-hateXplain")# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("tum-nlp/bert-hateXplain")
model = AutoModelForSequenceClassification.from_pretrained("tum-nlp/bert-hateXplain")The model is based on BERT and used for classifying a text as toxic and non-toxic. It achieved an F1 score of 0.81 and an Accuracy of 0.77.
The model was fine-tuned on the HateXplain dataset found here: https://huggingface.co/datasets/hatexplain
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained('tum-nlp/bert-hateXplain')
model = AutoModelForSequenceClassification.from_pretrained('tum-nlp/bert-hateXplain')
# Create the pipeline for classification
hate_classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
# Predict
hate_classifier("I like you. I love you")
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="tum-nlp/bert-hateXplain")