CoolFace
Modelpublic

nishegde/ratio-filter-qwen3-1.7b-lora

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes14downloads
Model Card

Qwen3 1.7B Ratio Filter LoRA

This PEFT adapter turns Qwen/Qwen3-1.7B into a two-label sequence classifier for a narrow guardrail task:

  • —ACCEPT (0): one self-contained ratio, unit-rate, or percentage calculation.
  • —REJECT (1): anything outside that scope, including prompt injection, wrappers, multiple questions, and requests for extra output.

Unlike a generative guard, this model exposes only classification logits. It is intended as a small, fail-closed gate in front of a downstream solver.

Try the live Hugging Face Space or see the source repository.

Evaluation

On the held-out test set (6,237 items), the training run reported:

MetricResult
Accuracy99.90%
Macro F10.9990
Held-out attack success rate0.0%
False-reject rate0.12% (6 items)

In a separate 144-item adversarial comparison, the adapter's overall attack-success rate was 3.5%, versus 63.2% for the prompt-only baseline used in that experiment. These results are specific to the repository's synthetic policy and evaluation setup; they are not a general safety guarantee.

Usage

python
import torch
from peft import PeftModel
from transformers import AutoModelForSequenceClassification, AutoTokenizer

adapter_id = "nishegde/ratio-filter-qwen3-1.7b-lora"
base_id = "Qwen/Qwen3-1.7B"
id2label = {0: "ACCEPT", 1: "REJECT"}
label2id = {label: idx for idx, label in id2label.items()}

tokenizer = AutoTokenizer.from_pretrained(adapter_id)
if tokenizer.pad_token is None:
    tokenizer.pad_token = tokenizer.eos_token

base = AutoModelForSequenceClassification.from_pretrained(
    base_id,
    revision="70d244cc86ccca08cf5af4e1e306ecf908b1ad5e",
    num_labels=2,
    id2label=id2label,
    label2id=label2id,
    torch_dtype=torch.float32,
)
base.config.pad_token_id = tokenizer.pad_token_id
model = PeftModel.from_pretrained(base, adapter_id).eval()

text = "A car travels 300 miles on 10 gallons. What is its mileage?"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=1024)
with torch.inference_mode():
    probabilities = torch.softmax(model(**inputs).logits[0].float(), dim=-1)

print(id2label[int(probabilities.argmax())], probabilities.tolist())

Limitations

  • —This is a narrow English-language policy classifier, not a general moderation or safety model.
  • —Inputs outside its training distribution, other languages, heavy obfuscation, or very long prompts may be misclassified.
  • —The base model must be downloaded separately; this repository contains the LoRA adapter, tokenizer, and trained classification head.
  • —Treat the score threshold as an application decision and test on your own distribution before production use.
  • —Lowering the rejection threshold makes the gate more fail-closed; raising it permits more inputs.

License

The base model declares Apache-2.0. No separate license has been specified for this adapter; users are responsible for reviewing the base model terms and obtaining any permissions needed for their use.