Views
No views yet
Optimized for FR / DE / LB, but works on “other” languages too.
1from transformers import pipeline
2pipe = pipeline(
3 "text-classification",
4 model="impresso-project/impresso-ad-classification-xlm-one-class",
5 trust_remote_code=True, # required to use the bundled pipeline.py
6 revision="v2.0", # optional adclassification model version. Latest version is the default one.
7)
8
9pipe("Appartement 3 pièces… Fr. 2'100.–, tél. 079 ...")
10# [{'label': 'AD', 'score': 0.87, 'promotion_prob': 0.83, 'threshold_used': 0.80,
11# 'xgenre_top_label': 'Promotion', 'xgenre_top_prob': 0.88, ...diagnostics...}]pipe(["texte A", "Text B"]) # → list of dicts in the same order1pipe([
2 {"ft": "Annonce en français ...", "lg": "fr"},
3 {"ft": "Mietwohnung ...", "lg": "de"}
4])model.safetensors / pytorch_model.bin + config.json + tokenizer filespipeline.py — custom HF pipeline that turns the multi-genre model into a binary ad detector (AD / NOT_AD)best_params_final.json — default inference knobs (loaded automatically if present)meta_classifier.pkl — extra stacking model (if you provide one)The Hugging Face inference widget doesn’t run custom code; use Python as shown above or build a small Space.
meta_classifier.pkl is present)ad_threshold: float — base threshold (per-language overrides below)lang_thresholds: str — e.g. "fr:0.58,de:0.62,lb:0.58,other:0.60"short_len: int, short_bonus: float — make short texts easier to flagmin_words: int — skip items with too few wordschunk_words: int — 0 = no chunking; else words per chunkmax_length: int — tokenizer max tokens per chunk (default 512)pool: str — one of max, mean, logits_max, logits_mean, logits_weightedtemperature: float — divides logits before softmax for calibrationmeta_clf: str — filename of a scikit-learn pickle in the repo (optional)return_diagnostics: bool — include rule flags & confidences (default True)1pipe(
2 ["Annonce FR ...", "Wohnung DE ..."],
3 ad_threshold=0.60,
4 lang_thresholds="fr:0.58,de:0.62,lb:0.58,other:0.60",
5 chunk_words=150,
6 pool="logits_weighted",
7 temperature=1.0,
8)pipeline.py also exposes a convenience method to mirror the CLI workflow:1from transformers import AutoPipelineForTextClassification
2p = AutoPipelineForTextClassification.from_pretrained(
3 "impresso-project/impresso-ad-classification-xlm-one-class",
4 trust_remote_code=True,
5)
6p.predict_jsonl("input.jsonl", "results.jsonl"){ "ft": "<text>" } (optionally "lg": "fr|de|lb|...")promotion_prob, promotion_prob_final (as score), is_ad_pred, etc.1{
2 "label": "AD" | "NOT_AD",
3 "score": <final_prob>, # after rules/ensembling
4 "promotion_prob": <raw model prob>, # 'Promotion' class
5 "threshold_used": <effective threshold>,
6 "xgenre_top_label": <top genre>,
7 "xgenre_top_prob": <top genre prob>,
8 # ... diagnostics (rule flags & confidences) unless return_diagnostics=False
9}min_words is set and the text is shorter, you’ll get:{"label": "SKIPPED", "score": None, ...}1pip install -U transformers huggingface_hub torch
2# optional: scikit-learn (only if you use meta_classifier.pkl)
3pip install -U scikit-learnlang_thresholds.pipeline.py — custom pipeline (loaded with trust_remote_code=True)best_params_final.json — default knobs; auto-loaded if presentmeta_classifier.pkl — optional meta-stackerREADME.md — this filefrom transformers import pipeline
pipe = pipeline('text-classification',
model='impresso-project/impresso-ad-classification-xlm-one-class',
trust_remote_code=True)
pipe("Annonce: 3 pièces à louer, Fr. 2'100.–/mois, tél. 079 ...")