CoolFace
Apppublic

LukeFP/Physh_Classification

sourceHugging Faceapache-2.0updated 2d agoView on Hugging Face
0likes
README.md94 linesDownload Raw Back to root
1---2title: Physh Classification3emoji: πŸ†4colorFrom: red5colorTo: purple6sdk: gradio7sdk_version: 6.28.08python_version: '3.12'9app_file: app.py10pinned: false11license: apache-2.012models:13  - LukeFP/physh_topic_supervised_classifier14  - google/embeddinggemma-300m15---16 17# PhySH Topic Classifier18 19Paste a physics title and abstract; get back its [PhySH](https://physh.org)20**disciplines** and **top-level research-area concepts**.21 22## How it works23 24```25text ──EmbeddingGemma-300m──> 768-d vector26          β”‚27          β”œβ”€β”€> discipline head   768 β†’ 1024 β†’ 512 β†’ 18    sigmoid28          β”‚                                    β”‚29          └──> concept head  [768 + 18] β†’ 1024 β†’ 512 β†’ 186 sigmoid30                                   β–²31                       discipline probabilities32```33 34Both heads are multi-label MLPs with ReLU and dropout 0.3, trained on35EmbeddingGemma vectors. The concept head is *conditioned* on the discipline36head's output: its 786-dimensional input is the text embedding concatenated with37the 18 discipline probabilities (the checkpoint records `use_logits: False`, so38probabilities rather than logits are what it expects).39 40Weights live in41[`LukeFP/physh_topic_supervised_classifier`](https://huggingface.co/LukeFP/physh_topic_supervised_classifier)42and are downloaded at startup, so retraining only requires a push to that repo β€”43no change here.44 45| Head | micro-F1 | macro-F1 | avg labels/sample |46|---|---|---|---|47| Discipline (18) | 0.799 | 0.683 | 1.41 |48| Concept (186) | 0.641 | 0.423 | 2.12 |49 50## Setup51 52`google/embeddinggemma-300m` is a gated repo. Accept the Gemma license on the53model page, then add a read token as a Space secret named `HF_TOKEN`54(Settings β†’ Variables and secrets). Without it the Space boots but the first55classification fails.56 57This Space runs on **ZeroGPU**: `infer()` carries the `@spaces.GPU` decorator,58the models are loaded on CPU in the main process, and device placement happens59inside the decorated function. The same code runs unchanged on CPU hardware β€”60`spaces` is optional at import and `torch.cuda.is_available()` picks the device.61 62### Prompt format63 64EmbeddingGemma prepends a task-specific prefix, and the prefix used here must65match the one used to build the training embeddings β€” a mismatch degrades66accuracy quietly instead of erroring. The default is the document prompt67(`title: none | text: …`); the Advanced panel lets you switch and compare.68 69## Running locally70 71```bash72pip install -r requirements.txt73export HF_TOKEN=hf_...74python app.py75```76 77Set `PHYSH_WEIGHTS_DIR=/path/to/physh_topic_supervised_classifier` to load the78`.pt` files from a local clone instead of the Hub.79 80## API81 82Gradio exposes the Space as an API, which is the practical route for batch83labelling:84 85```python86from gradio_client import Client87 88client = Client("LukeFP/Physh_Classification")89disciplines, concepts, summary = client.predict(90    "Title and abstract…", 0.5, "document β€” title: none | text: {}", 8,91    api_name="/classify",92)93```94