Content-Matched Triplets for Fine-Grained Dialect Identification

Telling apart closely related dialects, such as the Arabic of Cairo versus Alexandria or Damascus versus Beirut, is hard because two speakers talking about the same thing produce sentences that differ in only a few suffixes, function words, or spellings. Neural sentence encoders mostly represent what a sentence is about. On these tasks they tend to cluster sentences by topic rather than by dialect, and shallow character n-gram classifiers keep beating them in shared tasks. We propose to train a pretrained Arabic encoder with a triplet loss. A triplet loss is an objective that pulls an "anchor" example toward a "positive" of the same class and pushes it away from a "negative" of a different class by at least a fixed margin. The departure from earlier dialect work lies in how the triplets are built. The negative is the same sentence rendered in a different dialect, and the positive is a different sentence in the same dialect. Under that construction the only way to satisfy the loss is to encode the dialect markers themselves, because shared content and topic help with neither the pull nor the push.

The opportunity comes from a feature of the MADAR travel corpus, which contains parallel translations of the same underlying sentences into 25 city dialects plus Modern Standard Arabic (The MADAR Shared Task on Arabic Fine-Grained Dialect Identification). Cross-entropy training ignores this pairing: it sees each sentence alone. A triplet loss can use the pairing directly, which gives metric learning a role in dialect identification that a better-tuned classifier cannot copy. The claim we test goes beyond in-domain accuracy. We expect embeddings trained this way to transfer better to non-parallel social media text, and to place unseen cities near their geographic neighbours.

Core Claim

Triplet loss helps fine-grained dialect identification only when its negatives hold content fixed. Concretely, we expect three results. First, an encoder trained with content-matched negatives will beat the same encoder trained with ordinary class-label triplets, and will beat cross-entropy alone. Second, the gap will be larger on out-of-domain test sets than in-domain. Third, a linear probe will recover sentence content from these embeddings much less easily than from the baselines' embeddings. If class-label triplets do as well as content-matched ones, the claim is wrong. Metric learning would then be adding nothing over a well-regularized classifier.

Position Relative to Prior Work

Two papers have applied metric learning to dialects, and both motivate this proposal by what they left unresolved. DTeam @ VarDial 2019 trained a character CNN with triplet loss for the binary Moldavian/Romanian task, sampling triplets from class labels only. Its dialect identification was strong (macro-F1 0.89, 0.93 after post-competition pre-training). Cross-dialect topic transfer, however, fell to 0.39 and 0.44 in the competition, which the authors read as evidence that the representation had not separated dialect from topic. AlexUNLP-STM at NADI 2024 added a contrastive loss (NT-Xent) to MARBERTv2 and AraBERTv2. It reported gains over plain regression, but only for scalar "level of dialectness" estimation (test RMSE 0.1406), not for geographic classes. Neither paper controls what the negatives share with the anchor. That control is our contribution.

Hierarchical approaches set constraints on the design. Hierarchical Deep Learning for Arabic Dialect Identification found that a region-then-city BiLSTM cascade gained only 2 points over a flat BiLSTM (0.58 vs 0.56) and lost to a Naive Bayes plus random forest vote (63.02%). Hierarchical Aggregation of Dialectal Data aggregated 15 million lines into region/country/city KenLM features and moved MADAR-26 accuracy only from 67.69% to 68.13%. Both results suggest that adding taxonomy, or more data, to the classifier yields little. This is why we do not make a geographic-tree margin in the style of Deep Metric Learning with Hierarchical Triplet Loss our central idea, even though that paper supplies a useful sampling technique. A tree-shaped margin encodes roughly what soft geographic labels in cross-entropy would encode. A reviewer could reasonably expect the two to perform the same. The HTL-style margin appears below only as a secondary ablation.

The mining technique comes from batch-hard triplet mining, which selects the closest wrong-class example in each mini-batch. Examples include Multiple Saliency and Channel Sensitivity Network and Large-Scale Topological Radar Localization Using Learned Descriptors. We restrict that search to translations of the anchor's own sentence. The encoder comes from Adapting MARBERT for Improved Arabic Dialect Identification, which documents heavy confusion between neighbouring provinces and over-prediction of dominant dialects under cross-entropy.

Research Program

The encoder is MARBERT with a small projection head producing an L2-normalized embedding $f(x)$. Training batches are built from MADAR's parallel structure. Each batch samples $K$ source sentence IDs and, for each ID, $M$ of its city renditions, so that every anchor $a$ (sentence $s$, city $c$) has two kinds of partners in the batch. Its negatives are the other cities' renditions of sentence $s$. Its positives are sentences other than $s$ from city $c$, so the sampler must also ensure that each city appears with at least two sentence IDs. We take the hardest of each kind and train with

$$\mathcal{L} = \mathcal{L}_{\text{CE}} + \lambda \max\big(0,\ \max_{p} d(a,p) - \min_{n:\ \text{sent}(n)=s,\ \text{city}(n)\neq c} d(a,n) + \alpha\big),$$

where $d$ is cosine distance, $\alpha$ is the margin, $\lambda$ weights the triplet term, and $\mathcal{L}_{\text{CE}}$ is an ordinary 26-way classification loss on the same embedding. The cross-entropy term is kept to guard against the collapse failure noted for triplet training. The Modern Standard Arabic rendition of $s$ is always included among the candidate negatives. It acts as an explicit counterweight to the "MSA shadow" that NADI 2020 reports in about half of dialectal tweets.

To test generality beyond Arabic, we use MOROCO, which has no parallel sentences but does have topic labels. There we apply the same logic at topic level: the negative is a same-topic, different-dialect sample, and the positive is a different-topic, same-dialect sample. This directly targets the topic-transfer failure seen in DTeam.

The analysis has three parts. First, a linear probe tries to predict sentence ID (MADAR) or topic (MOROCO) from frozen embeddings; lower probe accuracy means the representation carries less content. Second, a nearest-neighbour classifier over embeddings measures how much of the gain lives in the geometry rather than in the classification head. Third, a held-out-city test retrains with one city removed, embeds that city's sentences, and checks whether their nearest class centroids are the cities geographically closest to it.

Baselines

The naive reference is a majority-class predictor, together with MARBERT fine-tuned with cross-entropy alone on the same data, learning-rate grid, and number of steps as our model. On MADAR-26 we found no reported result on Lacuna for plain MARBERT cross-entropy fine-tuning, so we run it ourselves. It defines how much any loss change adds.

The strongest existing system on MADAR-26 is the ArbDialectID ensemble of Multinomial Naive Bayes and linear SVM over character 2–5-gram and word n-gram TF-IDF features (ArbDialectID at MADAR Shared Task 1). It reports a test macro-F1 of 67.32% (accuracy 67.29%), which was the winning shared-task score. The KenLM-aggregated variant reports 68.13% accuracy (Hierarchical Aggregation). We rerun the n-gram ensemble on the official splits with tuned n-gram ranges, so that both systems see identical training data. Beating it means exceeding 67.32% macro-F1 on the official test set, with the difference significant under paired bootstrap across five seeds. For transfer, the reference points are the MADAR Twitter country-level winner at 71.70% macro-F1 (MADAR shared task) and the NADI 2021 province-level MARBERT ensemble at 32.26% test F1 (Adapting MARBERT). Our zero-shot transfer models are not trained on those sets, so we do not expect to beat these supervised winners. They calibrate scale only, and the transfer comparison we score is against our own cross-entropy and class-label-triplet models.

The ablation that isolates the key ingredient is identical training with batch-hard triplets whose negatives are any different-city sentence in the batch, not restricted to translations. Batch composition, $\lambda$, $\alpha$, and the tuning budget are all matched. A second ablation replaces content-matched negatives with an HTL-style geographic margin, to separate the content-control effect from the taxonomy effect. A third replaces the triplet term with supervised contrastive loss over class labels, matching the AlexUNLP-style objective.

Why not just…?

Why not just use the character n-gram SVM, which already wins? On clean parallel MADAR it may well stay competitive in-domain, and we treat that as a real possibility. The evidence against it as the final answer comes from social text. The MADAR Twitter subtask was won by a neural system, and the NADI 2020 province task reached only 6.39% F1 even with BERT features (NADI 2020). Our transfer experiments test whether content-matched embeddings carry over to that regime better than n-gram features trained on the same MADAR data. We also report a fusion system, n-gram features concatenated with our embeddings and fed to an SVM in the manner of DTeam. If fusion is what wins, that is the result we report.

Why not just fine-tune MARBERT with cross-entropy plus soft geographic labels or class-balanced sampling? This is the strongest threat to any taxonomy-based metric idea, and it is why we did not build the proposal around tree margins. A classifier sees one sentence at a time, so it cannot be told that the Cairo and Beirut versions of the same sentence must be separated by dialect evidence alone. We run cross-entropy with label smoothing toward geographic neighbours and with inverse-frequency sampling as additional baselines under the same budget. If they match our model on transfer and on the content probe, the claim fails.

Why not just remove content adversarially, with a gradient-reversal head predicting sentence ID? This is a legitimate alternative that also uses the parallel structure. It removes content information but gives no positive pressure to amplify dialect markers. We implement it with tuned reversal strength and compare it on the same three measures. If it ties, our contribution narrows to showing that parallel-data content control matters, regardless of whether a triplet or an adversary enforces it.

Proposed Experiments

The main experiment trains all systems on MADAR-26 and evaluates macro-F1 on the official test set. It then evaluates zero-shot on the 21-country MADAR Twitter set and on NADI 2021 country-level dialectal tweets, after collapsing city predictions to countries. The decisive check is the comparison between content-matched and class-label triplets on these out-of-domain sets. Our hypothesis predicts a larger gap there than in-domain, together with lower sentence-ID probe accuracy. If the gap is absent out-of-domain, or the probe shows no reduction, the content-control mechanism is not doing what we claim.

The MOROCO replication uses the topic-matched variant. We compare dialect macro-F1 against DTeam's reported 0.89 and 0.93. More importantly, we measure topic transfer across dialects, where DTeam reached 0.39 and 0.44 during the competition and 0.66 and 0.80 after pre-training. The held-out-city test asks whether an unseen city's sentences fall nearest its geographic neighbours more often than they do under cross-entropy embeddings. A classifier's fixed label set cannot express this, which makes it the clearest test of whether the learned space is a genuine dialect map.