An AI-powered web application for classifying patent documents using fine-tuned BERT models with explainability features.
This project provides an intelligent system for automatically classifying patent documents into CPC (Cooperative Patent Classification) categories using state-of-the-art NLP models. The application features:
patent-classification-ai/
├── app/ # Flask web application
│ ├── __init__.py # Application factory
│ ├── routes.py # URL routes and views
│ ├── models.py # Database models
│ ├── forms.py # WTForms definitions
│ ├── templates/ # Jinja2 HTML templates
│ └── static/ # CSS, JavaScript, images
├── ml/ # Machine learning components
│ ├── predictor.py # Main prediction engine
│ ├── data_processing.py # Data loading and preprocessing
│ ├── custom_classes.py # Custom PyTorch datasets/trainers
│ └── labels.py # CPC label definitions
├── training/ # Model fine-tuning scripts
│ ├── finetuning.py # Base BERT fine-tuning
│ ├── finetuning_scibert.py # SciBERT fine-tuning
│ └── finetuning_t5.py # T5 model fine-tuning
├── config.py # Configuration management
├── run.py # Application entry point
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
└── README.md # This file
Clone the repository
git clone https://github.com/yourusername/patent-classification-ai.git
cd patent-classification-ai
Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
Install dependencies
pip install -r requirements.txt
Configure environment variables
cp .env.example .env
# Edit .env with your configuration
Download or train models
model lvl 0 - balanced/training/Initialize the database
python run.py # Database tables are auto-created on first run
python run.py
The application will start on http://localhost:5000
Quick Classification (returns top predicted class):
curl -X POST http://localhost:5000/classify \
-H "Content-Type: application/json" \
-d '{
"input_data": "Your patent text here...",
"type": "quick"
}'
Full Classification (returns predictions + word attributions):
curl -X POST http://localhost:5000/classify \
-H "Content-Type: application/json" \
-d '{
"input_data": "Your patent text here...",
"type": "full"
}'
# Fine-tune SciBERT on your dataset
python -m training.finetuning_scibert
# Fine-tune T5 model
python -m training.finetuning_t5
The system uses SciBERT (BERT pre-trained on scientific publications) as the base model, fine-tuned for multi-label patent classification:
Key settings in config.py:
SECRET_KEY # Flask secret key (set in .env!)
DATABASE_URL # SQLAlchemy database URI
MODEL_DIR # Directory containing trained models
LOG_LEVEL # Logging verbosity
Set environment to production
export FLASK_ENV=production
Use a production WSGI server
gunicorn -w 4 -b 0.0.0.0:5000 run:app
Set a strong SECRET_KEY
export SECRET_KEY="your-cryptographically-strong-key"
Configure a production database
DATABASE_URL environment variableThis project is licensed under the MIT License.
1 commits
Python
67.5%
HTML
19.0%
CSS
12.7%
An AI-powered web application for classifying patent documents using fine-tuned BERT models with explainability features.
This project provides an intelligent system for automatically classifying patent documents into CPC (Cooperative Patent Classification) categories using state-of-the-art NLP models. The application features:
patent-classification-ai/
├── app/ # Flask web application
│ ├── __init__.py # Application factory
│ ├── routes.py # URL routes and views
│ ├── models.py # Database models
│ ├── forms.py # WTForms definitions
│ ├── templates/ # Jinja2 HTML templates
│ └── static/ # CSS, JavaScript, images
├── ml/ # Machine learning components
│ ├── predictor.py # Main prediction engine
│ ├── data_processing.py # Data loading and preprocessing
│ ├── custom_classes.py # Custom PyTorch datasets/trainers
│ └── labels.py # CPC label definitions
├── training/ # Model fine-tuning scripts
│ ├── finetuning.py # Base BERT fine-tuning
│ ├── finetuning_scibert.py # SciBERT fine-tuning
│ └── finetuning_t5.py # T5 model fine-tuning
├── config.py # Configuration management
├── run.py # Application entry point
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
└── README.md # This file
Clone the repository
git clone https://github.com/yourusername/patent-classification-ai.git
cd patent-classification-ai
Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
Install dependencies
pip install -r requirements.txt
Configure environment variables
cp .env.example .env
# Edit .env with your configuration
Download or train models
model lvl 0 - balanced/training/Initialize the database
python run.py # Database tables are auto-created on first run
python run.py
The application will start on http://localhost:5000
Quick Classification (returns top predicted class):
curl -X POST http://localhost:5000/classify \
-H "Content-Type: application/json" \
-d '{
"input_data": "Your patent text here...",
"type": "quick"
}'
Full Classification (returns predictions + word attributions):
curl -X POST http://localhost:5000/classify \
-H "Content-Type: application/json" \
-d '{
"input_data": "Your patent text here...",
"type": "full"
}'
# Fine-tune SciBERT on your dataset
python -m training.finetuning_scibert
# Fine-tune T5 model
python -m training.finetuning_t5
The system uses SciBERT (BERT pre-trained on scientific publications) as the base model, fine-tuned for multi-label patent classification:
Key settings in config.py:
SECRET_KEY # Flask secret key (set in .env!)
DATABASE_URL # SQLAlchemy database URI
MODEL_DIR # Directory containing trained models
LOG_LEVEL # Logging verbosity
Set environment to production
export FLASK_ENV=production
Use a production WSGI server
gunicorn -w 4 -b 0.0.0.0:5000 run:app
Set a strong SECRET_KEY
export SECRET_KEY="your-cryptographically-strong-key"
Configure a production database
DATABASE_URL environment variableThis project is licensed under the MIT License.
1 commits
Python
67.5%
HTML
19.0%
CSS
12.7%