Text Classification
Transformers
ONNX
Safetensors
fela-moderation
fela
fourier-neural-operator
fno
gated-linear-attention
cpu
on-device
content-moderation
toxicity
pii
byte-level
custom_code
Instructions to use lowdown-labs/fela-moderator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lowdown-labs/fela-moderator with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="lowdown-labs/fela-moderator", trust_remote_code=True)# Load model directly from transformers import AutoModelForSequenceClassification model = AutoModelForSequenceClassification.from_pretrained("lowdown-labs/fela-moderator", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
| from __future__ import annotations | |
| PAD_ID = 256 | |
| CLS_ID = 257 | |
| SEP_ID = 258 | |
| BYTE_VOCAB = 259 | |
| def encode_with_offsets(text: str, max_len: int, add_cls: bool = True): | |
| raw = text.encode("utf-8", errors="replace") | |
| ids: list[int] = [] | |
| offs: list[int] = [] | |
| if add_cls: | |
| ids.append(CLS_ID) | |
| offs.append(-1) | |
| budget = max_len - len(ids) | |
| for j, b in enumerate(raw[:budget]): | |
| ids.append(int(b)) | |
| offs.append(j) | |
| return (ids, offs, raw) | |
| def char_span_to_byte_span(text: str, c_start: int, c_end: int) -> tuple[int, int]: | |
| b_start = len(text[:c_start].encode("utf-8")) | |
| b_end = len(text[:c_end].encode("utf-8")) | |
| return (b_start, b_end) | |
| def spans_to_bio(text: str, spans, max_len: int, tag_to_id: dict) -> tuple[list, list]: | |
| ids, offs, _ = encode_with_offsets(text, max_len) | |
| o_id = tag_to_id["O"] | |
| tags = [o_id] * len(ids) | |
| for b_start, b_end, entity in sorted(spans, key=lambda s: s[0]): | |
| b_tag = tag_to_id.get(f"B-{entity}") | |
| i_tag = tag_to_id.get(f"I-{entity}") | |
| if b_tag is None or i_tag is None: | |
| continue | |
| first = True | |
| for pos, off in enumerate(offs): | |
| if off < 0: | |
| continue | |
| if b_start <= off < b_end: | |
| tags[pos] = b_tag if first else i_tag | |
| first = False | |
| return (ids, tags) | |