DML-Chain introduces a novel architecture that integrates blockchain technology with federated learning to decentralize machine learning. This approach mitigates key challenges such as data centralization, privacy breaches, and biases in training datasets. By leveraging blockchain's secure, decentralized ledger and federated learning's privacy-preserving capabilities, DML-Chain enables distributed model training without requiring centralized data repositories.
- Privacy-first Training: Data remains on local devices, preserving user privacy while enabling collaborative training.
- Blockchain Accountability: Blockchain records ensure transparency and track participant contributions securely.
- Smart Contract Incentives: An incentive mechanism rewards high-quality contributions while penalizing malicious behaviors.
- Energy Efficiency: Implemented on a energy-efficient, quantum-secure, single-layer blockchain(Algorand) to ensure sustainability and scalability.
Read More about Algorand on https://algorand.co/
The project's proof-of-concept demonstrates the potential for a secure, privacy-preserving ecosystem that fosters collaboration in machine learning while reducing bias and maintaining accountability.
This project is currently in active development. Future updates will focus on optimizing blockchain integration, improving model performance, and expanding real-world applications.
Before setting up DML-Chain, ensure you have the following installed:
- Node.js (v20.0 or higher)
- npm (v9.0 or higher)
- Python (v3.8 or higher)
- Git
- AlgoKit CLI (v2.0.0 or higher)
- MongoDB (for storing client profile information)
- Jupyter Notebook (for running ML model development notebooks)
AlgoKit is essential for running the Algorand blockchain backend. Install it using one of the following methods:
pip install algokit
pipx install algokit
brew install algorandfoundation/tap/algokit
choco install algokit
Verify the installation:
algokit --version
-
Clone the repository:
git clone https://github.com/anupa-perera/DML-Chain.git cd DML-Chain
-
Bootstrap the AlgoKit project:
algokit project bootstrap all
The backend consists of Algorand smart contracts written in TEALScript.
-
Navigate to the contracts directory:
cd projects/DML-contracts
-
Install dependencies:
npm install
-
Start the local Algorand network:
algokit localnet start
-
Compile contracts and generate clients:
npm run build
-
Run tests:
npm run test
The ML components handle federated learning, data aggregation, and model training.
-
Navigate to the model directory:
cd model
-
Create a Python virtual environment:
python -m venv venv
-
Activate the virtual environment:
Windows:
venv\Scripts\activate
macOS/Linux:
source venv/bin/activate
-
Install Python dependencies:
pip install -r requirements.txt
-
Set up environment variables:
cp .env.template .env
Configure your MongoDB connection string and other required variables in the
.env
file. -
Start the ML backend server:
python backend.py
The ML backend will be available at http://localhost:5000
The frontend is built with React, TypeScript, and Vite.
-
Navigate to the frontend directory:
cd projects/DML-frontend
-
Install dependencies:
npm install
-
Generate app clients:
npm run generate:app-clients
-
Start the development server:
npm run dev
The frontend will be available at http://localhost:5173
From the root directory, you can build both projects:
algokit project run build
- Compile contracts:
npm run compile-contract
- Generate TypeScript clients:
npm run generate-client
- Run tests:
npm run test
- Lint code:
npm run lint
- Start ML backend:
python model/backend.py
- Run Jupyter notebooks:
jupyter notebook
(from model directory) - Data splitting: Use
model/data_splitter/data_splitter.ipynb
- Model training: Use
model/base_model/fraud-detection-model.ipynb
- Aggregation: Use
model/Aggregator/Aggregator.ipynb
- Start dev server:
npm run dev
- Build for production:
npm run build
- Run tests:
npm run test
- Run E2E tests:
npm run playwright:test
-
Frontend environment:
cp projects/DML-frontend/.env.template projects/DML-frontend/.env
-
ML Model environment:
cp model/.env.template model/.env
Configure the following variables:
MONGO_CLIENT
: MongoDB connection string- Other ML-specific configuration variables
-
Configure your environment variables in the respective
.env
files as needed.
-
AlgoKit not found:
- Ensure AlgoKit is properly installed and in your PATH
- Try reinstalling using a different method
-
Local network issues:
- Stop and restart the local network:
algokit localnet stop && algokit localnet start
- Reset the network:
algokit localnet reset
- Stop and restart the local network:
-
Node version conflicts:
- Use Node.js v20.0 or higher
- Consider using nvm to manage Node versions
-
Build failures:
- Clear node_modules and reinstall:
rm -rf node_modules package-lock.json && npm install
- Ensure all dependencies are up to date
- Clear node_modules and reinstall:
-
Python/ML issues:
- Ensure Python virtual environment is activated
- Reinstall Python dependencies:
pip install -r model/requirements.txt
- Check MongoDB connection string in
.env
file - Verify all required Python packages are installed
This project is in active development. Please refer to the contribution guidelines when submitting pull requests or reporting issues.