Token Classification
Transformers
Safetensors
lfm2
feature-extraction
liquid
lfm2.5
bidirectional
masked-lm
encoder
custom_code
Instructions to use LiquidAI/LFM2.5-Encoder-350M-Policy-Linter with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LiquidAI/LFM2.5-Encoder-350M-Policy-Linter with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="LiquidAI/LFM2.5-Encoder-350M-Policy-Linter", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("LiquidAI/LFM2.5-Encoder-350M-Policy-Linter", trust_remote_code=True) model = AutoModel.from_pretrained("LiquidAI/LFM2.5-Encoder-350M-Policy-Linter", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
LFM2.5-Encoder-350-Policy-Linter
A full fine-tune of LFM2.5-Encoder-350M with a rule-matching head that scores every text token against free-text policy rules in a single encoder pass.
Find more details about our encoders in our blog post.
๐ป Demos: Try this fine-tuned model running in a CPU-only Hugging Face space: Zero-shot policy linting** โ check text against your company's rules, written as free text. It scores every token against every rule in one pass.
Usage
โ ๏ธ Loads custom code via
trust_remote_code=True(the model wraps atrust_remote_codeencoder).
Install the required packages:
pip install torch transformers
Run zero-shot policy linting:
import sys
from pathlib import Path
import torch
from transformers import AutoTokenizer
repo = Path(".")
sys.path.insert(0, str(repo))
from train_bizlint_v02 import Lfm2BidirForRuleMatching
rules = [
"Flag direct mentions of competitor companies.",
"Flag promises about guaranteed financial returns.",
]
text = "Our product is better than AcmeAI and will guarantee 30% savings."
prefix = "Policy:\n" + "\n".join(f"- {rule}" for rule in rules) + "\n\nText:\n"
full_text = prefix + text
tokenizer = AutoTokenizer.from_pretrained(repo, trust_remote_code=True)
model = Lfm2BidirForRuleMatching.from_pretrained(repo, trust_remote_code=True).eval()
enc = tokenizer(full_text, return_offsets_mapping=True, return_tensors="pt")
offsets = enc.pop("offset_mapping")[0].tolist()
rule_pool = torch.zeros(1, len(rules), len(offsets))
pos = len("Policy:\n")
for rule_idx, rule in enumerate(rules):
start = pos + 2
end = start + len(rule)
token_idxs = [
i for i, (a, b) in enumerate(offsets)
if a < end and b > start and a != b
]
rule_pool[0, rule_idx, token_idxs] = 1 / len(token_idxs)
pos = end + 1
with torch.no_grad():
probs = model(**enc, rule_pool=rule_pool)["logits"].sigmoid()[0]
text_start = len(prefix)
for token_idx, (a, b) in enumerate(offsets):
if b <= text_start or a == b:
continue
token_text = full_text[a:b]
for rule_idx, prob in enumerate(probs[token_idx]):
if prob.item() > 0.5:
print(f"{token_text!r} -> {prob.item():.3f}: {rules[rule_idx]}")
๐ฌ Contact
- Got questions or want to connect? Join our Discord community
- If you are interested in custom solutions with edge deployment, please contact our sales team.
Citation
@article{liquidAI2026Encoders,
author = {Liquid AI},
title = {LFM2.5-Encoders: Fast at Long Context, Even on CPU},
journal = {Liquid AI Blog},
year = {2026},
note = {www.liquid.ai/blog/lfm2-5-encoders},
}
- Downloads last month
- 4
Model tree for LiquidAI/LFM2.5-Encoder-350M-Policy-Linter
Base model
LiquidAI/LFM2.5-350M-Base Finetuned
LiquidAI/LFM2.5-Encoder-350M