Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚨 UPI Sentinel β€” Contextual Fraud Detection using Deep Learning

Live Demo Hugging Face Space Python TensorFlow FastAPI Streamlit Deep Learning License


πŸ€– Live Demo

Try UPI Sentinel Live: https://deemonduck-upi-sentinel.hf.space

The application is publicly deployed on Hugging Face Spaces and can be tested directly from the browser without any local setup.

Features Available in the Demo

  • Real-time fraud prediction
  • Sequence-aware transaction analysis
  • Interactive Streamlit dashboard
  • FastAPI-powered inference pipeline

πŸ“Œ Overview

UPI Sentinel is a sequence-based fraud detection system designed to analyze contextual transaction behavior instead of evaluating transactions independently.

Traditional fraud systems often rely on isolated transaction analysis, making them less effective against contextual financial fraud patterns.

This project combines:

  • CNN for local transaction pattern extraction
  • BiLSTM for temporal behavioral understanding
  • Attention mechanism for identifying important transaction steps
  • FastAPI deployment for real-time inference
  • Streamlit dashboard for live fraud monitoring

The system was trained and evaluated using multiple experimentation strategies on highly imbalanced financial transaction data.


πŸŽ₯ Dashboard Demonstration

Live Fraud Monitoring Dashboard

Dashboard Demo

The dashboard demonstrates:

  • Real-time transaction scoring
  • Sliding-window sequence inference
  • Fraud probability estimation
  • Contextual risk analysis
  • Live transaction history tracking

🧠 Problem Statement

Most fraud detection systems evaluate transactions independently.

However, real-world fraud often emerges through:

  • Rapid account draining
  • Sequential suspicious transfers
  • Behavioral anomalies over time
  • Abnormal spending progression

UPI Sentinel addresses this by analyzing transaction sequences using deep learning.

Instead of asking:

β€œIs this transaction fraudulent?”

The system asks:

β€œDoes the recent behavioral sequence appear suspicious?”


πŸ” Contextual Fraud Detection Example

Sequence-Based Risk Escalation

Contextual Fraud Flow

Example Scenario

A victim account starts with β‚Ή5000 balance.

The following rapid transactions occur:

Step Transaction Balance Remaining
1 β‚Ή2000 TRANSFER β‚Ή3000
2 β‚Ή1500 TRANSFER β‚Ή1500
3 β‚Ή1200 TRANSFER β‚Ή300
4 β‚Ή250 TRANSFER β‚Ή50
5 β‚Ή10 PAYMENT β‚Ή40

Although the final β‚Ή10 payment appears normal individually, the system flags it because the previous transaction sequence indicates suspicious account-draining behavior.

This demonstrates contextual sequence-based fraud detection.


πŸ—οΈ Model Architecture

CNN β†’ BiLSTM β†’ Attention

Architecture

Architecture Flow

Input Sequence
        ↓
Conv1D
        ↓
Dropout
        ↓
Bidirectional LSTM
        ↓
Attention Layer
        ↓
Dense Layers
        ↓
Fraud Probability Output

Why this architecture?

πŸ”Ή CNN Layer

Extracts local transaction patterns such as:

  • Sudden spending spikes
  • Rapid repetitive transfers
  • Abrupt balance changes

πŸ”Ή BiLSTM Layer

Learns temporal behavioral relationships across transaction history.

πŸ”Ή Attention Layer

Focuses on the most important transaction steps contributing to fraud probability.


πŸ“Š Experimental Results

Final Model Performance

Final Results

Final Evaluation Metrics

Metric Score
Accuracy 1.00
Precision 0.91
Recall 0.77
F1 Score 0.83
ROC-AUC 0.99
PR-AUC 0.8798

Experiment Comparison

Experiment Precision Recall F1 Score
CNN + Random Undersampling 0.13 0.94 0.23
CNN + Class Weights 0.42 0.90 0.57
CNN + BiLSTM + Attention 0.91 0.77 0.83

βš™οΈ Sequence Modeling Strategy

The system uses a sliding-window transaction sequence approach.

Example

With sequence length = 5:

[T1, T2, T3, T4, T5] β†’ Prediction
[T2, T3, T4, T5, T6] β†’ Prediction
[T3, T4, T5, T6, T7] β†’ Prediction

This enables contextual behavioral analysis over time.


πŸ§ͺ Experiments Conducted

βœ” Random Undersampling

Reduced majority-class dominance.

βœ” SMOTE

Synthetic minority oversampling.

βœ” Class Weight Experiments

Tested multiple class weight combinations:

  • Weight 5
  • Weight 7
  • Weight 10

βœ” Sliding Window Variations

Evaluated multiple sequence lengths:

  • Sequence Length = 5
  • Sequence Length = 10

βœ” Threshold Optimization

Experimented with:

  • Best F1 threshold
  • High-recall operating threshold

πŸš€ Deployment

FastAPI Backend

The project exposes a real-time fraud detection API using FastAPI.

Features

  • Sequence-aware inference
  • User-specific transaction buffers
  • Sliding-window contextual analysis
  • Fraud probability generation

Run FastAPI

uvicorn run:app --reload

API Docs:

http://127.0.0.1:8000/docs

Streamlit Dashboard

Interactive fraud monitoring dashboard with:

  • Live transaction inputs
  • Fraud probability visualization
  • Risk monitoring
  • Sequence-history tracking

Run Dashboard

streamlit run app.py

Dashboard URL:

http://localhost:8501

πŸ“‚ Project Structure

UPI_Sentinel/
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ api.py
β”‚   β”œβ”€β”€ inference.py
β”‚   β”œβ”€β”€ preprocessing.py
β”‚   β”œβ”€β”€ sequence_builder.py
β”‚   β”œβ”€β”€ model_loader.py
β”‚
β”œβ”€β”€ artifacts/
β”‚   β”œβ”€β”€ best_model.keras
β”‚   β”œβ”€β”€ scaler.pkl
β”‚   β”œβ”€β”€ label_encoder.pkl
β”‚   β”œβ”€β”€ metadata.json
β”‚
β”œβ”€β”€ app.py
β”œβ”€β”€ run.py
β”œβ”€β”€ requirements.txt
β”‚
β”œβ”€β”€ assets/
β”‚
└── README.md

πŸ› οΈ Tech Stack

Category Technologies
Language Python
Deep Learning TensorFlow / Keras
Backend API FastAPI
Dashboard Streamlit
Data Processing Pandas, NumPy, Scikit-learn
Visualization Matplotlib
Deployment Uvicorn

πŸ” Key Learnings

This project highlights several real-world machine learning challenges:

  • Extreme class imbalance
  • Precision vs Recall tradeoffs
  • Threshold optimization
  • Contextual sequence modeling
  • Deployment consistency
  • Real-time inference engineering
  • Sliding-window behavioral analysis

πŸ‘¨β€πŸ’» Author

Ridham Taneja

AI/ML Engineer β€’ Deep Learning Enthusiast β€’ Python Developer


⭐ Final Note

UPI Sentinel demonstrates how contextual sequence modeling can improve fraud detection beyond isolated transaction analysis.

The project combines:

  • Deep learning experimentation
  • Real-time deployment
  • Sequential behavioral analysis
  • Interactive visualization
  • Practical inference engineering

into a complete end-to-end AI system.

About

Hybrid deep learning fraud detection system using CNN, BiLSTM, and Attention mechanisms for UPI transaction classification.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages