Amoako419/Contract_Document_Classification

Jupyter Notebook

0

16 commits

updated Aug 25, 2025

See the code

README

Contract Document Classification

This project implements a Contract Document Classification system using both traditional Machine Learning (SVM) and Deep Learning (BERT) approaches. The system can automatically classify different types of contract documents based on their content.

Overview

The project consists of two main implementations:

  • SVM-based classification with TF-IDF vectorization
  • BERT-based classification using transformers

Each implementation has its own web application interface built with Streamlit and FastAPI.

Directory Structure

├── app/
│   ├── bert_app/         # BERT implementation frontend and backend
│   └── svm_app/          # SVM implementation frontend and backend
├── data/                 # Training and validation datasets
├── models/              # Trained model files
└── notebooks/           # Jupyter notebooks for model development

Requirements

  • Python 3.13
  • pip (Python package manager)

Pre-trained Models

The project uses two types of models:

  • SVM Model: Available locally in the models/ directory
  • LegalBERT Model: Hosted on Hugging Face Hub at amoako419/legal-bert-contract-classifier
    • Based on the LegalBERT architecture
    • Fine-tuned on the CUAD dataset
    • Automatically downloaded when running the application

Setup

Installation Steps

Clone the repository:

git clone https://github.com/Amoako419/Contract_Document_Classification.git
cd Contract_Document_Classification

Set up a virtual environment (recommended):

python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate

Install required packages:

pip install -r requirements.txt

Running the SVM Application

Start the FastAPI backend:

cd app/svm_app
uvicorn backend:app --reload

Then in a new terminal, launch the Streamlit frontend:

cd app/svm_app
streamlit run app.py

Running the LegalBERT Application

The BERT model is hosted on Hugging Face Hub at amoako419/legal-bert-contract-classifier for easy access and deployment.

Start the FastAPI backend:

cd app/bert_app
uvicorn backend:app --reload

Then in a new terminal, launch the Streamlit frontend:

cd app/bert_app
streamlit run app.py

The backend will automatically download the model from Hugging Face Hub on first use. The application will be available at:

Using the Web Interface

  1. Navigate to http://localhost:8501 in your web browser
  2. Choose one of the following:
    • Paste contract text directly into the text area
    • Upload a text file containing the contract
  3. Click "Classify Contract" to get the classification result

Development

Training Notebooks

Available in the notebooks/ directory:

  • contract_classification_ml.ipynb: SVM model training
  • contract_classification_bert.ipynb: BERT model training
  • data_preview.ipynb: Data exploration and preprocessing

Dataset Information

The project uses the Contract Understanding Atticus Dataset (CUAD) for training and validation. The processed data is available in the data/ directory.

Citation

@article{hendrycks2021cuad,
      title={CUAD: An Expert-Annotated NLP Dataset for Legal Contract Review}, 
      author={Dan Hendrycks and Collin Burns and Anya Chen and Spencer Ball},
      journal={NeurIPS},
      year={2021}
}

License

This project is licensed under the terms of the LICENSE file included in the repository.

Amoako419/Contract_Document_Classification

Jupyter Notebook

0

16 commits

updated Aug 25, 2025

See the code

README

Contract Document Classification

This project implements a Contract Document Classification system using both traditional Machine Learning (SVM) and Deep Learning (BERT) approaches. The system can automatically classify different types of contract documents based on their content.

Overview

The project consists of two main implementations:

  • SVM-based classification with TF-IDF vectorization
  • BERT-based classification using transformers

Each implementation has its own web application interface built with Streamlit and FastAPI.

Directory Structure

├── app/
│   ├── bert_app/         # BERT implementation frontend and backend
│   └── svm_app/          # SVM implementation frontend and backend
├── data/                 # Training and validation datasets
├── models/              # Trained model files
└── notebooks/           # Jupyter notebooks for model development

Requirements

  • Python 3.13
  • pip (Python package manager)

Pre-trained Models

The project uses two types of models:

  • SVM Model: Available locally in the models/ directory
  • LegalBERT Model: Hosted on Hugging Face Hub at amoako419/legal-bert-contract-classifier
    • Based on the LegalBERT architecture
    • Fine-tuned on the CUAD dataset
    • Automatically downloaded when running the application

Setup

Installation Steps

Clone the repository:

git clone https://github.com/Amoako419/Contract_Document_Classification.git
cd Contract_Document_Classification

Set up a virtual environment (recommended):

python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate

Install required packages:

pip install -r requirements.txt

Running the SVM Application

Start the FastAPI backend:

cd app/svm_app
uvicorn backend:app --reload

Then in a new terminal, launch the Streamlit frontend:

cd app/svm_app
streamlit run app.py

Running the LegalBERT Application

The BERT model is hosted on Hugging Face Hub at amoako419/legal-bert-contract-classifier for easy access and deployment.

Start the FastAPI backend:

cd app/bert_app
uvicorn backend:app --reload

Then in a new terminal, launch the Streamlit frontend:

cd app/bert_app
streamlit run app.py

The backend will automatically download the model from Hugging Face Hub on first use. The application will be available at:

Using the Web Interface

  1. Navigate to http://localhost:8501 in your web browser
  2. Choose one of the following:
    • Paste contract text directly into the text area
    • Upload a text file containing the contract
  3. Click "Classify Contract" to get the classification result

Development

Training Notebooks

Available in the notebooks/ directory:

  • contract_classification_ml.ipynb: SVM model training
  • contract_classification_bert.ipynb: BERT model training
  • data_preview.ipynb: Data exploration and preprocessing

Dataset Information

The project uses the Contract Understanding Atticus Dataset (CUAD) for training and validation. The processed data is available in the data/ directory.

Citation

@article{hendrycks2021cuad,
      title={CUAD: An Expert-Annotated NLP Dataset for Legal Contract Review}, 
      author={Dan Hendrycks and Collin Burns and Anya Chen and Spencer Ball},
      journal={NeurIPS},
      year={2021}
}

License

This project is licensed under the terms of the LICENSE file included in the repository.