Downloads · 30 days
0
julisses/ecoicop-pt-cnn
ecoicop-pt-cnn is a machine learning model from julisses. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This model classifies short product titles (product + brand) into 71 ECOICOP food-and-beverage categories in Portuguese. It was trained on a manually verified dataset collected from six major Portuguese retailers.
Downloads · 30 days
0
Access
Public
Updated May 31, 2025
Repo size
41.8 MB
Likes
0
Public
Click a slice to open those files.
.pt41.1 MB · 98%
From the Hugging Face model README
This model classifies short product titles (product + brand) into 71 ECOICOP food-and-beverage categories in Portuguese.
It was trained on a manually verified dataset collected from six major Portuguese retailers.
| Feature | Details |
|---|---|
| Architecture | PyTorch feed-forward neural network (1 hidden layer, ReLU, dropout 0.3) |
| Vectorizer | CountVectorizer (1- & 2-grams, top 20 000 features) |
| Input | Product + brand string (e.g. "Iogurte natural Danone") |
| Output | ECOICOP category name (71 classes) |
| Language | Portuguese (PT-PT) |
| Metric | Value |
|---|---|
| Accuracy | 0.97 |
| Macro F1 | 0.92 |
pip install torch joblib scikit-learn huggingface_hub
import torch, joblib, torch.nn as nn
from huggingface_hub import hf_hub_download
# ── Same architecture used during training ──
class SimpleCNN(nn.Module):
def __init__(self, input_dim, num_classes):
super().__init__()
self.fc1 = nn.Linear(input_dim, 512)
self.relu = nn.ReLU()
self.dropout = nn.Dropout(0.3)
self.fc2 = nn.Linear(512, num_classes)
def forward(self, x):
x = self.fc1(x)
x = self.relu(x)
x = self.dropout(x)
return self.fc2(x)
repo_id = "julisses/ecoicop-pt-cnn"
# Download vectorizer, label encoder and weights
vectorizer = joblib.load(hf_hub_download(repo_id, "vectorizer.pkl"))
label_encoder = joblib.load(hf_hub_download(repo_id, "label_encoder.pkl"))
state_dict = torch.load(hf_hub_download(repo_id, "model.pt"), map_location="cpu")
# Re-create and load the network
model = SimpleCNN(len(vectorizer.get_feature_names_out()), len(label_encoder.classes_))
model.load_state_dict(state_dict)
model.eval()
def predict_ecoicop(text: str) -> str:
X = vectorizer.transform([text]).toarray()
with torch.no_grad():
idx = model(torch.tensor(X, dtype=torch.float32)).argmax(1).item()
return label_encoder.inverse_transform([idx])[0]
# Example
print(predict_ecoicop("Queijo Mini Original, Cheddar e Emmental Babybel"))
# ➜ Queijo e requeijão