hnghiem-nlp/llm_hate

Repository of work at UMD's research on LLM on Hate Speech

1

stars

11

commits

Jupyter Notebook

primary language

Sep 5, 2025

updated

README

Repository for the project "Using LLM to Detect Toxic Content on Social Media"

Abstract

Toxic content on social media is pervasive. Exposure to these content may cause a wide range of negative effects to the audience, ranging from discomfor to severe mental trauma. In this work, we investigate the effectivenss of Large Language Models (LLMs) and their emergent capabilities to detect and explain toxic content. We perform SFT finetuning on synthetic Chain of Thought data and observe that these techniques improve LLama 2 7B up to 15% over the untrained baseline. Results also show that this method outperforms existing architectures, such as HateBERT.

Data

For the list of data sources used in this project, view Data/create_dataset_config.ipynb.
These datasets are opensourced and can be retrieved from their respective repository.

Code

This project uses Python 3.10. Use the requirements.txt file to isntall dependencies.

  • To load and save model, modify the model name, path and location in the script Model/script_to_save_model.py

  • To finetune base model, use Code/Job_scripts/run_finetune_base.job . Remember to change the dataset and model appropriately.

  • To finetune with in-domain data, that is, those training samples taken from the train portion of the Test sources, use
    Code/Job_scripts/run_finetune_indomain.job

  • For inference, select one of the following modes dependent on use case \

    • Code/Job_scripts/run_base_inference.job for native (non-LoRA) inference without explanation.
  • For inference with the Peft Adapters, use the following scripts

    • Code/Job_scripts/run_peft_inference_base.job for inference to obtain baselines.
    • Code/Job_scripts/run_peft_inference_indomain.job for inference with in-domain sample from certain source.
    • Code/Job_scripts/run_peft_inference_sequential.job for inference with multiple models/checkpoints in a sequential manner (batch).

If you use this repo, please star and cite using:

@misc{AuthorYear,
  author = {Nghiem, Huy},
  title = {LLM Toxic Speech Detection},
  year = {2023},
  publisher = {GitHub},
  howpublished = {\url{https://github.com/hnghiem-usc/llm_hate}},
}

Contributors

hnghiem-nlp

11 commits

hnghiem-nlp/llm_hate

Repository of work at UMD's research on LLM on Hate Speech

1

stars

11

commits

Jupyter Notebook

primary language

Sep 5, 2025

updated

README

Repository for the project "Using LLM to Detect Toxic Content on Social Media"

Abstract

Toxic content on social media is pervasive. Exposure to these content may cause a wide range of negative effects to the audience, ranging from discomfor to severe mental trauma. In this work, we investigate the effectivenss of Large Language Models (LLMs) and their emergent capabilities to detect and explain toxic content. We perform SFT finetuning on synthetic Chain of Thought data and observe that these techniques improve LLama 2 7B up to 15% over the untrained baseline. Results also show that this method outperforms existing architectures, such as HateBERT.

Data

For the list of data sources used in this project, view Data/create_dataset_config.ipynb.
These datasets are opensourced and can be retrieved from their respective repository.

Code

This project uses Python 3.10. Use the requirements.txt file to isntall dependencies.

  • To load and save model, modify the model name, path and location in the script Model/script_to_save_model.py

  • To finetune base model, use Code/Job_scripts/run_finetune_base.job . Remember to change the dataset and model appropriately.

  • To finetune with in-domain data, that is, those training samples taken from the train portion of the Test sources, use
    Code/Job_scripts/run_finetune_indomain.job

  • For inference, select one of the following modes dependent on use case \

    • Code/Job_scripts/run_base_inference.job for native (non-LoRA) inference without explanation.
  • For inference with the Peft Adapters, use the following scripts

    • Code/Job_scripts/run_peft_inference_base.job for inference to obtain baselines.
    • Code/Job_scripts/run_peft_inference_indomain.job for inference with in-domain sample from certain source.
    • Code/Job_scripts/run_peft_inference_sequential.job for inference with multiple models/checkpoints in a sequential manner (batch).

If you use this repo, please star and cite using:

@misc{AuthorYear,
  author = {Nghiem, Huy},
  title = {LLM Toxic Speech Detection},
  year = {2023},
  publisher = {GitHub},
  howpublished = {\url{https://github.com/hnghiem-usc/llm_hate}},
}

Contributors

hnghiem-nlp

11 commits

Languages

Jupyter Notebook

82.3%

Python

14.5%

Shell

3.2%