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/rules.py from botezx/flagtldr: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/botezx/flagtldr/resolve/main/classifier/src/xaddons_classifier/backends/rules.py
- Command line
-
hf download hf://botezx/flagtldr/classifier/src/xaddons_classifier/backends/rules.py
-
curl -L -o rules.py https://huggingface.co/botezx/flagtldr/resolve/main/classifier/src/xaddons_classifier/backends/rules.py
1.44 kB
| """Zero-dependency fallback (same idea as extension/src/lib/labelset.js rulesClassify).""" | |
| from __future__ import annotations | |
| import math | |
| import re | |
| import unicodedata | |
| from ..spec import LabelSet, Post, Result | |
| def _tok(s: str) -> list[str]: | |
| s = unicodedata.normalize("NFKD", (s or "").lower()) | |
| s = "".join(c for c in s if not unicodedata.combining(c)) | |
| return [w for w in re.split(r"[^\w]+", s) if len(w) > 2] | |
| class RulesBackend: | |
| name = "rules" | |
| def classify_one(self, ls: LabelSet, text: str) -> Result: | |
| t = set(_tok(text)) | |
| scores: dict[str, float] = {} | |
| for l in ls.labels: | |
| bag = set(_tok(l.rubric)) | |
| for e in ls.examples: | |
| if e.label == l.key: | |
| bag |= set(_tok(e.text)) | |
| inter = len(t & bag) | |
| scores[l.key] = (inter + 0.1) / (math.sqrt(len(t) * len(bag)) + 1) | |
| noise = next((l for l in ls.labels if l.action in ("collapse", "hide")), None) | |
| if noise and len(t) <= 2: | |
| scores[noise.key] += 1 | |
| total = sum(scores.values()) or 1.0 | |
| probs = {k: v / total for k, v in scores.items()} | |
| best = max(probs, key=probs.get) | |
| return Result(label=best, probabilities=probs, confidence=probs[best], backend=self.name) | |
| async def classify(self, ls: LabelSet, posts: list[Post]) -> dict[str, Result]: | |
| return {p.id: self.classify_one(ls, p.text) for p in posts} | |