Passo-a-passo detalhado do skill, referenciando as fases cognitivas:
1SENSE — Identificar requisitos
```python
texts = [
"Produto excelente, chegou rápido e embalagem perfeita",
"Muito decepcionante, não recomendo para ninguém",
"Produto ok, nada especial",
]
# Identificar idioma predominante e granularidade necessária
```
2CONTEXTUALIZE — Selecionar modelo
| Caso de Uso | Modelo Recomendado |
|------------|-------------------|
| PT-BR reviews | HeyLucasLeao/bert-base-portuguese-cased-finetuned-sentiment |
| Multilingual | cardiffnlp/twitter-xlm-roberta-base-sentiment |
| Fine-grained (1-5) | nlptown/bert-base-multilingual-uncased-sentiment |
| Zero-shot | GPT-4o-mini com structured output |
3RECOMMEND — Pipeline Hugging Face
```python
from transformers import pipeline
import torch
# Carregar modelo (auto-detecta GPU se disponível)
sentiment = pipeline(
"text-classification",
model="cardiffnlp/twitter-xlm-roberta-base-sentiment",
device=0 if torch.cuda.is_available() else -1,
truncation=True,
max_length=512,
)
def analyze_batch(texts: list[str], batch_size: int = 32):
results = sentiment(texts, batch_size=batch_size)
return [
{
"text": text[:100] + "..." if len(text) > 100 else text,
"label": r["label"].lower(), # positive/negative/neutral
"confidence": round(r["score"], 4),
}
for text, r in zip(texts, results)
]
results = analyze_batch(texts)
for r in results:
print(f"{r['label']:8} ({r['confidence']:.0%}) — {r['text'][:60]}")
```
4RECOMMEND — API endpoint (FastAPI)
```python
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class SentimentRequest(BaseModel):
text: str
@app.post("/analyze")
async def analyze(req: SentimentRequest):
result = sentiment(req.text[:512])[0]
return {"label": result["label"].lower(), "confidence": result["score"]}
```
5EVALUATE — Validar com casos difíceis
```python
edge_cases = [
"Não recomendo", # negação
"Ótimo, veio com defeito", # ironia
"...", # texto mínimo
"A" * 1000, # texto muito longo
]
for text in edge_cases:
result = sentiment(text[:512])[0]
print(f"'{text[:40]}' → {result['label']} ({result['score']:.0%})")
```
6REFLECT — Documentar e monitorar
Calcular precision/recall/F1 com dataset rotulado do domínio
Configurar monitoramento de data drift: distribuição de sentimentos no tempo
Reportar telemetria via mcp-skillschain