|
--- |
|
tags: |
|
- pytorch |
|
- anomaly-detection |
|
- time-series |
|
- gru |
|
- sequence-model |
|
- binary-classification |
|
model-index: |
|
- name: GRU Sequence Anomaly Detector |
|
results: [] |
|
--- |
|
|
|
# GRU Sequence Anomaly Detector |
|
|
|
This model uses a bidirectional GRU (Gated Recurrent Unit) architecture to detect anomalies in sequential tabular data β such as transaction records, log events, or sensor readings. It's designed for general-purpose anomaly detection and can be fine-tuned on domain-specific datasets. |
|
|
|
## π§ Model Architecture |
|
|
|
- **Type:** Bidirectional GRU |
|
- **Input:** Sequence of numerical feature vectors `(batch_size, time_steps, input_dim)` |
|
- **Output:** Binary classification (0 = normal, 1 = anomaly) |
|
- **Layers:** 2-layer GRU β BatchNorm β Dense β Sigmoid |
|
|
|
## π οΈ Intended Use |
|
|
|
This model is ideal for: |
|
- Transaction anomaly detection |
|
- Time-series pattern disruption |
|
- Sequential event log monitoring |
|
|
|
It is open for fine-tuning using your labeled anomaly dataset via `fine_tune_template.py`. |
|
|
|
## π How to Use |
|
|
|
```python |
|
import torch |
|
from models.model import TxnAnomalyGRU |
|
|
|
model = TxnAnomalyGRU(input_dim=32) |
|
model.load_state_dict(torch.load("models/txn_anomaly_model.pt")) |
|
model.eval() |
|
``` |
|
|
|
Or use the ONNX version with ONNX Runtime: |
|
|
|
```python |
|
import onnxruntime |
|
session = onnxruntime.InferenceSession("models/txn_anomaly_model.onnx") |
|
outputs = session.run(None, {"input": your_input_array}) |
|
``` |
|
|
|
## π Fine-Tuning |
|
|
|
To fine-tune on your own dataset: |
|
|
|
```bash |
|
python fine_tune_template.py --data your_dataset.csv |
|
``` |
|
|
|
Ensure your data is preprocessed into sequences of the same input dimension (`input_dim=32` by default). |
|
|
|
## π¦ Files Included |
|
|
|
- `models/txn_anomaly_model.pt` β Pretrained PyTorch model |
|
- `models/txn_anomaly_model.onnx` β ONNX export |
|
- `fine_tune_template.py` β Script to fine-tune on your dataset |
|
- `pipeline/main.py` β End-to-end pipeline |
|
|