sdg-classifier / README.md
PraveenNIPE's picture
Add ONNX export and tokenizer.json for Transformers.js
6edca37 verified
|
Raw History Blame Contribute Delete
2.46 kB
---
language: en
license: other
library_name: transformers
pipeline_tag: text-classification
base_model: bert-base-uncased
tags:
- sdg
- sustainable-development-goals
- multi-label-classification
- bert
---
# SDG Classifier
A multi-label text classifier that tags a project or policy description with the UN Sustainable Development Goals (SDGs) it relates to. It is `bert-base-uncased` fine-tuned with one sigmoid output per goal, so a text can match several goals.
## Goals covered
The model predicts 11 of the 17 SDGs:
| Label | Goal |
|---|---|
| SDG 1 | No Poverty |
| SDG 2 | Zero Hunger |
| SDG 4 | Quality Education |
| SDG 5 | Gender Equality |
| SDG 6 | Clean Water and Sanitation |
| SDG 7 | Affordable and Clean Energy |
| SDG 9 | Industry, Innovation and Infrastructure |
| SDG 10 | Reduced Inequalities |
| SDG 11 | Sustainable Cities and Communities |
| SDG 12 | Responsible Consumption and Production |
| SDG 13 | Climate Action |
SDGs 3, 8, 14, 15, 16 and 17 are not predicted.
## Usage
```python
from transformers import pipeline
clf = pipeline("text-classification", model="PraveenNIPE/sdg-classifier", top_k=None,
function_to_apply="sigmoid")
results = clf(["Encouraging young women to pursue careers in engineering and technology"])[0]
print([(r["label"], round(r["score"], 3)) for r in results if r["score"] > 0.3])
# [('SDG 5: Gender Equality', 0.637), ('SDG 9: Industry, Innovation and Infrastructure', 0.444)]
```
Use `function_to_apply="sigmoid"` and a threshold (0.3 works as a starting point). Each goal is scored independently, so the scores do not add up to 1.
## In the browser (Transformers.js)
`onnx/model.onnx` is a full-precision ONNX export for [Transformers.js](https://huggingface.co/docs/transformers.js). Load it with `dtype: "fp32"`; 8-bit quantized versions changed the predicted goals and are not provided. Apply a sigmoid to the logits, as above. Live demo: https://pnbayar.github.io/sdg-classifier/
## Limitations
This is an early prototype trained on a very small dataset of short project descriptions. Treat its output as a suggestion, not a judgement:
- It only knows the 11 goals above. Text about health, oceans, forests, peace or decent work will be assigned to the closest goal it does know.
- Confidence on text unlike its training examples is usually low (often 0.4–0.5 at best).
- It works best on short, single-topic English descriptions. Input is truncated at 512 tokens.