--- # LLAMA 7B Sentiment Analysis Adapter Explore the capabilities of sentiment analysis with our LLAMA 7B Sentiment Analysis Adapter. This repository showcases the application of the LORA (Low-Rank Adaptation) technique and the Peft library to enhance the sentiment analysis capabilities of the existing LLAMA 7B model. ## Adapter Description Our adapter applies the LORA technique to the LLAMA 7B model, facilitating improved sentiment analysis. This work demonstrates the potential of adapting advanced models to specific tasks, such as extracting nuanced sentiment from textual data. ## Training Methodology The adapter has been trained using the Amazon Sentiment Review dataset, which includes several million customer reviews from Amazon, each with a corresponding star rating. This training allows the adapter to better understand and interpret a broad range of consumer sentiments. ## Dataset Overview The Amazon Sentiment Review dataset was chosen for its size and its realistic representation of customer feedback. It serves as an excellent basis for training models to perform sentiment analysis in real-world scenarios. ```python 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 = "rudransh2004/FuturixAI-AmazonSentiment-LLAMA7B-LORA" # Initialize the tokenizer and model tokenizer_t5 = transformers.AutoTokenizer.from_pretrained(model_name) model_t5 = transformers.AutoModelForCausalLM.from_pretrained(model_name) model_t5 = PeftModel.from_pretrained(model_t5, 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 sentiment of the tweet. ###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_t5(prompt, return_tensors="pt") for k, v in inputs.items(): inputs[k] = v # Generate a response using the model outputs = model_t5.generate(**inputs, max_length=256, do_sample=True) # Decode and print the response text = tokenizer_t5.batch_decode(outputs, skip_special_tokens=True)[0] print(text)