Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

ClassifierNeuralNet

A simple neural network text classifier that converts English text into one of 100 predefined actions using Sentence Transformers and PyTorch.

Features

  • Uses all-MiniLM-L6-v2 Sentence 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

Architecture

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

Training Data

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.


Train

Run:

python classifier.py

Example output:

Epoch 1, Loss: 2.94
Epoch 2, Loss: 2.10
...
Training complete

Inference

pred, probs = predict("play some songs")

print(pred)

Output:

12

Model

  • Embedding Model: all-MiniLM-L6-v2
  • Embedding Size: 384
  • Hidden Layers:
    • 256 neurons
    • 128 neurons
  • Output Classes: 100
  • Loss: CrossEntropyLoss
  • Optimizer: Adam

Requirements

  • Python 3.9+
  • PyTorch
  • sentence-transformers

License

MIT License

About

Given English text, predicts one of 100 predefined actions.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors