Instructions to use botezx/flagtldr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Grok
How to use botezx/flagtldr with Grok:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download classifier/src/xaddons_classifier/backends/embed.py from botezx/flagtldr: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/botezx/flagtldr/resolve/main/classifier/src/xaddons_classifier/backends/embed.py
- Command line
-
hf download hf://botezx/flagtldr/classifier/src/xaddons_classifier/backends/embed.py
-
curl -L -o embed.py https://huggingface.co/botezx/flagtldr/resolve/main/classifier/src/xaddons_classifier/backends/embed.py
2.02 kB
| """Embedding + trainable head: the "few labelled examples" path that trains in seconds. | |
| Encode examples + label rubrics (as extra pseudo-examples) with a multilingual sentence | |
| encoder, fit a logistic-regression head, predict calibrated-ish probabilities. | |
| Requires the `embed` extra: uv sync --extra embed | |
| Default model is multilingual and small; swap via --embed-model. | |
| """ | |
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| from ..spec import LabelSet, Post, Result | |
| DEFAULT_MODEL = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2" | |
| class EmbedBackend: | |
| name = "embed" | |
| def __init__(self, model: str = DEFAULT_MODEL): | |
| from sentence_transformers import SentenceTransformer # lazy: heavy import | |
| self.encoder = SentenceTransformer(model) | |
| self._heads: dict[str, object] = {} | |
| def _key(self, ls: LabelSet) -> str: | |
| return hashlib.sha1(json.dumps(ls.model_dump(), sort_keys=True).encode()).hexdigest() | |
| def _head(self, ls: LabelSet): | |
| k = self._key(ls) | |
| if k not in self._heads: | |
| from sklearn.linear_model import LogisticRegression | |
| texts = [e.text for e in ls.examples] + [f"{l.key}: {l.rubric}" for l in ls.labels] | |
| ys = [e.label for e in ls.examples] + [l.key for l in ls.labels] | |
| X = self.encoder.encode(texts, normalize_embeddings=True) | |
| self._heads[k] = LogisticRegression(max_iter=1000, C=4.0).fit(X, ys) | |
| return self._heads[k] | |
| async def classify(self, ls: LabelSet, posts: list[Post]) -> dict[str, Result]: | |
| head = self._head(ls) | |
| X = self.encoder.encode([p.text for p in posts], normalize_embeddings=True) | |
| out: dict[str, Result] = {} | |
| for p, row in zip(posts, head.predict_proba(X)): | |
| probs = {str(c): float(v) for c, v in zip(head.classes_, row)} | |
| best = max(probs, key=probs.get) | |
| out[p.id] = Result(label=best, probabilities=probs, confidence=probs[best], backend=self.name) | |
| return out | |