Update README.md
Browse files
README.md
CHANGED
|
@@ -45,7 +45,7 @@ import torch
|
|
| 45 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 46 |
from peft import PeftModel
|
| 47 |
|
| 48 |
-
#
|
| 49 |
base_model = "google/gemma-2b"
|
| 50 |
adapter_repo = "indrajeet77/sentiment-analyzer"
|
| 51 |
|
|
@@ -60,7 +60,7 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 60 |
model = PeftModel.from_pretrained(model, adapter_repo)
|
| 61 |
|
| 62 |
|
| 63 |
-
#
|
| 64 |
def get_sentiment(text):
|
| 65 |
# We use "Few-Shot Prompting" to force the model to give a one-word answer
|
| 66 |
prompt = f"""Classify the sentiment as positive, negative, or neutral.
|
|
@@ -88,7 +88,7 @@ Sentiment:"""
|
|
| 88 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 89 |
return response.strip().lower()
|
| 90 |
|
| 91 |
-
#
|
| 92 |
print("Model Loaded. Testing...")
|
| 93 |
text = "The product quality is amazing"
|
| 94 |
print(f"Text: {text}")
|
|
|
|
| 45 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 46 |
from peft import PeftModel
|
| 47 |
|
| 48 |
+
# 1. Load Model & Adapter
|
| 49 |
base_model = "google/gemma-2b"
|
| 50 |
adapter_repo = "indrajeet77/sentiment-analyzer"
|
| 51 |
|
|
|
|
| 60 |
model = PeftModel.from_pretrained(model, adapter_repo)
|
| 61 |
|
| 62 |
|
| 63 |
+
# 2. Inference Function
|
| 64 |
def get_sentiment(text):
|
| 65 |
# We use "Few-Shot Prompting" to force the model to give a one-word answer
|
| 66 |
prompt = f"""Classify the sentiment as positive, negative, or neutral.
|
|
|
|
| 88 |
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 89 |
return response.strip().lower()
|
| 90 |
|
| 91 |
+
# 3. Run It
|
| 92 |
print("Model Loaded. Testing...")
|
| 93 |
text = "The product quality is amazing"
|
| 94 |
print(f"Text: {text}")
|