File size: 727 Bytes
f61ccfd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from optimum.intel.openvino import OVModelForSequenceClassification

# Carregar modelo da Hugging Face
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Converter para TinyML usando Optimum e OpenVINO
ov_model = OVModelForSequenceClassification.from_pretrained(model_name, export=True)

# Tokenizar texto de entrada
text = "I love TinyML!"
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)

# Inferência no modelo otimizado
outputs = ov_model(**inputs)
sentiment = "Positive" if outputs.logits.argmax() == 1 else "Negative"
print("Sentiment:", sentiment)