YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
- Patent Green Technology Classification
- Python
PyTorch
- π― Project Overview
- π Table of Contents
- π Installation & Requirements
- β‘ Quick Start
- π File Organization
- π Step-by-Step Workflow
- π€ Models & Methods
- π Results & Metrics
- π Usage Guide
- π Green Technology Definition
- π€ Contributing
- π Acknowledgments
- π§ Questions?
- Python
PyTorch
Patent Green Technology Classification
A comprehensive deep learning system for classifying patent claims as green/environmentally beneficial technology using baseline models, LLM fine-tuning, and multi-agent debate.
π― Project Overview
This project implements an end-to-end pipeline for classifying patent claims as GREEN (environmentally beneficial) or NOT GREEN technology. The system progresses from baseline models to advanced LLM fine-tuning and culminates in a sophisticated multi-agent debate system for robust predictions.
Dataset: 1.37M patent claims from Hugging Face with 650+ CPC code columns
Key Achievements
| Method | F1 Score | Key Advantage |
|---|---|---|
| Baseline (LogReg + Frozen) | 0.777 | Fast, lightweight |
| Fine-tuned PatentSBERTa | 0.808 | Best accuracy-speed tradeoff |
| QLoRA Mistral | 0.811 | JSON output, memory efficient |
| Multi-Agent Debate | 0.867 | Most interpretable, robust |
π Table of Contents
- Installation
- Quick Start
- Project Structure
- Workflow
- Models & Methods
- Results
- Usage Guide
- Contributing
π Installation & Requirements
Prerequisites
- Python 3.8+
- CUDA 11.8+ (for GPU acceleration)
Setup
1. Clone Repository
git clone https://github.com/KarolinaBohdan/Deep_Learning_Final.git
cd Deep_Learning_Final
2. Create Virtual Environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# OR
venv\Scripts\activate # Windows
3. Install Dependencies
pip install --upgrade pip
pip install -r requirements.txt
4. Download Pre-trained Models (First Run)
# PatentSBERTa auto-downloads
python -c "from transformers import AutoModel; AutoModel.from_pretrained('AI-Growth-Lab/PatentSBERTa')"
# Mistral-7B-Instruct
python -c "from transformers import AutoModel; AutoModel.from_pretrained('mistralai/Mistral-7B-Instruct-v0.2')"
requirements.txt
# Core ML/DL
torch>=2.0.0
transformers>=4.41.0
peft>=0.11.0
trl>=0.8.0
datasets>=2.14.0
# Scientific Computing
numpy>=1.24.0
pandas>=2.0.0
scikit-learn>=1.3.0
# Utilities
tqdm>=4.66.0
joblib>=1.3.0
bitsandbytes>=0.42.0
accelerate>=0.25.0
pyarrow>=13.0.0
β‘ Quick Start
Classify New Patents
import torch
import json
from transformers import AutoTokenizer, AutoModel
from peft import PeftModel
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load fine-tuned PatentSBERTa (fastest, best accuracy)
tokenizer = AutoTokenizer.from_pretrained("AI-Growth-Lab/PatentSBERTa")
model = AutoModel.from_pretrained(
"partD_patentsberta_finetuned_evalsilver_only/",
device_map=device
)
# Classify a claim
new_claim = "A method for converting wind energy into electrical power with 95% efficiency..."
inputs = tokenizer(new_claim, return_tensors="pt", truncation=True, max_length=256)
outputs = model(**inputs)
# Process embeddings for classification...
Batch Evaluation
python A3_qlora_inference_.py \
--adapter_dir qlora_mistral_adapter_json \
--eval_silver eval_silver.parquet \
--output_csv predictions.csv
π File Organization
Deep_Learning_Final/
β
βββ README.md (this file)
βββ requirements.txt
β
βββ ASSIGNMENT 2 - BASELINE & LLM INTEGRATION
β βββ Assignment 2_Part A.ipynb [Data prep & splitting]
β βββ Assigment2_baseline_partA.py [Frozen embeddings baseline]
β βββ A2_partB_uncertainty.py [Uncertainty estimation]
β βββ A2_partC_llm_local.py [Mistral labeling + HITL]
β βββ A2_partD_finetune.py [PatentSBERTa fine-tuning]
β βββ results/
β βββ A2_LR_results_partA.out
β βββ A2PartD_finetuned_results/
β βββ finetune_part3_final_metrics/
β
βββ ASSIGNMENT 3 - QLORA FINE-TUNING
β βββ A3_qlora_finetuning.py [QLoRA training]
β βββ A3_qlora_inference_.py [QLoRA inference]
β βββ qlora_mistral_adapter_json/ [LoRA adapter checkpoint]
β βββ Qlora_patentsberta_finetuning_final_metrics/
β
βββ ASSIGNMENT 4 - MULTI-AGENT DEBATE
β βββ mas_final.py [MAS implementation]
β βββ MAS_train_patentsberta_human3/ [Training procedures]
β βββ results/
β βββ mas_debate_results.csv
β βββ MAS evaluation reports
β
βββ DATA FILES
β βββ patents_50k_green.parquet [50k balanced dataset]
β βββ train_silver.parquet [30k training split]
β βββ eval_silver.parquet [10k eval split]
β βββ pool_unlabeled.parquet [10k pool split]
β βββ hitl_green_100.csv [100 HITL samples]
β βββ hitl_green_100_llm_corrected.csv [100 HITL samples (verified)]
β βββ embeddings/
β βββ X_train.npy
β βββ X_eval.npy
β βββ X_pool.npy
β
βββ MODEL CHECKPOINTS
β βββ baseline_logreg.joblib
β βββ partD_patentsberta_finetuned_evalsilver_only/
β βββ qlora_mistral_adapter_json/
β
βββ M4_ASSIGNEMENT1_BDS_MFC.ipynb [Portfolio assignment]
π Step-by-Step Workflow
Phase 1: Data Preparation
Load 1.37M raw patent claims
β
Create is_green_silver labels from Y02* CPC codes
β
Balance to 50k (25k green + 25k non-green)
β
Split into train/eval/pool (60/20/20)
β
Output: 4 parquet files
Run: jupyter notebook "Assignment 2_Part A.ipynb"
Phase 2: Baseline Establishment
Generate PatentSBERTa embeddings (frozen, 768-dim)
β
Train Logistic Regression on train_silver
β
Evaluate on eval_silver
β
Output: Baseline metrics + model checkpoint
Run: python Assigment2_baseline_partA.py
Results: 0.777 F1 score
Phase 3: Uncertainty & LLM Labeling
Calculate uncertainty scores on pool_unlabeled
β
Select top-100 uncertain samples
β
Use Mistral-7B to generate initial labels + rationales
β
Human review and correction (HITL)
β
Output: 100 gold labels with human validation
Run: python A2_partC_llm_local.py
Phase 4: Fine-tuning PatentSBERTa
Load 30k train_silver + 100 gold labels
β
Tokenize with PatentSBERTa tokenizer
β
Fine-tune PatentSBERTa (unfrozen)
β
Evaluate on eval_silver
Run: python A2_partD_finetune.py
Results: 0.808 F1 score
Phase 5: QLoRA Fine-tuning
Quantize Mistral-7B to 4-bit
β
Add LoRA adapters (trainable)
β
Train on 30k train_silver + 100 gold
β
Output JSON predictions with rationales
Run Training:
python A3_qlora_finetuning.py \
--output_dir qlora_mistral_adapter_json \
--num_train_epochs 3 \
--per_device_train_batch_size 4
Run Inference: python A3_qlora_inference_.py --adapter_dir qlora_mistral_adapter_json
Results: 0.811 F1 score
Phase 6: Multi-Agent Debate System
Load fine-tuned Advocate (Mistral + LoRA)
β
Load base Skeptic (Mistral base)
β
Load base Judge (Mistral base)
β
For each claim: Advocate argues GREEN,
Skeptic argues NOT GREEN, Judge decides
β
Output: Final predictions with explanations
Run:
python mas_final.py \
--eval_silver eval_silver.parquet \
--hitl_file hitl_green_100_llm_corrected.csv \
--adapter_path qlora_mistral_adapter_json \
--output mas_debate_results.csv
Results: 0.867 F1 score
π€ Models & Methods
PatentSBERTa
- Model: BERT fine-tuned on patent documents
- Embedding Dimension: 768
- Max Sequence Length: 256 tokens
- Training Data: 16M patent documents
- Use Case: Feature extraction, domain-specific understanding
Mistral-7B-Instruct
- Parameters: 7 billion
- Context Window: 8,192 tokens
- Instruction Tuning: Yes (optimized for instruction following)
- Fine-tuning Method: QLoRA (efficient, memory-friendly)
- Quantization: 4-bit (14GB β 3.5GB)
Multi-Agent Debate System
Three specialized agents provide robust predictions:
Patent Claim
βββ ADVOCATE (Mistral + LoRA) β "Argue for GREEN (1)"
β
βββ SKEPTIC (Mistral base) β "Argue against NOT GREEN (0)"
β
βββ JUDGE (Mistral base) β Reviews both, decides
Output: {label, confidence, reasoning}
Why MAS Works:
- β Reduces single-model bias
- β Better calibration through perspective diversity
- β Explainable reasoning (debate arguments)
- β Robust: unlikely all 3 agents make same mistake
π Results & Metrics
Performance Comparison
| Method | F1 Score | Key Advantage |
|---|---|---|
| Baseline (LogReg + Frozen) | 0.777 | Fast, lightweight |
| Fine-tuned PatentSBERTa | 0.808 | Best accuracy-speed tradeoff |
| QLoRA Mistral | 0.811 | JSON output, memory efficient |
| Multi-Agent Debate | 0.867 | Most interpretable, robust |
π Usage Guide
Classify New Patents
import torch
from transformers import AutoTokenizer, AutoModel
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load fine-tuned PatentSBERTa
tokenizer = AutoTokenizer.from_pretrained("AI-Growth-Lab/PatentSBERTa")
model = AutoModel.from_pretrained(
"partD_patentsberta_finetuned_evalsilver_only/",
device_map=device
)
# Classify
new_claim = "A method for converting wind energy..."
inputs = tokenizer(new_claim, return_tensors="pt", truncation=True, max_length=256)
outputs = model(**inputs)
# Process embeddings...
Batch Evaluation
python A3_qlora_inference_.py \
--adapter_dir qlora_mistral_adapter_json \
--eval_silver eval_silver.parquet \
--output_csv predictions.csv
Multi-Agent Debate on Custom Data
python mas_final.py \
--eval_silver your_data.parquet \
--adapter_path qlora_mistral_adapter_json \
--output results.csv
π Green Technology Definition
The system classifies patents as GREEN if they describe:
- β Emissions reduction, exhaust treatment, carbon capture
- β Pollution control, filtration, removal
- β Recycling, waste processing, circular economy
- β Water treatment, purification, desalination
- β Renewable energy, storage, grid integration
- β Explicit energy-saving (not just "efficient")
- β Environmental monitoring reducing waste
π€ Contributing
Contributors
- Karolina Bohdan
- Faraiba Farnan
- Maleha Afzal
π Acknowledgments
- Hugging Face for the patent dataset and transformers library
- AI-Growth-Lab for PatentSBERTa
- Mistral AI for Mistral-7B-Instruct
- Meta for PEFT and QLoRA implementations
π§ Questions?
For questions or issues, please open a GitHub issue or contact the project maintainers.
Happy classifying! π