File size: 4,534 Bytes
0e55a4f | 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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | ---
license: mit
task_categories:
- text-classification
language:
- en
tags:
- accessibility
- wcag
- text-classification
- distilbert
size_categories:
- n<1K
---
# WCAG Accessibility Issues
A small synthetic dataset for experimenting with machine learning classification of accessibility defects against WCAG success criteria.
This project was created as a learning exercise to explore the complete Hugging Face text-classification workflow, including dataset preparation, tokenisation, fine-tuning a pretrained Transformer model, evaluation and inference.
## Dataset
The dataset contains **100 synthetic accessibility defect descriptions** across five WCAG success criteria.
Each class contains 20 examples.
| Label | WCAG success criterion |
|---|---|
| 0 | 1.3.1 Info and Relationships |
| 1 | 2.1.1 Keyboard |
| 2 | 2.4.3 Focus Order |
| 3 | 2.4.7 Focus Visible |
| 4 | 4.1.2 Name, Role, Value |
Example:
```text
Custom radio control does not expose its selected state
```
Label:
```text
4.1.2 Name, Role, Value
```
All examples are synthetic and were created specifically for this project. The dataset does not contain real audit findings or customer data.
## Dataset Splits
The 100 examples are divided using a stratified split:
| Split | Examples | Examples per class |
|---|---:|---:|
| Training | 80 | 16 |
| Validation | 10 | 2 |
| Test | 10 | 2 |
The original complete dataset is available in `data.csv`.
`split_data.py` can be used to reproduce the train, validation and test datasets.
## Model Training
The project uses `distilbert-base-uncased` as the pretrained base model.
DistilBERT is fine-tuned for multiclass sequence classification with five output classes corresponding to the five WCAG success criteria.
The training configuration currently uses:
- 5 epochs
- Batch size of 8
- Learning rate of 2e-5
- Validation after each epoch
- Weighted F1 as the model-selection metric
The training process is implemented in `train_model.py`.
## Initial Results
The initial model achieved:
| Metric | Result |
|---|---:|
| Test accuracy | 80% |
| Weighted precision | 0.867 |
| Weighted recall | 0.800 |
| Weighted F1 | 0.787 |
These results are based on a test set containing only **10 examples** and should not be interpreted as evidence that the model will achieve 80% accuracy on real-world accessibility defects.
The results demonstrate that the end-to-end classification pipeline is working.
## Example Predictions
After fine-tuning, the model correctly classified previously unseen examples such as:
```text
no focus indicator
```
as:
```text
2.4.7 Focus Visible
```
and:
```text
can't open menu with keyboard
```
as:
```text
2.1.1 Keyboard
```
## Repository Files
- `data.csv` — complete synthetic dataset
- `train.csv` — training split
- `validation.csv` — validation split
- `test.csv` — held-out test split
- `split_data.py` — creates the stratified dataset splits
- `load_dataset.py` — loads the CSV files using Hugging Face Datasets
- `tokenize_dataset.py` — tokenises examples and encodes labels
- `load_model.py` — loads DistilBERT for sequence classification
- `train_model.py` — fine-tunes and evaluates the classifier
- `predict.py` — performs inference using the trained model
## Limitations
This is a small educational dataset rather than a production accessibility dataset.
In particular:
- Only five WCAG success criteria are represented.
- The examples are synthetic.
- There are only 20 examples per class.
- The test set contains only 10 examples.
- Real accessibility defects may be substantially more complex or ambiguous.
- Some accessibility defects can relate to more than one WCAG success criterion.
The classifier is a closed-set classifier. It must select one of its five known classes even when an issue actually belongs to a WCAG criterion that is not represented in the dataset.
For example, an issue concerning missing alternative text would normally relate to **1.1.1 Non-text Content**, but the current model has no 1.1.1 class available.
## Purpose
The purpose of this project is to learn and demonstrate an end-to-end Hugging Face machine learning workflow:
```text
Dataset
↓
Train / Validation / Test Split
↓
Tokenisation
↓
Pretrained DistilBERT
↓
Fine-tuning
↓
Evaluation
↓
Inference
```
The project can be extended by adding more examples, introducing additional WCAG success criteria and evaluating the resulting classifier against a larger and more representative test dataset. |