How gopiashokan/financial-document-classification-using-deep-learning works
Component Identification
• Data Source & Ingestion:
– The “dataset” folder holds raw HTML financial documents separated into different categories.
– “samples” directory provides example documents.
• Data Preprocessing Pipeline:
– HTML processing via BeautifulSoup.
– Tokenization and text cleaning using NLTK and spaCy (lemmatization, stop words removal).
– Word Embedding module: Training of a Word2Vec (300-dimensional vectors).
– Data balancing using SMOTETomek to handle imbalanced classes.
– Transformation to TensorFlow tensors (also data splitting into training, validation, and test sets).
• Deep Learning Model:
– Architecture: RNN with Bidirectional LSTM layers, dropout to mitigate overfitting.
– Components: Input layer, multiple Bi-LSTM layers, dropout, and an output softmax layer for multiclass classification.
– Training optimizations: cache, shuffle, prefetch (optimized pipeline) and usage of Adam optimizer with SparseCategoricalCrossentropy loss.
– Artifacts: trained model saved as “model.h5”.
• Application / Inference:
– A Streamlit application (file: app.py) that loads the saved model.
– Provides an interface to upload new HTML files and displays classified results with confidence metrics.
– Deployed on Hugging Face for public access.
• Supporting Utilities:
– Additional notebooks for exploration (Financial_Document_Classification.ipynb), requirements.txt for dependencies, and a report folder for documentation.
– Pre-trained Word2Vec model file (word2vec_model.bin).
Relationships and Interactions
• Data flows from the Dataset to the Preprocessing Pipeline.
– Raw HTML files are processed by extraction and tokenization modules.
– Tokenized text then goes through word embedding and data balancing.
• Preprocessed, tensorized data is input to the deep learning model training pipeline.
– The optimized data pipeline feeds training, validation, and test data to the bi-LSTM network.
– After training, the model parameters are saved.
• For inference, the saved model is loaded by the Streamlit application.
– The app accepts a new document, processes it similarly, and then outputs classification predictions.
• Deployment: The Streamlit app is integrated with Hugging Face’s platform, enabling remote use.
Architectural Patterns and Design Principles
• Separation of Concerns:
– Distinct modules for data ingestion, preprocessing, model training, and deployment.
• Data Pipeline Optimization:
– Use of caching, shuffling, and prefetching optimizes the deep learning training.
• Modularity & Reusability:
– Preprocessing (HTML extraction, text cleaning, embedding) is decoupled from model training and inference, which helps in maintenance and potential extension to other document types.
Relevant Technologies and Frameworks
• Python as the programming language.
• TensorFlow/Keras for building and training the RNN (Bi-LSTM) model.
• spaCy, NLTK, BeautifulSoup for text preprocessing.
• Gensim for the Word2Vec model.
• Streamlit for the interactive application interface.
• Hugging Face for deployment.
• Supporting libraries such as Numpy, Pandas, Matplotlib.
Elements
• Each component block should be clearly labeled (e.g., “Data Source: Financial HTML Documents”, “Preprocessing Module”, “Word Embedding & Balancing”, “Deep Learning Training: Bi-LSTM Model”, “Inference Module/Streamlit Application”, “Deployment: Hugging Face”).
• Subcomponents if necessary; for example, within the preprocessing layer, detail the text extraction and embedding process.
• Data Ingestion & Preprocessing:
– Raw financial HTML documents (organized in directories by category)
– HTML parsing with BeautifulSoup
– Tokenization, lemmatization, and stop-word removal using NLTK/spaCy
– Word Embedding using Word2Vec
– Dataset balancing using SMOTETomek
– Conversion to TensorFlow-compatible tensors and splitting into training/validation/test sets
• Model Training & Evaluation:
– Deep neural network architecture (Bidirectional LSTM layers, dropout, softmax output)
– Optimized training pipeline (caching, shuffling, prefetching)
– Training loop using TensorFlow with Adam optimizer and SparseCategoricalCrossentropy loss
– Model evaluation and saving (model.h5)
• Inference & Deployment:
– Streamlit application (app.py) serving as the user interface for document upload and classification
– Model loading for inference and presentation of predictions with confidence scores
– Deployment on the Hugging Face platform for public usage