A simple neural network text classifier that converts English text into one of 100 predefined actions using Sentence Transformers and PyTorch.
- Uses
all-MiniLM-L6-v2Sentence Transformer embeddings - Multi-layer neural network (MLP) classifier
- Supports up to 100 predefined action classes
- Simple training loop with PyTorch
- Easy inference on new text
English Text
│
▼
SentenceTransformer
(all-MiniLM-L6-v2)
│
384-dimensional embedding
│
▼
Linear(384 → 256)
│
ReLU
│
Dropout(0.2)
│
Linear(256 → 128)
│
ReLU
│
Linear(128 → 100)
│
▼
Predicted Action ID
Replace the example dataset with your own.
texts = [
"turn on lights",
"play music",
"book cab",
"switch off fan",
"order food"
]
labels = [
5,
12,
37,
5,
22
]Each label is an integer representing one predefined action.
Run:
python classifier.pyExample output:
Epoch 1, Loss: 2.94
Epoch 2, Loss: 2.10
...
Training complete
pred, probs = predict("play some songs")
print(pred)Output:
12
- Embedding Model:
all-MiniLM-L6-v2 - Embedding Size: 384
- Hidden Layers:
- 256 neurons
- 128 neurons
- Output Classes: 100
- Loss: CrossEntropyLoss
- Optimizer: Adam
- Python 3.9+
- PyTorch
- sentence-transformers
MIT License