iBrokeTheCode/Multimodal_Product_Classification
0
1---2title: Multimodal Product Classification3emoji: π4colorFrom: purple5colorTo: yellow6sdk: gradio7sdk_version: 5.44.08app_file: app.py9pinned: true10license: mit11short_description: Product classification using image and text12---13 14# ποΈMultimodal Product Classification with Gradio15 16## Table of Contents17 181. [Project Description](#1-project-description)192. [Methodology & Key Features](#2-methodology--key-features)203. [Technology Stack](#3-technology-stack)214. [Model Details](#4-model-details)22 23## 1. Project Description24 25This project implements a **multimodal product classification system** for Best Buy products. The core objective is to categorize products using both their text descriptions and images. The system was trained on a dataset of **almost 50,000** items.26 27The entire system is deployed as a lightweight, web application using **Gradio**. The app allows users to:28 29- Use both text and an image for the most accurate prediction.30- Run predictions using only text or only an image to understand the contribution of each data modality.31 32This project showcases the power of combining different data types to build a more robust and intelligent classification system.33 34> [!IMPORTANT]35>36> - Check out the deployed app here: ποΈ [Multimodal Product Classification App](https://huggingface.co/spaces/iBrokeTheCode/Multimodal_Product_Classification) ποΈ37> - Check out the Jupyter Notebook for a detailed walkthrough of the project here: ποΈ [Jupyter Notebook](https://huggingface.co/spaces/iBrokeTheCode/Multimodal_Product_Classification/blob/main/notebook_guide.ipynb) ποΈ38 3940 41## 2. Methodology & Key Features42 43- **Core Task:** Multimodal Product Classification on a Best Buy dataset.44 45- **Pipeline:**46 47 - **Data:** A dataset of \~50,000 products, each with a text description and an image.48 - **Feature Extraction:** Pre-trained models are used to convert raw text and image data into high-dimensional embedding vectors.49 - **Classification:** A custom-trained **Multilayer Perceptron (MLP)** model performs the final classification based on the embeddings.50 51- **Key Features:**52 53 - **Multimodal:** Combines text and image data for a more accurate prediction.54 - **Single-Service Deployment:** The entire application runs as a single, deployable Gradio app.55 - **Flexible Inputs:** The app supports multimodal, text-only, and image-only prediction modes.56 57## 3. Technology Stack58 59This project was built using the following technologies:60 61**Deployment & Hosting:**62 63- [Gradio](https://gradio.app/) β interactive web app frontend.64- [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces) β for cost-effective deployment.65 66**Modeling & Training:**67 68- [TensorFlow / Keras](https://www.tensorflow.org/) β used to train the final MLP classification model.69- [Sentence-Transformers](https://www.sbert.net/) β for generating text embeddings.70- [Hugging Face Transformers](https://huggingface.co/docs/transformers/index) β for the image feature extractor (`TFConvNextV2Model`).71 72**Development Tools:**73 74- [Ruff](https://github.com/charliermarsh/ruff) β Python linter and formatter.75- [uv](https://github.com/astral-sh/uv) β fast Python package installer and resolver.76 77## 4. Model Details78 79The final classification is performed by a custom-trained **Multilayer Perceptron (MLP)** model that takes the extracted embeddings as input.80 81- **Text Embedding Model:** `SentenceTransformer` (`all-MiniLM-L6-v2`)82- **Image Embedding Model:** `TFConvNextV2Model` (`convnextv2-tiny-22k-224`)83- **Classifier:** A custom MLP model trained on top of the embeddings.84- **Classes:** The model classifies products into a set of specific Best Buy product categories.85 86| Model | Modality | Accuracy | Macro Avg F1-Score | Weighted Avg F1-Score |87| :------------------ | :----------- | :------- | :----------------- | :-------------------- |88| Random Forest | Text | 0.90 | 0.83 | 0.90 |89| Logistic Regression | Text | 0.90 | 0.84 | 0.90 |90| Random Forest | Image | 0.80 | 0.70 | 0.79 |91| Random Forest | Combined | 0.89 | 0.79 | 0.89 |92| Logistic Regression | Combined | 0.89 | 0.83 | 0.89 |93| **MLP** | **Image** | **0.84** | **0.77** | **0.84** |94| **MLP** | **Text** | **0.92** | **0.87** | **0.92** |95| **MLP** | **Combined** | **0.92** | **0.85** | **0.92** |96 97> [!TIP]98>99> Based on the evaluation on the test set, the Multimodal MLP model achieved an excellent **92% accuracy** and a **92% weighted F1-score**, confirming its superior performance by leveraging both text and image data.100 