UBC-NLP / GreenLLaMA-7b

huggingface.co
Total runs: 13
24-hour runs: 0
7-day runs: 0
30-day runs: 0
Model's Last Updated: February 28 2024
text-generation

Introduction of GreenLLaMA-7b

Model Details of GreenLLaMA-7b

GreenLLaMA-7B



This model card corresponds to the GreenLLaMA-7B detoxification model based on LLaMA-2 . The model is finetuned with Chain-of-Thought (CoT) explanation.

Paper : GreenLLaMA: A Framework for Detoxification with Explanations

Authors : Md Tawkat Islam Khondaker, Muhammad Abdul-Mageed, Laks V.S. Lakshmanan

Model Information

Summary description and brief definition of inputs and outputs.

Description

GreenLLaMA is the first comprehensive end-to-end detoxification framework trained on cross-platform pseudo-parallel corpus. GreenLLaMA further introduces explanation to promote transparency and trustworthiness. The framework also demonstrates robustness against adversarial toxicity.

Usage

Below we share some code snippets on how to get quickly started with running the model. First make sure to pip install -U transformers accelerate bitsandbytes , then copy the snippet from the section that is relevant for your usecase.

Running the model on a CPU
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "UBC-NLP/GreenLLaMA-7b"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

prompt = "Rewrite the following toxic input into non-toxic version. Let's break the input down step by step to rewrite the non-toxic version. You should first think about the expanation of why the input text is toxic. Then generate the detoxic output. You must preserve the original meaning as much as possible.\nInput: "

input = "Those shithead should stop talking and get the f*ck out of this place"
input_text = prompt+input+"\n"

input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids, do_sample=False)
print(tokenizer.decode(outputs[0]))
Running the model on a single / multi GPU
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "UBC-NLP/GreenLLaMA-7b"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")


prompt = "Rewrite the following toxic input into non-toxic version. Let's break the input down step by step to rewrite the non-toxic version. You should first think about the expanation of why the input text is toxic. Then generate the detoxic output. You must preserve the original meaning as much as possible.\nInput: "

input = "Those shithead should stop talking and get the f*ck out of this place"
input_text = prompt+input+"\n"

input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids, do_sample=False)
print(tokenizer.decode(outputs[0]))
Running the model on a GPU using different precisions
  • Using torch.float16
# pip install accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "UBC-NLP/GreenLLaMA-7b"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16)

prompt = "Rewrite the following toxic input into non-toxic version. Let's break the input down step by step to rewrite the non-toxic version. You should first think about the expanation of why the input text is toxic. Then generate the detoxic output. You must preserve the original meaning as much as possible.\nInput: "

input = "Those shithead should stop talking and get the f*ck out of this place"
input_text = prompt+input+"\n"

input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids, do_sample=False)
print(tokenizer.decode(outputs[0]))
  • Using torch.bfloat16
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "UBC-NLP/GreenLLaMA-7b"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.bfloat16)

prompt = "Rewrite the following toxic input into non-toxic version. Let's break the input down step by step to rewrite the non-toxic version. You should first think about the expanation of why the input text is toxic. Then generate the detoxic output. You must preserve the original meaning as much as possible.\nInput: "

input = "Those shithead should stop talking and get the f*ck out of this place"
input_text = prompt+input+"\n"

input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids, do_sample=False)
print(tokenizer.decode(outputs[0]))
Quantized Versions through bitsandbytes
  • Using 8-bit precision (int8)
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(load_in_8bit=True)

model_name = "UBC-NLP/GreenLLaMA-7b"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=quantization_config)

prompt = "Rewrite the following toxic input into non-toxic version. Let's break the input down step by step to rewrite the non-toxic version. You should first think about the expanation of why the input text is toxic. Then generate the detoxic output. You must preserve the original meaning as much as possible.\nInput: "

input = "Those shithead should stop talking and get the f*ck out of this place"
input_text = prompt+input+"\n"

input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids, do_sample=False)
print(tokenizer.decode(outputs[0]))
  • Using 4-bit precision
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(load_in_4bit=True)

model_name = "UBC-NLP/GreenLLaMA-7b"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=quantization_config)

prompt = "Rewrite the following toxic input into non-toxic version. Let's break the input down step by step to rewrite the non-toxic version. You should first think about the expanation of why the input text is toxic. Then generate the detoxic output. You must preserve the original meaning as much as possible.\nInput: "

input = "Those shithead should stop talking and get the f*ck out of this place"
input_text = prompt+input+"\n"

input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids, do_sample=False)
print(tokenizer.decode(outputs[0]))
Model Data

The model is trained on cross-platform pseudo-parallel detoxification corpus generated using ChatGPT.

Usage and Limitations

These models have certain limitations that users should be aware of.

Intended Usage

The intended use of GreenLLaMA is for the detoxification tasks. We aim to help researchers to build an end-to-end complete detoxification framework. GreenLLaMA can also be regarded as a promising baseline to develop more robust and effective detoxification frameworks.

Limitations
  • Data Generation Process: This work uses ChatGPT, a gpt-3.5-turbo version from June, 2023. Since the model can be updated on a regular interval, the data generation process should be treated accordingly.
  • Data Quality: GreenLLaMA proposes an automated data generation pipeline to create a pseudo-parallel cross-platform corpus. The synthetic data generation process involves multi-stage data processing without the necessity of direct human inspection. Although this automated pipeline makes the overall data generation process scalable, it comes at the risk of allowing low-quality data in our cross-platform corpus. Hence, human inspection is recommended to remove any sort of potential vulnerability and maintain a standard quality of the corpus.
  • Model Responses: Although GreenLLaMA exhibits impressive ability in generating detoxified responses, we believe there is still room for improvement for the model in terms of producing meaning-preserved detoxified outcomes. Moreover, the models can sometimes be vulnerable to implicit, adversarial tokens and continue to produce toxic content. Therefore, we recommend that GreenLLaMA should be couched with caution before deployment.
Ethical Considerations and Risks

The development of large language models (LLMs) raises several ethical concerns. In creating an open model, we have carefully considered the following:

  • Data Collection and Release: We compile datasets from a wide range of platforms. To ensure proper credit assignment, we refer users to the original publications in our paper. We create the cross-platform detoxification corpus for academic research purposes. We intend to share the corpus in the future. We would also like to mention that some content are generated using GPT-4 for illustration purposes.
  • Potential Misuse and Bias: GreenLLaMA can potentially be misused to generate toxic and biased content. For these reasons, we recommend that GreenLLaMA not be used in applications without careful prior consideration of potential misuse and bias.
Citation

If you use GreenLLaMA for your scientific publication, or if you find the resources in this repository useful, please cite our paper as follows:

@inproceedings{Khondaker2024GreenLLaMA,
  title={GreenLLaMA: A Framework for Detoxification with Explanations},
  author={Md. Tawkat Islam Khondaker and Muhammad Abdul-Mageed and Laks V. S. Lakshmanan},
  year={2024},
  url={https://arxiv.org/abs/2402.15951}
}

Runs of UBC-NLP GreenLLaMA-7b on huggingface.co

13
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs

More Information About GreenLLaMA-7b huggingface.co Model

More GreenLLaMA-7b license Visit here:

https://choosealicense.com/licenses/llama2

GreenLLaMA-7b huggingface.co

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

GreenLLaMA-7b huggingface.co Url

https://huggingface.co/UBC-NLP/GreenLLaMA-7b

UBC-NLP GreenLLaMA-7b online free

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

UBC-NLP GreenLLaMA-7b online free url in huggingface.co:

https://huggingface.co/UBC-NLP/GreenLLaMA-7b

GreenLLaMA-7b install

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

GreenLLaMA-7b install url in huggingface.co:

https://huggingface.co/UBC-NLP/GreenLLaMA-7b

Url of GreenLLaMA-7b

GreenLLaMA-7b huggingface.co Url

Provider of GreenLLaMA-7b huggingface.co

UBC-NLP
ORGANIZATIONS

Other API from UBC-NLP

huggingface.co

Total runs: 129.6K
Run Growth: 66.5K
Growth Rate: 51.31%
Updated:March 31 2022
huggingface.co

Total runs: 32.8K
Run Growth: 16.0K
Growth Rate: 48.67%
Updated:August 17 2022
huggingface.co

Total runs: 4.2K
Run Growth: -1.7K
Growth Rate: -40.87%
Updated:April 24 2024
huggingface.co

Total runs: 3.1K
Run Growth: -968
Growth Rate: -31.82%
Updated:May 17 2024
huggingface.co

Total runs: 1.9K
Run Growth: 0
Growth Rate: 0.00%
Updated:November 11 2025
huggingface.co

Total runs: 1.8K
Run Growth: 703
Growth Rate: 39.76%
Updated:August 14 2024
huggingface.co

Total runs: 1.6K
Run Growth: 169
Growth Rate: 10.94%
Updated:January 20 2022
huggingface.co

Total runs: 1.6K
Run Growth: 0
Growth Rate: 0.00%
Updated:February 20 2024
huggingface.co

Total runs: 1.3K
Run Growth: 0
Growth Rate: 0.00%
Updated:January 22 2025
huggingface.co

Total runs: 1.2K
Run Growth: 249
Growth Rate: 20.56%
Updated:March 10 2026
huggingface.co

Total runs: 277
Run Growth: -59
Growth Rate: -19.47%
Updated:February 13 2026
huggingface.co

Total runs: 222
Run Growth: 180
Growth Rate: 81.08%
Updated:February 13 2026
huggingface.co

Total runs: 108
Run Growth: -23
Growth Rate: -21.30%
Updated:November 26 2024
huggingface.co

Total runs: 87
Run Growth: 41
Growth Rate: 47.13%
Updated:March 14 2025
huggingface.co

Total runs: 73
Run Growth: 0
Growth Rate: 0.00%
Updated:June 10 2022
huggingface.co

Total runs: 25
Run Growth: 2
Growth Rate: 8.00%
Updated:August 31 2021
huggingface.co

Total runs: 16
Run Growth: -6
Growth Rate: -37.50%
Updated:November 26 2024
huggingface.co

Total runs: 7
Run Growth: -4
Growth Rate: -57.14%
Updated:December 04 2023
huggingface.co

Total runs: 6
Run Growth: 0
Growth Rate: 0.00%
Updated:June 03 2022
huggingface.co

Total runs: 5
Run Growth: 0
Growth Rate: 0.00%
Updated:June 03 2022
huggingface.co

Total runs: 5
Run Growth: -10
Growth Rate: -200.00%
Updated:November 12 2024
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:October 10 2023