Downloads · 30 days
0
sangngoc27042001/TinyLlama-sentiment-classification
TinyLlama-sentiment-classification is a text generation model from sangngoc27042001. Use it when you need the model to write or continue text. The card lists the license as other.
This model was trained using AutoTrain. For more information, please visit AutoTrain.
Downloads · 30 days
0
Access
Public
Updated Jan 23, 2024
Repo size
27.6 MB
Likes
0
Public
Click a slice to open those files.
.pt18.1 MB · 44%
From the Hugging Face model README
This model was trained using AutoTrain. For more information, please visit AutoTrain.
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
import transformers
adapters_name = os.environ['REPO_ID']
model_name = os.environ['MODEL_NAME'] #"mistralai/Mistral-7B-Instruct-v0.1"
device = "cuda" # the device to load the model onto
bnb_config = transformers.BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
model = AutoModelForCausalLM.from_pretrained(
model_name,
load_in_4bit=True,
torch_dtype=torch.bfloat16,
quantization_config=bnb_config,
device_map='auto'
)
model = PeftModel.from_pretrained(model, adapters_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
tokenizer.bos_token_id = 1
stop_token_ids = [0]
print(f"Successfully loaded the model {model_name} into memory")
text = """<|system|>
Classify the sentence of user into those classes: negative, positive, no_impact, mixed</s>
<|user|>
I love you so much</s>
<|assistant|>
"""
encoded = tokenizer(text, return_tensors="pt", add_special_tokens=False)
model_input = encoded
model.to(device)
generated_ids = model.generate(**model_input, max_new_tokens=5, do_sample=True, temperature = 0.1)
decoded = tokenizer.batch_decode(generated_ids)
print(decoded[0])