A Name Entity Recognition model based on AlgerianDeBERTa, finetuned to extract 13 real-estate entities from Algerian Facebook posts
Handles the exact language mix found on Facebook Marketplace and Algerian classified groups: Darja (Algerian dialect), Arabizi (Arabic written in Latin script), French, and heavy code-switching, finetuned on +7k examples of pure algerian real-estate posts from Facebook
algerianDeBERTa (pre-trained on Algerian web text)
Task
Token classification — 27 BIO labels, 13 entity types
Languages
Algerian Darja · Arabizi · French · MSA · Code-switched
Domain
Real estate classifieds (sales, rentals, land, villas, apartments)
Test F1
0.9672 micro (seqeval, strict entity-level)
Best val F1
0.9858
Parameters
~60M
License
Apache 2.0
Quick Start
Option 1 : pipeline (standard, recommended for short texts)
Uses aggregation_strategy="max": for each surface word the subword token with the highest entity-class score wins, then consecutive spans that have the same type are merged automatically
python
1from transformers import pipeline
23ner = pipeline(4"token-classification",5 model="81melody/algerianDeBERTa-realestate-ner",6 aggregation_strategy="max",7)8910print(ner("سلام ، خصني اف2 فالعاصمة في ميسوني ولا اودان ولا ديدوش ، في هاد الجويه لي عندو يتوصل معيا في الخاص"))1112print(ner("Appartement F4 à vendre Oran centre 120m² 4ème étage acte notarié"))13
For texts that may exceed 192 tokens, pass sliding-window arguments directly to the pipeline call:
For real estate posts that frequently exceed one chunk + to adapt with The small vocab size of the first version of the base model (30k), the approach below is more robust for production use: it averages the probability vectors of overlapping tokens across all chunks, then merges subword pieces that form the same surface word before BIO decoding
This fixes a common artefact where words like "cherche" (tokenised as ["cher", "che"]) or prices like "1.700" (tokenised as ["1", ".", "700"]) get truncated mid-word if a trailing subword happens to predict O
python
1from transformers import AutoTokenizer, AutoModelForTokenClassification
2import torch
3import numpy as np
4from typing import List
56MODEL_NAME ="81melody/algerianDeBERTa-realestate-ner"7MAX_SEQ_LEN =1928STRIDE =64910tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)11model = AutoModelForTokenClassification.from_pretrained(MODEL_NAME)12model.eval()13device = torch.device("cuda"if torch.cuda.is_available()else"cpu")14model.to(device)151617defextract_entities(text:str)-> List[dict]:1819 enc = tokenizer(20 text,21 return_tensors="pt",22 max_length=MAX_SEQ_LEN,23 stride=STRIDE,24 truncation=True,25 return_overflowing_tokens=True,26 return_offsets_mapping=True,27 padding="max_length",28)29 enc.pop("overflow_to_sample_mapping",None)30 offsets = enc.pop("offset_mapping")313233with torch.no_grad():34 logits = model(**{k: v.to(device)for k, v in enc.items()}).logits
35 probs = torch.softmax(logits, dim=-1).cpu().numpy()36 attention = enc["attention_mask"].numpy()37 off_np = offsets.numpy()383940 char_probs ={}41for c inrange(probs.shape[0]):42for t inrange(off_np.shape[1]):43if attention[c, t]==0:44continue45 cs, ce =int(off_np[c, t,0]),int(off_np[c, t,1])46if cs ==0and ce ==0:47continue48if cs notin char_probs:49 char_probs[cs]={"end": ce,"vecs":[probs[c, t]]}50else:51 char_probs[cs]["vecs"].append(probs[c, t])5253ifnot char_probs:54return[]5556 items =sorted(char_probs.items())5758 word_tokens =[]59 w_start, w_info = items[0]60 w_end = w_info["end"]61 w_avg_p = np.mean(w_info["vecs"], axis=0)6263for cs, info in items[1:]:64if cs == w_end:65 w_end = info["end"]66else:67 word_tokens.append({"start": w_start,"end": w_end,"avg_p": w_avg_p})68 w_start = cs
69 w_end = info["end"]70 w_avg_p = np.mean(info["vecs"], axis=0)71 word_tokens.append({"start": w_start,"end": w_end,"avg_p": w_avg_p})7273 label_map = model.config.id2label
74 entities, current =[],None7576for w in word_tokens:77 idx =int(np.argmax(w["avg_p"]))78 label = label_map[idx]79 score =float(w["avg_p"][idx])8081if label =="O":82if current:83 entities.append(current)84 current =None8586elif label.startswith("B-"):87if current:88 entities.append(current)89 current ={90"entity": label[2:],91"word": text[w["start"]:w["end"]],92"score": score,93"_sc":[score],"_s": w["start"],"_e": w["end"],94}9596elif label.startswith("I-"):97 etype = label[2:]98if current and current["entity"]== etype:99 current["word"]= text[current["_s"]:w["end"]]100 current["_e"]= w["end"]101 current["_sc"].append(score)102 current["score"]=float(np.mean(current["_sc"]))103else:104if current:105 entities.append(current)106 current ={107"entity": etype,108"word": text[w["start"]:w["end"]],109"score": score,110"_sc":[score],"_s": w["start"],"_e": w["end"],111}112113if current:114 entities.append(current)115116return[117{"entity": e["entity"],"word": e["word"],"score":round(e["score"],6)}118for e in entities
119]120121122123
Entity Schema
The model uses a 27-label BIO scheme covering 13 entity types drawn directly from Algerian real estate Facebook market
Metric: seqeval entity-level strict match (not token-level an entity prediction counts as correct only if both the span and the label match the annotation exactly)
Language distribution: Arabic (Darja) 53% · French 34% · Mixed / Arabizi 13% Listing intent: Seller 95.4% · Buyer 4.6%
All posts were collected from public Algerian Facebook real estate groups(using Facebook API in the Apify platforl) Phone numbers are replaced with [PHONE] before publishing (BIO tags preserved so the model learns positional context without memorizing digits)
Training Details
yaml
1base_model: algerianDeBERTa (DeBERTa-v2)
2architecture: DebertaV2ForTokenClassification
3num_labels: 27 (BIO, 13 entity types)
456max_seq_len:1927stride:648910optimizer: AdamW
11peak_lr:2e-512llrd_factor:0.913weight_decay:0.0114adam_eps:1e-615adam_beta1:0.916adam_beta2:0.99917max_grad_norm:1.018grad_accum_steps:21920epochs: 20 (early stop at epoch 14, patience=5)
21warmup_ratio:0.122schedule: cosine with warmup
232425label_smoothing:0.0526class_weighting: inverse-frequency,capped at 10× (rare tags: CITY, WILAYA, CONDITION)
27dropout: 0.1 (attention + hidden)
282930best_val_f1:0.985831test_f1:0.967232test_precision:0.956633test_recall:0.9780
Training highlights
Layerwise Learning Rate Decay (LLRD): The classifier head trains at peak_lr=2e-5, each successive DeBERTa layer is scaled by 0.9×, reaching ≈4.3e-6 at the embedding layer, This preserves general language representations while aggressively adapting the top layers to the NER task
Weighted label-smoothed cross-entropy: Rare entity tags (CITY, WILAYA, CONDITION) carry up to 10× the loss weight of frequent tags , Label smoothing (ε=0.05) prevents the model from becoming over-confident on the abundant O tag
Sliding-window tokenization: Posts exceeding 192 tokens are split into overlapping chunks (stride=64). Predictions from overlapping windows are reconciled at entity boundaries, ensuring long posts are fully covered without truncation
Limitations
NEIGHBORHOOD F1=0.85: Neighbourhood names in Algeria are highly variable in spelling across Arabic, French, and Arabizi. This entity is underrepresented in the training data (188 annotations). Performance will improve with more annotated data from underrepresented neighbourhoods
PRICE edge cases: Non-standard price expressions that rely heavily on slang are occasionally missed, The model handles the most common formats reliably
Platform distribution: Trained on Facebook posts — casual, informal register. May underperform on formal Arabic (MSA) or structured portal listings
Purely extractive: This is a span classifier, not a generative model. It labels tokens; it does not summarise or rewrite listings
Intended Use
Use case
Notes
Structured extraction from classifieds
This is the Core use case , extract price, surface, location, type from raw posts
Real estate market analytics
Build price-per-m² indices by wilaya; track inventory trends
Lead enrichment pipelines
Enrich CRM records from social media listing text
Training data generation
Use model outputs as silver labels for downstream tasks
Algerian NLP research
Low-resource benchmark for Darja and Arabizi NER
Citation
If you use this model or the dataset in your research, please cite:
bibtex
1@misc{himeur2026algeriandeberta_ner,
2 title = {algerianDeBERTa-realestate-ner: Named Entity Recognition
3 for Algerian Real Estate Text in Darja, Arabizi, and French},
4 author = {Himeur, Ayoub},
5 year = {2026},
6 publisher = {Hugging Face},
7 url = {https://huggingface.co/81melody/algerianDeBERTa-realestate-ner},
8 note = {Fine-tuned DeBERTa-v2 on annotated
9 Algerian Facebook real estate posts, 13 entity types}
10}