Text Classification
Transformers
ONNX
Safetensors
English
betterlens_dual_head
feature-extraction
sentiment-analysis
multi-task
distilbert
betterlens
starmatrix
custom_code
Instructions to use starmatrixtechnologies/betterlens-text-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use starmatrixtechnologies/betterlens-text-classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="starmatrixtechnologies/betterlens-text-classifier", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("starmatrixtechnologies/betterlens-text-classifier", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download loading_utils.py from starmatrixtechnologies/betterlens-text-classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/starmatrixtechnologies/betterlens-text-classifier/resolve/main/loading_utils.py
- Command line
-
hf download hf://starmatrixtechnologies/betterlens-text-classifier/loading_utils.py
-
curl -L -o loading_utils.py https://huggingface.co/starmatrixtechnologies/betterlens-text-classifier/resolve/main/loading_utils.py
1.77 kB
| """ | |
| Loading helper for the BetterLens dual-head model. | |
| Usage (note: requires trust_remote_code=True): | |
| from loading_utils import load_dual_head | |
| model, tokenizer = load_dual_head("starmatrixtechnologies/betterlens-text-classifier") | |
| out = model(**tokenizer("Something is just generally wrong these days.", | |
| return_tensors="pt", max_length=128, | |
| padding="max_length", truncation=True)) | |
| import torch | |
| probs = torch.softmax(out.sentiment_logits, dim=-1) | |
| print(probs[0]) # [positive, neutral, negative] | |
| print(out.vagueness_score) # [0..1] | |
| """ | |
| from transformers import AutoTokenizer, AutoModel | |
| def load_dual_head(model_id="starmatrixtechnologies/betterlens-text-classifier"): | |
| tokenizer = AutoTokenizer.from_pretrained( | |
| model_id, trust_remote_code=True, use_fast=True | |
| ) | |
| model = AutoModel.from_pretrained( | |
| model_id, trust_remote_code=True, torch_dtype="float32" | |
| ) | |
| model.eval() | |
| return model, tokenizer | |
| def predict(model, tokenizer, text, max_length=128): | |
| """Single-text convenience wrapper. Returns a dict with labels + scores.""" | |
| import torch | |
| enc = tokenizer( | |
| text, return_tensors="pt", max_length=max_length, | |
| padding="max_length", truncation=True, | |
| ) | |
| with torch.no_grad(): | |
| out = model(**enc) | |
| probs = torch.softmax(out.sentiment_logits, dim=-1)[0] | |
| label = out.sentiment_labels[0].item() | |
| names = list(model.config.sentiment_label_names) | |
| return { | |
| "text": text, | |
| "sentiment": names[label], | |
| "sentiment_probs": {n: float(p) for n, p in zip(names, probs)}, | |
| "vagueness": float(out.vagueness_score[0, 0]), | |
| } | |