Text Classification
Transformers
Safetensors
English
distilbert
fine-tuned
24-679
text-embeddings-inference
Instructions to use jackstev/hw2-distilbert-garment-type with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jackstev/hw2-distilbert-garment-type with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="jackstev/hw2-distilbert-garment-type")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("jackstev/hw2-distilbert-garment-type") model = AutoModelForSequenceClassification.from_pretrained("jackstev/hw2-distilbert-garment-type", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- README.md +92 -0
- config.json +42 -0
- confusion_matrix.png +0 -0
- model.safetensors +3 -0
- probe_confusion.png +0 -0
- tokenizer.json +0 -0
- tokenizer_config.json +15 -0
- training_curve.png +0 -0
README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: distilbert-base-uncased
|
| 4 |
+
library_name: transformers
|
| 5 |
+
pipeline_tag: text-classification
|
| 6 |
+
datasets:
|
| 7 |
+
- leixiang25/24679-hw1-text-garments
|
| 8 |
+
language:
|
| 9 |
+
- en
|
| 10 |
+
tags:
|
| 11 |
+
- text-classification
|
| 12 |
+
- fine-tuned
|
| 13 |
+
- 24-679
|
| 14 |
+
metrics:
|
| 15 |
+
- accuracy
|
| 16 |
+
- f1
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# DistilBERT Garment Type Classifier
|
| 20 |
+
|
| 21 |
+
Homework 2, Problem 3.
|
| 22 |
+
|
| 23 |
+
## What it does
|
| 24 |
+
|
| 25 |
+
Reads a short product-style clothing description and predicts the garment type:
|
| 26 |
+
|
| 27 |
+
| Label | Type |
|
| 28 |
+
|---|---|
|
| 29 |
+
| 0 | top |
|
| 30 |
+
| 1 | bottom |
|
| 31 |
+
| 2 | outerwear |
|
| 32 |
+
| 3 | dress |
|
| 33 |
+
| 4 | footwear |
|
| 34 |
+
|
| 35 |
+
## Data
|
| 36 |
+
|
| 37 |
+
- Source: [leixiang25/24679-hw1-text-garments](https://huggingface.co/datasets/leixiang25/24679-hw1-text-garments), revision `49d58b5a0942`. A classmate wrote 100 original descriptions (~190 characters each) from retail product photos.
|
| 38 |
+
- Splits used as published: train = 70 originals + 1,289 noisy copies (character swaps/deletions, word swaps, WordNet synonyms), validation = 15 originals, test = 15 originals, 3 per class in each holdout. No original crosses splits.
|
| 39 |
+
- Preprocessing: DistilBERT uncased tokenizer, max length 64 tokens, dynamic padding. No other cleaning, so the model also sees the typo copies during training.
|
| 40 |
+
|
| 41 |
+
## Training
|
| 42 |
+
|
| 43 |
+
- Base: `distilbert-base-uncased`, full fine-tune with a new 5-way head. Every weight is updated, which is what AutoGluon calls `optim.peft = None`; the partial options (`bit_fit`, `norm_fit`) were not needed with this much text.
|
| 44 |
+
- Up to 6 epochs, learning rate 5e-5 with linear decay and 10% warmup, batch size 16, weight decay 0.01, seed 24679, mixed precision on GPU.
|
| 45 |
+
- Early stopping on validation loss with patience 2. Kept epoch 1 of 3.
|
| 46 |
+
- Compute: Tesla T4, 35 s of training.
|
| 47 |
+
|
| 48 |
+
## Results
|
| 49 |
+
|
| 50 |
+
| Split | Accuracy | Macro F1 | Errors |
|
| 51 |
+
|---|---:|---:|---:|
|
| 52 |
+
| Validation (15) | 1.000 | 1.000 | 0 |
|
| 53 |
+
| Test (15) | 1.000 | 1.000 | 0 |
|
| 54 |
+
|
| 55 |
+
Per-class on test:
|
| 56 |
+
|
| 57 |
+
| Class | Precision | Recall | F1 |
|
| 58 |
+
|---|---:|---:|---:|
|
| 59 |
+
| top | 1.00 | 1.00 | 1.00 |
|
| 60 |
+
| bottom | 1.00 | 1.00 | 1.00 |
|
| 61 |
+
| outerwear | 1.00 | 1.00 | 1.00 |
|
| 62 |
+
| dress | 1.00 | 1.00 | 1.00 |
|
| 63 |
+
| footwear | 1.00 | 1.00 | 1.00 |
|
| 64 |
+
|
| 65 |
+
**Stress test:** with the garment noun replaced by "item" in the 30 validation and test descriptions, accuracy is **0.833** (macro F1 0.792). The gap between this and the normal score shows how much the model relies on the noun itself. Confusion matrices for both are in the repo.
|
| 66 |
+
|
| 67 |
+
## Limitations
|
| 68 |
+
|
| 69 |
+
- 15 test examples is very small; one error is 6.7 points of accuracy.
|
| 70 |
+
- The descriptions all follow the same listing template written by one person, and the garment noun nearly gives away the answer. Expect worse results on real, messier product listings.
|
| 71 |
+
- Only 5 broad types. Edge cases follow the author's labels (for example, a jumpsuit counts as a dress, a zip pullover as outerwear).
|
| 72 |
+
- The noisy copies are not independent examples.
|
| 73 |
+
|
| 74 |
+
## Ethics
|
| 75 |
+
|
| 76 |
+
The texts are the dataset author's own fictional product descriptions with no brands or personal data. The model is not meant for anything beyond coursework.
|
| 77 |
+
|
| 78 |
+
## How to use
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
from transformers import pipeline
|
| 82 |
+
clf = pipeline("text-classification", model="jackstev/hw2-distilbert-garment-type")
|
| 83 |
+
clf("Relaxed crewneck sweatshirt in heather gray fleece, with dropped shoulders and ribbed cuffs.")
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
## License
|
| 87 |
+
|
| 88 |
+
Apache 2.0, the same as the DistilBERT base model. The dataset card assigns no license, so check with its author before reusing the data.
|
| 89 |
+
|
| 90 |
+
## AI usage disclosure
|
| 91 |
+
|
| 92 |
+
I used Claude (Anthropic) to help write this notebook and draft this model card. I chose the dataset, ran the training, and checked the results and the card against the outputs.
|
config.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"activation": "gelu",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"DistilBertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_dropout": 0.1,
|
| 7 |
+
"bos_token_id": null,
|
| 8 |
+
"dim": 768,
|
| 9 |
+
"dropout": 0.1,
|
| 10 |
+
"dtype": "float32",
|
| 11 |
+
"eos_token_id": null,
|
| 12 |
+
"hidden_dim": 3072,
|
| 13 |
+
"id2label": {
|
| 14 |
+
"0": "top",
|
| 15 |
+
"1": "bottom",
|
| 16 |
+
"2": "outerwear",
|
| 17 |
+
"3": "dress",
|
| 18 |
+
"4": "footwear"
|
| 19 |
+
},
|
| 20 |
+
"initializer_range": 0.02,
|
| 21 |
+
"label2id": {
|
| 22 |
+
"bottom": 1,
|
| 23 |
+
"dress": 3,
|
| 24 |
+
"footwear": 4,
|
| 25 |
+
"outerwear": 2,
|
| 26 |
+
"top": 0
|
| 27 |
+
},
|
| 28 |
+
"max_position_embeddings": 512,
|
| 29 |
+
"model_type": "distilbert",
|
| 30 |
+
"n_heads": 12,
|
| 31 |
+
"n_layers": 6,
|
| 32 |
+
"pad_token_id": 0,
|
| 33 |
+
"problem_type": "single_label_classification",
|
| 34 |
+
"qa_dropout": 0.1,
|
| 35 |
+
"seq_classif_dropout": 0.2,
|
| 36 |
+
"sinusoidal_pos_embds": false,
|
| 37 |
+
"tie_weights_": true,
|
| 38 |
+
"tie_word_embeddings": true,
|
| 39 |
+
"transformers_version": "5.16.1",
|
| 40 |
+
"use_cache": false,
|
| 41 |
+
"vocab_size": 30522
|
| 42 |
+
}
|
confusion_matrix.png
ADDED
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:69107faaf0c4eb2ae4d8dba86a1307ec3877bccc70c8cf45bb3d757493548f82
|
| 3 |
+
size 267841796
|
probe_confusion.png
ADDED
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"do_lower_case": true,
|
| 5 |
+
"is_local": false,
|
| 6 |
+
"local_files_only": false,
|
| 7 |
+
"mask_token": "[MASK]",
|
| 8 |
+
"model_max_length": 512,
|
| 9 |
+
"pad_token": "[PAD]",
|
| 10 |
+
"sep_token": "[SEP]",
|
| 11 |
+
"strip_accents": null,
|
| 12 |
+
"tokenize_chinese_chars": true,
|
| 13 |
+
"tokenizer_class": "BertTokenizer",
|
| 14 |
+
"unk_token": "[UNK]"
|
| 15 |
+
}
|
training_curve.png
ADDED
|