File size: 1,905 Bytes
73212c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
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