Instructions to use igoramf/lora-pt-sentiment-analysis with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use igoramf/lora-pt-sentiment-analysis with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="igoramf/lora-pt-sentiment-analysis")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("igoramf/lora-pt-sentiment-analysis", dtype="auto") - Notebooks
- Google Colab
- Kaggle
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("igoramf/lora-pt-sentiment-analysis", dtype="auto")Quick Links
I trained this model just to learn, using a dataset of product reviews
HYPERPAREMETERS
lr = 1e-3 batch_size = 4 num_epochs = 5 weight_decay = 0.01 LoraConfig: r=4 lora_alpha=32 lora_dropout=0.01 target_modules = ['q_lin']
F1_SCORE = 0.914643
HOW TO USE
from transformers import (
AutoTokenizer,
AutoConfig,
AutoModelForSequenceClassification,
)
from peft import PeftModel, PeftConfig, get_peft_model
model_repo = "igoramf/lora-pt-sentiment-analysis"
config = PeftConfig.from_pretrained(model_repo)
model = AutoModelForSequenceClassification.from_pretrained(
config.base_model_name_or_path,
num_labels=3
)
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
tokenizer.pad_token = tokenizer.eos_token
model = PeftModel.from_pretrained(model, model_repo)
RESULTS
id2c = {0: 'neg', 1:'neutral', 2: 'pos'}
text_list = ["Não gostei da programação da TV hoje, o programa BBB foi muito ruim!!", "Gostei muito do jogo do corinthians hoje", "Que prova dificil", "Baptista é um professor muito legal"]
for text in text_list:
inputs = tokenizer.encode(text, return_tensors="pt")
logits = model(inputs).logits
predictions = torch.argmax(logits)
print(text + " - " + id2c[predictions.tolist()])
## RESULTS:
Não gostei da programação da TV hoje, o programa BBB foi muito ruim!! - neg
Gostei muito do jogo do corinthians hoje - pos
Que prova dificil - neg
Baptista é um professor muito legal - pos
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="igoramf/lora-pt-sentiment-analysis")