File size: 6,307 Bytes
4a00f6a
3ad404e
 
4a00f6a
3ad404e
 
 
 
c338518
 
4c85eec
c338518
3ad404e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c338518
 
3ad404e
aadc26d
3ad404e
aadc26d
 
 
 
 
3ad404e
aadc26d
3ad404e
 
 
 
 
aadc26d
3ad404e
aadc26d
3ad404e
aadc26d
 
 
 
 
3ad404e
aadc26d
 
 
3ad404e
aadc26d
 
 
3ad404e
aadc26d
 
 
3ad404e
aadc26d
 
 
3ad404e
aadc26d
3ad404e
4526f9d
 
aadc26d
4526f9d
 
aadc26d
4526f9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aadc26d
0f59632
7bee2be
784f6ba
 
7bee2be
 
784f6ba
7bee2be
 
 
 
784f6ba
7bee2be
 
 
784f6ba
7bee2be
 
784f6ba
7bee2be
 
 
784f6ba
7bee2be
 
784f6ba
7bee2be
 
784f6ba
7bee2be
 
 
 
784f6ba
7bee2be
 
26d06b9
7bee2be
 
 
 
 
4c85eec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
---
language:
- en
tags:
- text-classification
- e-commerce
- product-classification
- distilbert
license: apache-2.0
datasets:
- Adnan-AI-Labs/products_categories_data
model-index:
- name: DistilBERT-ProductClassifier
  results:
  - task:
      type: text-classification
      name: Product Category Classification
    dataset:
      name: Product Classification and Categorization
      type: lakritidis/product-classification-and-categorization
    metrics:
    - type: accuracy
      value: 96.17
      name: Accuracy
base_model:
- lxs1/DistilBertForSequenceClassification_6h_768dim
- distilbert/distilbert-base-uncased
pipeline_tag: text-classification
---

# Model Card for DistilBERT-ProductClassifier

This is a fine-tuned version of the DistilBERT model, specifically trained for product classification tasks within the e-commerce domain. The model distinguishes between various categories like "CPUs," "Digital Cameras," "Dishwashers," and more, making it useful for organizing and categorizing products in online retail platforms.

## Model Details

### Model Description

The DistilBERT-ProductClassifier model is trained on an e-commerce dataset to classify products into specific categories. It is optimized for efficient text classification tasks and is designed to work well with limited computational resources. This model leverages the compact DistilBERT architecture, making it suitable for real-time applications, including mobile and web environments.

- **Developed by:** Adnan AI Labs
- **Model type:** DistilBERT fine-tuned for text classification
- **Language:** English
- **License:** Apache 2.0
- **Finetuned from model:** [DistilBERT](https://huggingface.co/distilbert-base-uncased)

## Model Sources

- **Repository:** [Adnan-AI-Labs/DistilBERT-ProductClassifier](https://huggingface.co/Adnan-AI-Labs/DistilBERT-ProductClassifier)

## Uses

### Direct Use

The model is intended for classifying products in text-based product listings for e-commerce platforms. Users can use this model to categorize products automatically, reducing the need for manual tagging and improving product discoverability.

### Out-of-Scope Use

This model should not be used for tasks unrelated to product classification or outside the e-commerce context. It is not designed for sentiment analysis, general text generation, or other unrelated NLP tasks.

## Bias, Risks, and Limitations

The model was trained on e-commerce data and may not perform well on products or categories outside the provided training scope. Additionally, some categories may have less representation in the training data, potentially affecting classification accuracy for those classes.

### Recommendations

For use cases involving other languages or highly specialized product categories not included in the training data, further fine-tuning may be necessary. Users should validate the model's output before using it for high-stakes decisions.

## How to Get Started with the Model

Use the code below to get started with the model for product classification:

```python
import torch
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification

# Define the model repository name
model_name = "Adnan-AI-Labs/DistilBERT-ProductClassifier"

# Load the tokenizer and model from the Hugging Face Hub
try:
    # Load tokenizer
    tokenizer = DistilBertTokenizer.from_pretrained(model_name, use_fast=True)

    # Load model, forcing the download to avoid any cached version
    model = DistilBertForSequenceClassification.from_pretrained(model_name)

    print("Model and tokenizer loaded successfully.")

except Exception as e:
    print(f"An error occurred while loading the model: {e}")
    exit()

# Test the model with some sample inputs
sample_texts = [
    "estar s20 single uk sim free mobile phone red",
    "cello c40227dvbt2 40 full hd black led tv",
]

# Prepare the inputs for the model
inputs = tokenizer(sample_texts, padding=True, truncation=True, return_tensors="pt")

# Make predictions
with torch.no_grad():
    outputs = model(**inputs)

# Get the predicted class indices
predictions = torch.argmax(outputs.logits, dim=1)

# Print out the predictions
for text, pred in zip(sample_texts, predictions):
    print(f"Text: {text} \nPredicted Class: {pred.item()}\n")

```

# Training Details
## Training Data
The model was trained on an e-commerce dataset that includes various product categories such as CPUs, Digital Cameras, Dishwashers, Fridge Freezers, Microwaves, Mobile Phones, TVs, and Washing Machines. The data was preprocessed by removing duplicates, lowercasing, and tokenizing text.

## Training Procedure
 1. Preprocessing: Text data was cleaned, lowercased, and tokenized. Product descriptions were truncated to 128 tokens for uniformity.
 2. Hyperparameters: Fine-tuning was conducted with a learning rate of 2e-5 and batch size of 16 for 3 epochs.
 3. Training Hardware: The model was trained on a single NVIDIA Tesla V100 GPU for approximately 3 hours.

## Evaluation
Testing Data, Factors & Metrics
The model was evaluated on a separate test set of product descriptions, using precision, recall, and F1-score as the evaluation metrics.

## Summary
The model achieved an overall accuracy of 96.16%, with strong performance across multiple product categories. The F1-scores indicate that the model performs particularly well in the "CPUs" and "Digital Cameras" categories.

## Technical Specifications
Model Architecture and Objective
The DistilBERT-ProductClassifier model utilizes the DistilBERT architecture, fine-tuned with a text classification head for e-commerce product categorization tasks.

## Compute Infrastructure
The model is optimized to run efficiently on CPUs and small GPUs, making it suitable for real-time applications.

## Hardware
This model requires a minimum of 4GB of RAM for efficient inference, and a modern CPU or basic GPU is recommended.

## Software
Transformers library: v4.26.0
Python version: 3.8 or higher
CUDA [optional]: 10.2 or higher (if running on GPU)

## Citation
If you use this model, please cite as follows:


@misc{distilbert_product_classifier,
  author = {Adnan AI Labs},
  title = {DistilBERT-ProductClassifier for E-commerce},
  year = {2024},
  url = {https://huggingface.co/Adnan-AI-Labs/DistilBERT-ProductClassifier}
}