Instructions to use indrajeet77/sentiment-analyzer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use indrajeet77/sentiment-analyzer with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("google/gemma-2b") model = PeftModel.from_pretrained(base_model, "indrajeet77/sentiment-analyzer") - Transformers
How to use indrajeet77/sentiment-analyzer with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="indrajeet77/sentiment-analyzer")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("indrajeet77/sentiment-analyzer", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use indrajeet77/sentiment-analyzer with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "indrajeet77/sentiment-analyzer" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "indrajeet77/sentiment-analyzer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/indrajeet77/sentiment-analyzer
- SGLang
How to use indrajeet77/sentiment-analyzer with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "indrajeet77/sentiment-analyzer" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "indrajeet77/sentiment-analyzer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "indrajeet77/sentiment-analyzer" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "indrajeet77/sentiment-analyzer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use indrajeet77/sentiment-analyzer with Docker Model Runner:
docker model run hf.co/indrajeet77/sentiment-analyzer
Model Card for sentiment-analyzer
This model is a Fine-tuned LoRA (Low-Rank Adaptation) adapter for Google's Gemma-2b, specifically designed for Sentiment Analysis.
Model Details
Model Description
This is a PEFT (Parameter-Efficient Fine-Tuning) adapter capable of analyzing text sentiment. It was trained using the LoRA method on top of the google/gemma-2b base model. It is designed to be lightweight and efficient while retaining the capabilities of the base model.
- Developed by: Indrajeet Pimpalgaonkar (indrajeet77)
- Model type: LoRA Adapter for Causal Language Modeling
- Language(s) (NLP): English
- License: Apache-2.0 (Inherited from Gemma)
- Finetuned from model: google/gemma-2b
Model Sources
Uses
Direct Use
The model is intended for analyzing the sentiment of input text (e.g., classifying text as Positive, Negative, or Neutral) or generating sentiment-aware responses.
How to Get Started with the Model
You can load this model using the peft and transformers libraries. Since this is a LoRA adapter, you must load the base model first.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# 1. Load Model & Adapter
base_model = "google/gemma-2b"
adapter_repo = "indrajeet77/sentiment-analyzer"
tokenizer = AutoTokenizer.from_pretrained(base_model)
model = AutoModelForCausalLM.from_pretrained(
base_model,
device_map="auto",
torch_dtype=torch.float16
)
model = PeftModel.from_pretrained(model, adapter_repo)
# 2. Inference Function
def get_sentiment(text):
# We use "Few-Shot Prompting" to force the model to give a one-word answer
prompt = f"""Classify the sentiment as positive, negative, or neutral.
Text: The movie was terrible and boring.
Sentiment: negative
Text: I am so happy with this result!
Sentiment: positive
Text: {text}
Sentiment:"""
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=2,
do_sample=False,
pad_token_id=tokenizer.eos_token_id
)
# Decode and clean the output
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
return response.strip().lower()
# 3. Run It
print("Model Loaded. Testing...")
text = "The product quality is amazing"
print(f"Text: {text}")
print(f"Prediction: {get_sentiment(text)}")
- Downloads last month
- 1
Model tree for indrajeet77/sentiment-analyzer
Base model
google/gemma-2b
docker model run hf.co/indrajeet77/sentiment-analyzer