Spaces:
Running on Zero
Running on Zero
A newer version of the Gradio SDK is available: 6.24.0
metadata
title: Vertical SubverticalClassifier
emoji: π
colorFrom: green
colorTo: gray
sdk: gradio
sdk_version: 6.20.0
python_version: '3.12'
app_file: app.py
pinned: false
Hybrid upgrade: TF-IDF + MiniLM embeddings -> logistic regression
Adds semantic understanding so cases like "Barbers" land near beauty, not books. Same app, same output columns, same thresholds β only the model behind it changes.
What each file is
train_hybrid.pyβ trains the hybrid, saveshybrid_models.joblib. Run on GPU + internet.inference_hybrid.pyβ drop-in replacement forinference.py(sameclassify()output).requirements_hybrid.txtβ addssentence-transformers; use this on the Space.
Step 1 β train (Google Colab, free GPU, has HF access)
- New Colab notebook, Runtime β change type β GPU.
- Upload
Raw_data_vertical_subvertical.xlsxandtrain_hybrid.py. - Run:
(Pinning scikit-learn==1.8.0 is required so the saved model loads on the Space.)!pip install -q scikit-learn==1.8.0 sentence-transformers openpyxl !python train_hybrid.py - It prints held-out accuracy and writes
hybrid_models.joblib. Download that file. (emb_all.npyis just a cache β you don't need to upload it. Keep it if you want to re-tuneEMB_Wlater without re-embedding.)
Step 2 β deploy to the Space
- Upload
hybrid_models.joblibandinference_hybrid.py. - In
app.py, change the one import line:from inference import classify, VERT_THR, SUB_THR->from inference_hybrid import classify, VERT_THR, SUB_THR - Replace
requirements.txtwithrequirements_hybrid.txt(rename it torequirements.txt). - Commit. First build is slower (it downloads the embedding model, ~470 MB).
You can delete the old inference.py, vertical_model.joblib, and subvertical_model.joblib
once the hybrid is working β they're no longer used.
Tuning knob
EMB_W in train_hybrid.py (default 1.4) balances the two signals: higher = more semantic
(helps barbers-type cases), lower = more lexical (closer to the old behavior). Because
embeddings are cached in emb_all.npy, re-running with a new EMB_W is fast β no re-embedding.
Notes
- Inference embeds on CPU by default (fast enough for single names). Bulk uploads of many thousands of rows will be slower than the pure-TF-IDF version β that's the cost of semantics.
- Keep the
scikit-learn==1.8.0pin identical in Colab and on the Space, or the pickle won't load.