BART-TweetDetox / README.md
radwa-f's picture
Update README.md
c393bd9 verified
metadata
language: en
license: apache-2.0
tags:
  - text-generation
  - bart
  - detoxification
  - text-transformation
  - style-transfer
base_model: facebook/bart-large
datasets:
  - paradetox
metrics:
  - bleu
  - rouge
library_name: transformers
pipeline_tag: text-generation

BART Tweet Detoxification

Fine-tuned BART model for converting toxic text into neutral/polite versions while preserving semantic meaning.

Model Description

This model performs text-to-text transformation to detoxify toxic language. It takes potentially offensive or toxic text as input and generates a neutral, polite version while maintaining the original semantic content.

Key Features:

  • Converts toxic tweets to neutral language
  • Preserves semantic meaning
  • Maintains fluency and naturalness
  • Trained with prompt engineering techniques

Intended Uses

Primary Use Cases:

  • Content moderation assistance
  • Educational tools for communication
  • Text sanitization for public platforms
  • Research in NLP and text transformation

Out of Scope:

  • Should not be used as sole content moderation tool
  • Not intended for censorship purposes
  • Requires human review for production use

How to Use

from transformers import pipeline

detoxifier = pipeline(
    "text-generation",
    model="radwa-f/bart-tweet-detoxification"
)

toxic_text = "You're such an idiot for thinking that!"
result = detoxifier(toxic_text, max_length=128)

print(result[0]['generated_text'])
# Output: "I respectfully disagree with your perspective on that."

Alternative usage with AutoModel:

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

tokenizer = AutoTokenizer.from_pretrained("radwa-f/bart-tweet-detoxification")
model = AutoModelForSeq2SeqLM.from_pretrained("radwa-f/bart-tweet-detoxification")

toxic_text = "You're such an idiot for thinking that!"
inputs = tokenizer(toxic_text, return_tensors="pt", max_length=128, truncation=True)
outputs = model.generate(**inputs, max_length=128, num_beams=5, early_stopping=True)

detoxified = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(detoxified)

Training Details

Training Data

  • Dataset: ParaDetox
  • Description: Parallel corpus of toxic and neutral text pairs
  • Preprocessing: Text cleaning and normalization
  • Language: English

Training Procedure

  • Base Model: facebook/bart-large (or facebook/bart-base - confirm which you used)
  • Task: Sequence-to-sequence generation for text style transfer
  • Prompt Engineering: Applied controlled generation techniques
  • Framework: PyTorch + Hugging Face Transformers

Hardware:

  • GPU: Google Colab A100 GPU
  • Training Time: 30 min

Hyperparameters

  • Optimizer: AdamW
  • Learning Rate: 2e-5
  • Batch Size: 16
  • Epochs: 3
  • Max Length: 128 tokens

Evaluation

The model is evaluated on:

  • Semantic Similarity: How well meaning is preserved
  • Fluency: Naturalness of generated text
  • Detoxification Rate: Reduction in toxic language
  • BLEU Score: Translation quality metric
  • ROUGE Score: Text overlap metric

Limitations

  • May occasionally alter semantic meaning significantly
  • Performance varies with highly context-dependent toxicity
  • Training data biases may affect outputs
  • Not 100% accurate - requires human oversight
  • Works best with English text similar to training distribution

Ethical Considerations

This model is a research tool and should be used responsibly:

  • Not a replacement for human moderation
  • May reflect biases from training data
  • Should be tested thoroughly before production use
  • Users should be aware of limitations
  • Consider privacy and consent when processing user-generated content

Model Creators

Radwa Fattouhi

Amine Boktaya

Citation

If you use this model, please cite:

@misc{fattouhi2025detox,
  author = {Fattouhi, Radwa and Boktaya, Amine},
  title = {BART Tweet Detoxification},
  year = {2025},
  publisher = {Hugging Face},
  howpublished = {\url{https://huggingface.co/radwa-f/BART-TweetDetox}}
}

Model Card Authors

Radwa Fattouhi

Related Work

Published research: AgriAlertX - SoftwareX (Elsevier)


Model card last updated: December 2025