Skip to content

PreritSM/Wafer_Pulse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”¬ Wafer Pulse β€” Predictive Maintenance for Semiconductor Manufacturing

Sensor-driven AI to preemptively identify defective silicon wafers and streamline semiconductor manufacturing quality control.

Wafer Pulse tackles one of the most expensive problems in semiconductor fabrication β€” undetected wafer defects. By analyzing readings from 590 in-line sensors, the system classifies wafers as Good (βˆ’1) or Bad (+1) before they reach downstream processing, reducing scrap costs and improving yield.

Built on the SECOM (Semiconductor Manufacturing) dataset (1,567 samples, 590 sensor features, ~6.6% defect rate), the pipeline handles real-world challenges: high dimensionality, extreme class imbalance, and pervasive missing data.


✨ Key Features

  • End-to-end ML pipeline β€” from raw batch sensor files to production-ready predictions.
  • Automated data ingestion β€” consolidates 30+ timestamped CSV batch files into a unified dataset.
  • Robust preprocessing β€” handles 41,951+ missing values across 538 columns via imputation; removes constant/near-zero-variance features (590 β†’ 562).
  • Feature scaling β€” StandardScaler normalization with a persisted scaler artifact for inference parity.
  • Mutual Information feature selection β€” reduces dimensionality from 562 to the top 60 most informative sensors.
  • Hyperparameter-tuned models β€” GridSearchCV over Random Forest and XGBoost; best model (XGBoost) serialized for serving.
  • Batch prediction β€” ingests new batch files, applies the saved scaler and feature selector, and outputs predictions.
  • Detailed artifact logging β€” every pipeline stage produces human-readable reports (data profile, missing-value analysis, feature rankings, model metrics).
  • DVC-initialized β€” data version control scaffolding in place for large-file tracking.
  • Code quality tooling β€” ruff for linting and formatting with import sorting.

πŸ› οΈ Tech Stack

Category Technology Purpose
Language Python 3.12 Core language
Data Processing Pandas, NumPy Data manipulation & numerical computing
Machine Learning Scikit-learn Preprocessing, feature selection, Random Forest, metrics
Gradient Boosting XGBoost Primary classification model
Web Framework Flask REST API for serving predictions
WSGI Server Gunicorn Production-grade HTTP server
CLI Click Command-line interface
Config Management python-dotenv Environment variable handling
Cloud AWS (S3, EC2, ALB, RDS, Lambda, SNS, CloudWatch, Secrets Manager) Production deployment and operations
Experiment Tracking MLflow Model versioning, metadata and metric logging
Data Versioning DVC Large file tracking & pipeline reproducibility
Build System Setuptools Python package building
Linting & Formatting Ruff Fast Python linter + formatter
Testing Pytest, pytest-cov Unit testing & coverage
Package Management uv, pip Dependency resolution & installation

πŸ“ Project Structure

Wafer_Pulse/
β”‚
β”œβ”€β”€ Makefile                        # Build automation (install, lint, format, test, clean)
β”œβ”€β”€ pyproject.toml                  # Package metadata, build config & ruff settings
β”œβ”€β”€ requirements.txt                # Pinned Python dependencies
β”œβ”€β”€ LICENSE                         # MIT License
β”œβ”€β”€ README.md                       # ← You are here
β”œβ”€β”€ Dockerfile                      # 🐳 API container image (python:3.12-slim + gunicorn)
β”œβ”€β”€ .env.example                    # πŸ” Environment variable template (WAFER_PROJECT_*)
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ Training_Batch_Files/       # πŸ“₯ Raw sensor CSVs (30+ batch files, 590 sensors each)
β”‚   β”œβ”€β”€ Prediction_Batch_files/     # πŸ“₯ Unlabeled batch files for inference
β”‚   β”œβ”€β”€ raw/                        # πŸ—ƒοΈ Consolidated raw dataset
β”‚   β”œβ”€β”€ preprocessed_data/          # πŸ”§ Cleaned & transformed data
β”‚   β”œβ”€β”€ Train_data/                 # 🎯 Final training-ready data (top 60 MI features)
β”‚   β”œβ”€β”€ Prediction_Output_File/     # πŸ“€ Model predictions
β”‚   └── Artifacts/                  # πŸ“Š Pipeline reports & serialized objects (scaler, etc.)
β”‚
β”œβ”€β”€ models/                         # πŸ€– Serialized trained models
β”‚   └── best_model.pkl              #    XGBoost (lr=0.5, depth=5, n=50)
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ api/                        # πŸš€ Flask API (/predict, /predict/batch, /health)
β”‚   β”œβ”€β”€ infrastructure/             # ☁️ Cloud integration (AWS/RDS/MLflow/settings)
β”‚   β”œβ”€β”€ lambda_handlers/            # Ξ» S3-triggered batch inference handler
β”‚   └── pipeline_0*.py              # ML pipeline stages (prep β†’ preprocess β†’ train β†’ infer)
β”‚
β”œβ”€β”€ infrastructure/
β”‚   └── terraform/                  # πŸ—οΈ AWS IaC: VPC, S3, ALB, EC2, RDS, CloudWatch, SNS
β”‚
β”œβ”€β”€ .github/workflows/              # πŸ”„ CI/CD and scheduled training workflows
β”‚   β”œβ”€β”€ ci.yml
β”‚   └── daily-training.yml
β”‚
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ params.yaml                 # Pipeline hyperparameters and paths
β”‚   β”œβ”€β”€ cloud_provisioning_contract.yaml  # AWS resource contract & post-provision outputs
β”‚   β”œβ”€β”€ schema_training.json
β”‚   └── schema_prediction.json
β”‚
β”œβ”€β”€ tests/                          # πŸ§ͺ Test suite
β”œβ”€β”€ notebooks/                      # πŸ““ Jupyter notebooks (experimentation)
β”œβ”€β”€ docs/                           # πŸ“– MkDocs documentation site
└── references/                     # πŸ“š Reference materials & data dictionaries

βš™οΈ Installation & Setup

Prerequisites

  • Python 3.12+
  • pip or uv (recommended)
  • Git
  • Make (optional, for shortcut commands)

1. Clone the Repository

git clone https://github.com/PreritSM/Wafer_Pulse.git
cd Wafer_Pulse

2. Create a Virtual Environment

python3 -m venv venv
source venv/bin/activate

3. Install Dependencies

pip install -U pip
pip install -r requirements.txt

4. Verify Installation

python -c "import src; print('βœ… wafer project imports correctly')"

5. Configure Environment Variables

cp .env.example .env

Populate all required WAFER_PROJECT_* values in .env.


☁️ Cloud Provisioning Contract

Before provisioning AWS resources, fill:

  • config/cloud_provisioning_contract.yaml

This file is the single source for:

  • Terraform input values (api_ami_id, CIDRs, alert email, etc.)
  • Runtime environment values (WAFER_PROJECT_*)
  • Post-provision outputs that must be handed back (api_alb_dns_name, rds_endpoint, subnet IDs, etc.)

After apply, update the post_provision_outputs section with real values.


πŸ—οΈ AWS Deployment (Terraform)

cd infrastructure/terraform

# Copy the example config and fill in real values
cp minimal.auto.tfvars.example minimal.auto.tfvars
# Edit minimal.auto.tfvars β€” set api_ami_id, db_password, api_key, alert_email

# Download providers (~674 MB, kept out of git)
terraform init

# Preview
terraform plan -var-file="minimal.auto.tfvars"

# Apply
terraform apply -var-file="minimal.auto.tfvars"

# Tear down
terraform destroy -var-file="minimal.auto.tfvars"

Provisioned components include:

  • Custom VPC with public/private subnets
  • S3 bucket (s3://wafer-project-pm29/) with versioning + SSE-S3
  • RDS PostgreSQL (db.t3.micro)
  • Optional internet-facing ALB + EC2 API target
  • CloudWatch logs and optional SNS alerts
  • Secrets Manager secret for runtime config

Note: minimal.auto.tfvars is gitignored. Only minimal.auto.tfvars.example (with placeholders) is committed. Never commit a tfvars file with real credentials.


πŸš€ Usage

Makefile Commands

Command Description
make requirements Install all Python dependencies
make clean Remove compiled .pyc files and __pycache__/ directories
make lint Check code style with ruff (no auto-fix)
make format Auto-format and fix code with ruff
make test Run the test suite
make help List all available Make targets

Start API Locally

python src/api/main.py
# or with gunicorn:
gunicorn --chdir src "api.main:app" --bind 0.0.0.0:5000

API Endpoints

Method Endpoint Description
GET /health Liveness β€” model load status
POST /predict Single wafer inference (60 scaled sensor readings)
POST /predict/batch Batch inference β€” list of wafers

Example:

curl -s -X POST http://localhost:5000/predict \
  -H "Content-Type: application/json" \
  -d '{"sensor_readings": [0.0, 0.1, ...]}' | python -m json.tool

The sensor_readings array must contain exactly 60 pre-scaled floating-point values (output of StandardScaler + Mutual Information feature selection).

Pipeline Overview

Training_Batch_Files/*.csv
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Data Ingestion   │────▢│  raw/combined_secom_data.csv  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Preprocessing    │────▢│  preprocessed_data/preprocessed_*.csv  β”‚
β”‚  (impute + filter)β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Feature Scaling  │────▢│  preprocessed_data/scaled_*.csv      β”‚
β”‚  (StandardScaler) β”‚     β”‚  Artifacts/feature_scaler.pkl        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Feature Selection│────▢│  Train_data/selected_features_*.csv  β”‚
β”‚  (Mutual Info)    β”‚     β”‚  Top 60 of 562 features              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Model Training   │────▢│  models/best_model.pkl               β”‚
β”‚  (RF vs XGBoost)  β”‚     β”‚  Logged to MLflow                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Prediction       │────▢│  Prediction_Output_File/Predictions  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Model Performance

Model Best Parameters CV Score Accuracy Precision F1 ROC-AUC
Random Forest gini, max_depth=2, log2, n=10 0.9338 0.9331 0.8707 0.9008 0.6079
XGBoost βœ… lr=0.5, max_depth=5, n=50 0.9354 0.9172 0.8899 0.9015 0.6958

Note: Model selection uses PR-AUC as the primary metric (best for class imbalance at 6.6% defect rate). ROC-AUC and F1 are logged as supporting metrics.

Dataset Summary

Property Value
Samples 1,567
Sensors (raw features) 590
Selected features 60
Good wafers (βˆ’1) 1,463 (93.4%)
Defective wafers (+1) 104 (6.6%)
Missing values 41,951 (4.53% of all cells)

πŸ—ΊοΈ Implementation Status

βœ… Completed

  • Flask API in src/api/ with /predict, /predict/batch, /health.
  • Cloud integration layer in src/infrastructure/ for settings, retries, S3, RDS persistence, and MLflow tagging.
  • Batch ingestion Lambda handler in src/lambda_handlers/batch_ingestion.py.
  • DVC remote configured to s3://wafer-project-pm29/dvc-registry/.
  • Terraform scaffold in infrastructure/terraform/ for VPC, S3, ALB, EC2, RDS, CloudWatch, SNS.
  • CI workflows in .github/workflows/ including daily training schedule and PR-AUC gate.
  • MLflow tracking wired into pipeline_06_model_training.py.

πŸ”œ Next Steps

  • Apply Terraform with real account values and capture outputs in config/cloud_provisioning_contract.yaml.
  • Configure Secrets Manager and start API container on EC2.
  • Execute smoke tests against the ALB endpoint and Lambda S3 trigger.
  • Enable MLflow model promotion flow (Staging/Production aliases).

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


πŸ‘€ Author

PreritSM β€” GitHub

About

Predictive maintenance for silicon wafers: using sensor-driven AI to preemptively identify defects and streamline semiconductor manufacturing

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors