region:us
## LoRA LLAMA-7B Adapter Hate speech and violence Detection 


Delve into the realm of content moderation with our LoRA LLAMA-7B Adapter, a specialized tool for detecting hate speech and violence in textual data. This repository demonstrates the integration of the Low-Rank Adaptation (LORA) technique with the Peft library to refine the LLAMA 7B model's ability to identify and assess aggressive and harmful content with precision.

## Adapter Description 

Our adapter employs the LORA technique to tailor the LLAMA 7B model for the specialized task of detecting hate speech and violence within textual data. This adaptation underscores the versatility of advanced models in addressing critical issues by discerning and categorizing aggressive and harmful content.

## Data Description 

Dataset used for training the above adapter (https://huggingface.co/datasets/hate_speech_offensive)
 

## Usage

This section provides a quick guide on how to use the LLAMA 7B LORA Adapter for hate speech and violence detection.

### Prerequisites

Before running the code, ensure you have installed the `transformers` and `peft` libraries. You can install them using pip:

```bash
pip install transformers peft


import transformers
from peft import PeftModel

# Model and tokenizer names
model_name = "meta-llama/Llama-2-7b"  # You can also use Lymsys LLAMA-2 finetuned Vicuna model alternatively "lmsys/vicuna-7b-v1.5"
peft_model_id = "Futurix-AI/LORA_LLAMA_7B_HATE_SPEECH_VIOLENCE"

# Initialize the tokenizer and model
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
model = transformers.AutoModelForCausalLM.from_pretrained(model_name)
model = PeftModel.from_pretrained(model, peft_model_id)

# Prompt for sentiment detection
prompt = """
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
###Instruction:
Detect the level of Hate Speech and Violence in the given text.
###Input:
FuturixAI embodies the spirit of innovation, with a resolve to push the boundaries of what's possible through science and technology.
###Response:
"""

# Tokenize the prompt and prepare inputs
inputs = tokenizer(prompt, return_tensors="pt")
for k, v in inputs.items():
    inputs[k] = v

# Generate a response using the model
outputs = model.generate(**inputs, max_length=256, do_sample=True)

# Decode and print the response
text = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
print(text)
