BenjaminOcampo / peace_cont_bert

huggingface.co
Total runs: 6
24-hour runs: 0
7-day runs: 0
30-day runs: 3
Model's Last Updated: July 31 2024

Introduction of peace_cont_bert

Model Details of peace_cont_bert

This model card documents the demo paper "PEACE: Providing Explanations and Analysis for Combating Hate Expressions" accepted at the 27th European Conference on Artificial Intelligence: https://www.ecai2024.eu/calls/demos .

The Model

This model is a hate speech detector fine-tuned specifically for detecting implicit hate speech. It is based on the paper "PEACE: Providing Explanations and Analysis for Combating Hate Expressions" by Greta Damo, Nicolás Benjamín Ocampo, Elena Cabrio, and Serena Villata, presented at the 27th European Conference on Artificial Intelligence.

Training Parameters and Experimental Info

The model was trained using the ISHate dataset, focusing on implicit data. Training parameters included:

  • Batch size: 32
  • Weight decay: 0.01
  • Epochs: 4
  • Learning rate: 2e-5

For detailed information on the training process, please refer to the model's paper .

Usage

First you might need the transformers version 4.30.2.

pip install transformers==4.30.2

This model was created using pytorch vanilla. In order to load it you have to use the following Model Class.

class ContrastiveModel(nn.Module):
    def __init__(self, model):
        super(ContrastiveModel, self).__init__()
        self.model = model
        self.embedding_dim = model.config.hidden_size
        self.fc = nn.Linear(self.embedding_dim, self.embedding_dim)
        self.classifier = nn.Linear(self.embedding_dim, 2)  # Classification layer

    def forward(self, input_ids, attention_mask):
        outputs = self.model(input_ids, attention_mask)
        embeddings = outputs.last_hidden_state[:, 0]  # Use the CLS token embedding as the representation
        embeddings = self.fc(embeddings)
        logits = self.classifier(embeddings)  # Apply classification layer

        return embeddings, logits

Then, we instantiate the model as:

from transformers import AutoModel, AutoTokenizer, AutoConfig

repo_name = "BenjaminOcampo/peace_cont_bert"

config = AutoConfig.from_pretrained(repo_name)
contrastive_model = ContrastiveModel(AutoModel.from_config(config))
tokenizer = AutoTokenizer.from_pretrained(repo_name)

Finally, to load the weights of the model we do as follows:

model_tmp_file = hf_hub_download(repo_id=repo_name, filename="model.pt", token=read_token)

state_dict = torch.load(model_tmp_file)

contrastive_model.load_state_dict(state_dict)

You can make predictions as any pytorch model:

import torch

text = "Are you sure that Islam is a peaceful religion?"
inputs = tokenizer(text, return_tensors="pt")

with torch.no_grad():
    _, logits = contrastive_model(inputs["input_ids"], inputs["attention_mask"])

probabilities = torch.softmax(logits, dim=1)
_, predicted_labels = torch.max(probabilities, dim=1)

Datasets

The model was trained on the ISHate dataset , specifically the training part of the dataset which focuses on implicit hate speech.

Evaluation Results

The model's performance was evaluated using standard metrics, including F1 score and accuracy. For comprehensive evaluation results, refer to the linked paper.

Authors:

Runs of BenjaminOcampo peace_cont_bert on huggingface.co

6
Total runs
0
24-hour runs
-1
3-day runs
0
7-day runs
3
30-day runs

More Information About peace_cont_bert huggingface.co Model

More peace_cont_bert license Visit here:

https://choosealicense.com/licenses/bsl-1.0

peace_cont_bert huggingface.co

peace_cont_bert huggingface.co is an AI model on huggingface.co that provides peace_cont_bert's model effect (), which can be used instantly with this BenjaminOcampo peace_cont_bert model. huggingface.co supports a free trial of the peace_cont_bert model, and also provides paid use of the peace_cont_bert. Support call peace_cont_bert model through api, including Node.js, Python, http.

BenjaminOcampo peace_cont_bert online free

peace_cont_bert huggingface.co is an online trial and call api platform, which integrates peace_cont_bert's modeling effects, including api services, and provides a free online trial of peace_cont_bert, you can try peace_cont_bert online for free by clicking the link below.

BenjaminOcampo peace_cont_bert online free url in huggingface.co:

https://huggingface.co/BenjaminOcampo/peace_cont_bert

peace_cont_bert install

peace_cont_bert is an open source model from GitHub that offers a free installation service, and any user can find peace_cont_bert on GitHub to install. At the same time, huggingface.co provides the effect of peace_cont_bert install, users can directly use peace_cont_bert installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

peace_cont_bert install url in huggingface.co:

https://huggingface.co/BenjaminOcampo/peace_cont_bert

Url of peace_cont_bert

Provider of peace_cont_bert huggingface.co

BenjaminOcampo
ORGANIZATIONS

Other API from BenjaminOcampo