Spaces:
No application file
No application file
Create deteccao_sentimentos_em_texto.ipynb
Browse files
deteccao_sentimentos_em_texto.ipynb
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
2 |
+
from optimum.intel.openvino import OVModelForSequenceClassification
|
3 |
+
|
4 |
+
# Carregar modelo da Hugging Face
|
5 |
+
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
|
8 |
+
# Converter para TinyML usando Optimum e OpenVINO
|
9 |
+
ov_model = OVModelForSequenceClassification.from_pretrained(model_name, export=True)
|
10 |
+
|
11 |
+
# Tokenizar texto de entrada
|
12 |
+
text = "I love TinyML!"
|
13 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
14 |
+
|
15 |
+
# Inferência no modelo otimizado
|
16 |
+
outputs = ov_model(**inputs)
|
17 |
+
sentiment = "Positive" if outputs.logits.argmax() == 1 else "Negative"
|
18 |
+
print("Sentiment:", sentiment)
|