CoolFace
Modelpublic

innerCircuit/llama3-sentiment-Cell-Phones-Accessories-3class-baseline-150k

sourceHugging Facellama3.1updated 10mo agoView on Hugging Face
0likes15downloads
Model Card

LLaMA 3.1-8B Sentiment Analysis: Cell Phones and Accessories

Fine-tuned LLaMA 3.1-8B-Instruct for sentiment analysis on Amazon product reviews.

Model Description

This model is a QLoRA fine-tuned version of meta-llama/Llama-3.1-8B-Instruct for 3-class (negative/neutral/positive) sentiment classification on Amazon Cell Phones and Accessories reviews.

Training Configuration

ParameterValue
Base Modelmeta-llama/Llama-3.1-8B-Instruct
Training PhaseBaseline
CategoryCell Phones and Accessories
Classification3-class
Training Samples150,000
Epochs1
Sequence Length384 tokens
LoRA Rank (r)128
LoRA Alpha32
Quantization4-bit NF4
AttentionSDPA

Performance Metrics

Overall

MetricScore
Accuracy0.7412 (74.12%)
Macro Precision0.7659
Macro Recall0.7391
Macro F10.7211

Per-Class

ClassPrecisionRecallF1
Negative0.61950.94380.7480
Neutral0.74880.38010.5042
Positive0.92940.89350.9111

Confusion Matrix

              Pred Neg  Pred Neu  Pred Pos
True Neg       1579        80        14
True Neu        921       626       100
True Pos         49       130      1501

Usage

python
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

# Load model
base_model = AutoModelForCausalLM.from_pretrained(
    "meta-llama/Llama-3.1-8B-Instruct",
    torch_dtype=torch.bfloat16,
    device_map="auto"
)
model = PeftModel.from_pretrained(base_model, "innerCircuit/llama3-sentiment-Cell-Phones-Accessories-3class-baseline-150k")
tokenizer = AutoTokenizer.from_pretrained("innerCircuit/llama3-sentiment-Cell-Phones-Accessories-3class-baseline-150k")

# Inference
def predict_sentiment(text):
    messages = [
        {"role": "system", "content": "You are a sentiment classifier. Classify as negative, neutral, or positive. Respond with one word."},
        {"role": "user", "content": text}
    ]
    inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
    outputs = model.generate(inputs, max_new_tokens=5, do_sample=False)
    return tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True).strip()

# Example
print(predict_sentiment("This product is amazing! Best purchase ever."))
# Output: positive

Training Data

AttributeValue
DatasetAmazon Reviews 2023
CategoryCell Phones and Accessories
Training Samples150,000
Evaluation Samples15,000
Class BalanceEqual samples per sentiment class

Research Context

This model is part of a research project investigating LLM poisoning attacks, based on methodologies from Souly et al. (2025). The fine-tuned baseline establishes performance benchmarks prior to introducing adversarial samples.

References

  • —Souly, A., Rando, J., et al. (2025). Poisoning attacks on LLMs require a near-constant number of poison samples. arXiv:2510.07192
  • —Hou, Y., et al. (2024). Bridging Language and Items for Retrieval and Recommendation. arXiv:2403.03952

Citation

bibtex
@misc{llama3-sentiment-Cell-Phones-Accessories-baseline,
  author = {Govinda Reddy, Akshay},
  title = {LLaMA 3.1 Sentiment Analysis for Amazon Reviews},
  year = {2024},
  publisher = {HuggingFace},
  howpublished = {\url{https://huggingface.co/innerCircuit/llama3-sentiment-Cell-Phones-Accessories-3class-baseline-150k}}
}

License

This model is released under the Llama 3.1 Community License.


Generated: 2025-12-13 03:34:21 UTC