Care operations · Research feature

Generalistic or Specific Embeddings, Which is Better? An Empirical Study on Search for Clinical Coding in Non-English Languages

The researchers assessed a two-stage retrieval model trained on synthetic data generated by large language models, focusing on Spanish clinical coding using the CodiESP v4 dataset.

Adapted from research by David Rey-Blanco, Roberto Cruz.

arXiv preprint revision · 2026-05-28 · Attribution & reuse
In this article
Editorial illustration of stack of documents.

Editor’s introduction

The researchers assessed a two-stage retrieval model trained on synthetic data generated by large language models, focusing on Spanish clinical coding using the CodiESP v4 dataset. The model, built from a Spanish biomedical encoder and enhanced with a cross-encoder reranker, achieved better recall at top ranks than the untrained Spanish encoder and matched BioBERT-ST in mean reciprocal rank. The model’s performance on Portuguese reached 0.829 R@5 compared to BioBERT-ST’s 0.714, demonstrating improved retrieval precision in low-resource settings.

Introduction

Clinical coding is a high-stakes text-to-code retrieval problem. Given a short clinical mention, complaint, or fragment of a medical note, the system must retrieve the correct entry from a controlled terminology such as ICD-10-CM or its Spanish adaptation, CIE-10. This is harder than ordinary semantic search because adjacent codes often describe clinically similar conditions that differ by a qualifier such as organism, laterality, severity, episode type, or anatomical location. A useful model must therefore retrieve the right clinical variant, not only the right disease family.

Modern dense retrieval usually addresses this kind of problem with two stages. A bi-encoder first projects queries and candidate descriptions into a shared vector space and retrieves a shortlist efficiently. A cross-encoder then jointly reads the query and each candidate in the shortlist to produce a more precise relevance score. This recall-then-rerank architecture is common in retrieval-augmented generation and in automatic ICD coding.

The difficulty is that most public embedding models and biomedical NLP resources are still centred on English. BioBERT, ClinicalBERT, and related models are strong on English EHRs and biomedical benchmarks such as PubMedQA, but Spanish, Catalan, Italian, Portuguese, and other clinical languages are under-represented. Multilingual encoders help, but clinical retrieval remains fragile when abbreviations, morphology, surface forms, and coding conventions vary across languages.

The limitations of clinical coding models

The central issue is not only the lack of model capacity. General-purpose encoders are usually trained to capture broad semantic relatedness, whereas clinical coding requires fine-grained equivalence. For example, “Brucelosis debida a Brucella suis” and “Brucelosis debida a Brucella melitensis” are semantically close but not interchangeable as codes. The same tension appears across thousands of CIE-10 descriptions: the nearest clinical neighbour is often the wrong answer.

Four practical limitations follow from this setting. First, tokenisation and pretraining corpora under-cover non-English clinical morphology, which can flatten important lexical distinctions. Second, biomedical pretraining does not necessarily transfer if it was learned in another language or on a different clinical distribution. Third, cross-lingual transfer degrades in dense retrieval because small representation shifts can change the top-1 result. Fourth, two-stage systems can be misaligned: a reranker cannot recover the correct code if the bi-encoder never retrieves it, and a high-recall bi-encoder is insufficient if it cannot order clinically adjacent candidates.

The data problem is equally important. Labelled clinical data is expensive because annotation requires both medical and linguistic expertise. In multilingual coding, the data must also match the local coding vocabulary and the intended level of granularity. A corpus labelled at chapter level does not teach full-code distinctions, and an English ICD corpus does not necessarily contain the Spanish, Catalan, or Portuguese expressions that a local coding system must handle.

Proposal, results, and contributions

We study whether LLM-generated synthetic supervision can make domain- and language-specific clinical retrievers practical under these data constraints. Rather than using synthetic data only as generic augmentation, we use an LLM as a tutor for a controlled label space: given a code, definition, neighbouring codes, and target language, the generator creates clinical mentions, paraphrases, and hard negatives that force the model to learn the decision boundary. This follows recent work on LLM-generated instruction and retrieval data and on clinical synthetic text generated from domain knowledge or labels.

Concretely, we train a two-stage retriever for Spanish CIE-10/ICD-10 search. The bi-encoder is fine-tuned from PlanTL-GOB-ES/bsc-bio-ehr-es on about 19,500 multilingual synthetic pairs covering English, Spanish, Catalan, Italian, Portuguese, and French. The cross-encoder reranker is trained on roughly 10,600 listwise groups with clinically plausible hard negatives. We evaluate the resulting system on two held-out Spanish clinical coding datasets, CodiESP v4 and DISTEMIST, at full-code, category, and chapter resolution.

The main result is that targeted synthetic supervision and reranking produce a large improvement over public baselines. On CodiESP, the complete system reaches 70.9% top-1 exact accuracy, improving by 48.4 percentage points over the best public encoder tested, MiniLM-L6-v2, and by 51.6 points over the in-domain English S-BioBERT baseline. On DISTEMIST, it reaches 77.6% top-1 exact accuracy. The results also show that larger embeddings and biomedical pretraining alone are not enough: MPNet-v2 underperforms MiniLM-L6-v2, while S-BioBERT underperforms both despite domain-specific pretraining.

Synthetic data is not treated here as a substitute for real clinical evaluation, thus generated examples can be too regular, biased toward the generator’s preferred phrasing, or detached from the noise of real notes. For that reason, we use synthetic data only for supervision and evaluate exclusively on held-out human clinical coding datasets (using human-anotated sets only for this task).

This paper is structured as follows. The methodology section describes the synthetic data generation process, the bi-encoder, and the cross-encoder. The experimental design section defines the CIE-10 hierarchy, the search backend, the baseline models, the evaluation datasets, and the metrics. The results section reports performance on CodiESP and DISTEMIST. The discussion compares the findings with public benchmarks and related ICD coding literature, and the final sections summarize limitations and future work.

System overview

We train a two-stage neural retrieval architecture for ICD code search following the retrieve-and-rerank paradigm commonly used in dense information retrieval systems. In the first stage, a bi-encoder retrieves the top-k candidate ICD descriptions using cosine similarity in a shared embedding space. In the second stage, a cross-encoder jointly models the query and each retrieved candidate to rerank results by semantic relevance.

The bi-encoder is initialised from PlanTL-GOB-ES/bsc-bio-ehr-es and fine-tuned with MultipleNegativesRankingLoss using multilingual synthetic positive pairs and in-batch negatives, while the reranker is optimised with a listwise softmax cross-entropy objective over one positive and up to nine hard negatives per query.

Synthetic data generation for training

Dataset A was intentionally designed as a compact but high-quality synthetic corpus. Rather than relying on web-scale weak supervision, we focus on clinically grounded examples with difficult in-chapter negatives that force the bi-encoder to learn fine-grained semantic distinctions between related diagnoses. This design follows the hypothesis that, for specialised medical retrieval tasks, carefully curated synthetic supervision can compensate for limited dataset size. A central aspect of the dataset construction is the balance between hard and soft negatives. Hard negatives expose the model to clinically adjacent concepts that may differ only in severity, anatomical location, temporality, or etiology, encouraging the encoder to learn subtle decision boundaries within the ICD hierarchy. In contrast, soft negatives sampled from unrelated chapters prevent representation collapse and preserve global semantic separation across the embedding space. This balance is particularly important in clinical coding, where code assignment is often ambiguous and partially subjective, and where many retrieval errors arise not from lexical mismatch but from confusion between semantically neighbouring diagnoses. To improve consistency and reduce noise, all generated samples undergo a multi-stage curation pipeline including rule-based validation, semantic deduplication, language consistency checks, and manual spot inspection. The resulting dataset is substantially smaller than large-scale sentence embedding corpora used in general-domain retrieval models, which are often trained on hundreds of millions of text pairs, yet it remains sufficiently expressive for domain-specific semantic search.

Cross-encoder training

The cross-encoder is trained exclusively on Spanish CodiEsp-derived data, although the bi-encoder sees six languages. This reflects the higher cost of obtaining listwise supervision in minority languages and allows us to measure the effect of this stage-level mismatch.

Coding: CIE-10-ES and the ICD-10 hierarchy

The International Classification of Diseases, 10th revision (ICD-10) is a controlled vocabulary maintained by the World Health Organisation in which every clinical concept — diagnosis, sign, external cause, social circumstance — is mapped to an alphanumeric code drawn from a strict hierarchy. Codes are organised into 22 chapters (e.g. I. Certain infectious and parasitic diseases covering A00–B99, IX. Diseases of the circulatory system covering I00–I99). Within a chapter each code opens with a three-character category that names the disease family — for example K35 for acute appendicitis — and then resolves to a finer-grained code by appending up to four additional characters that specify laterality, severity, episode of care or anatomical site, e.g. K35.20 acute appendicitis with generalized peritonitis, without abscess. Two codes that share their first three characters therefore denote clinically related conditions, while two codes that share only their first character merely belong to the same chapter.

Evaluation datasets

We use two independent CIE-10-ES corpora. CodiESP v4 is the development set of the CLEF eHealth 2020 shared task on automatic clinical coding in Spanish. It provides 3,664 mention-to-code pairs annotated from 250 case reports (testD.tsv for diagnoses, testP.tsv for procedures and testX.tsv for the textual spans). For each row we treat the mention text as the query and the gold CIE-10-ES code as the relevance judgment. CodiESP is our primary benchmark and we evaluate every model on it.

DISTEMIST is a complementary corpus of disease mentions extracted from Spanish clinical cases, released as part of the BioASQ track and distributed on the BigBio repository. We use the subtrack 2 linking split with cross-mappings (1,224 disease mentions with a CIE-10 code). DISTEMIST is used as a secondary benchmark whose role is narrower: it tests whether the conclusions drawn on CodiESP extrapolate to another Spanish clinical corpus with a different provenance and a different distribution of disease mentions. For this reason we report DISTEMIST only for the TietAI stack and the BM25 baseline.

Mean Average Precision at K (MAP@K)

This is the metric of choice when the retriever feeds a human coder or an agentic reranker that inspects the top shortlist: clinically, the right code should appear early. The CodiESP shared task uses MAP as its primary diagnosis metric, and we follow the same convention.

Accuracy

In summary, MAP@10 captures how useful the system is as a ranker; F1 captures overall quality at the top-1 decision; recall and precision separate the two failure modes; accuracy is reported only for compatibility with earlier comparators.

Results on CodiESP v4

Three observations follow directly. First, the TietAI cross-encoder is best on every metric and at every resolution. Its MAP@10 exact = 0.747 is +0.038 above its F1 exact = 0.709, which means the gold code is frequently present in the top-10 even when it does not land at top-1; the reranker’s residual error is mostly an ordering problem, not a coverage problem. Second, the bi-encoder pattern is more pronounced: F1 exact = 0.359 vs MAP@10 exact = 0.461, a +0.102 gap. The candidate retrieval is much better than top-1 suggests; what is missing is the calibrated reranker. Third, the three off-the-shelf sentence-transformer baselines have similar (low) MAP@10 in the 0.22–0.29 band, with MiniLM-L6-v2 the strongest of the three on every metric — the larger MPNet-v2 is not.

Results on DISTEMIST

As on CodiESP, MAP is uniformly higher than F1, by a wider margin for the bi-encoder (+0.079 exact) and BM25 (+0.073 exact) than for the cross-encoder (+0.036 exact). The cross-encoder’s reranking is already exploiting most of the ranking signal in the bi-encoder pool, leaving little room for a further pass; the un-reranked stages still have ranking quality that a downstream reranker could harvest.

Discussion

The CodiESP results motivate two interpretations. First, ICD retrieval differs from general biomedical similarity because full codes encode qualifier-level distinctions. Second, the public-baseline ranking suggests that Spanish language coverage matters more than English biomedical pretraining on this benchmark.

Why clinical-domain training does not transfer to coding

Automatic ICD assignment aligns a free-text mention with a controlled vocabulary entry. It is not equivalent to retrieving a broadly similar biomedical sentence. ICD-10-CM and CIE-10-ES codes often encode disease, anatomical site, laterality, severity, episode of care, and etiology / manifestation structure in a single label.

Code “s22.49xa” illustrates this structure. The corresponding description is “multiple fractures of ribs, right side, initial encounter for closed fracture”. The model must jointly capture anatomy, laterality, multiplicity, fracture type, and episode information to distinguish this code from its siblings in “S22.4”.

Bi-encoders trained on NLI or STS-style objectives, including MiniLM-L6-v2 and BioBERT-ST, are optimized for sentence-level semantic proximity. This tends to place sibling concepts such as right-sided and left-sided rib fractures close to each other. Domain pretraining can move representations toward biomedical content, but it does not necessarily separate the qualifier axes required by coding guidelines.

The cross-encoder addresses this limitation by scoring each query-code pair jointly. Its listwise hard negatives are drawn from neighbouring CIE-10 codes, so training directly penalises loss of laterality, episode, and severity information. This interpretation is consistent with the CodiESP gap: the bi-encoder captures chapter-level topic information well, but the reranker is needed for exact-code ordering.

Why language matters more than domain on this benchmark

Cross-lingual transfer from English biomedical models is also known to weaken on Spanish, Catalan, and Portuguese clinical NLP tasks. In our setting, both queries and candidates are Spanish. The observed BioBERT-ST < MiniLM-L6-v2 ordering should therefore be read as evidence against English biomedical transfer, not against biomedical specialisation in general.

Calibrating our numbers against the CodiESP benchmark

Three direct conclusions follow. First, the TietAI cross-encoder matches or exceeds the best F1 reported in the 2020 shared task (0.709 vs 0.687) and is substantially ahead on MAP (0.747 vs 0.593). Second, the absolute level of the benchmark is, frankly, modest: the best-published F1 in 2020 sits below 0.69 on diagnosis coding, and the median best-team F1 is around 0.35. That ceiling is the operational context any downstream coding-assistant system inherits. Third, in the agentic-coding pipelines that have emerged since 2024 — where an LLM reranks a candidate shortlist — a high-MAP upstream retriever is structurally much more useful than a high-recall one. If MAP@10 is 0.75, then on three out of four mentions the first reranker iteration is examining a shortlist that already contains the correct code in a near-top position; the reranker pays for itself in roughly the number of tokens it spends on the first prompt and avoids the long-tail iterations that high-recall / low-precision retrievers force.

Conclusions

We evaluated benefits of the optimization of input data in clinical coding models, based on semantic search (bi-encoder plus a cross encoder reranker). We confirm that the proper data, in this case we use a LLM frontier model as tutor, is enough to improve specialized models trainined with large dataset: CodiESP v4 (3,664 mention-to-code pairs) and DISTEMIST (1,224 disease mentions). On CodiESP the pipeline reaches F1 = 0.709 at the exact-code level and MAP@10 = 0.747; on DISTEMIST it reaches F1 = 0.776 exact / MAP@10 = 0.812. At the three-character category level, the same metrics rise to 0.82 / 0.85 and 0.82 / 0.85 respectively.

Nevertyheless, retrieval quality concentrates in the cross-encoder reranking stage, which has direct architectural implications for production deployment. On CodiESP, the cross-encoder adds +0.350 to exact F1 over the bi-encoder on the same candidate pool; on DISTEMIST, +0.173. The bi-encoder’s MAP@10 is already in the 0.69–0.75 band at category level, which means the right candidate is almost always in the shortlist; what the cross-encoder supplies is the calibrated ordering. The clean production architecture is therefore a universal curated bi-encoder shared across all clinical workloads, plus language-specific (and optionally specialty-specific) cross-encoders applied on demand. The same shortlist could equally well be consumed by an LLM-based coding agent, in particular we believe an agenitc reranker on top of a two-step encoder would yield the optimal results.