Search that still works when nobody types tone marks

    Restore the marks your documents lost, then match on an accent-folded key, so a user typing "oko" finds "ọkọ" and still sees it written properly.

    Media & publishingMarketplacesArchivesGovernment portals
    0.0130
    MEAN DER, DIACTAG-2.0
    ~8 ms
    PER SENTENCE, INT8 ON A LAPTOP CPU
    0
    MODELS ON THE QUERY PATH
    / The problem

    Why this breaks today

    A user searches "oko" and gets nothing, because the article says "ọkọ". A marketplace listing typed with tone marks never surfaces for the buyer who typed without them. Neither side did anything wrong: the index and the query are in different orthographies.

    Accent-folding both sides fixes the matching in one line of Unicode, and plenty of teams stop there. But a corpus that was scraped, OCR’d, or user-typed without marks is still broken everywhere it is displayed, and folding just hides that.

    So do both, and keep them separate: restore the marks so the text reads correctly, and fold a copy so it matches however anyone types.

    / How it works

    The pipeline, step by step

    01

    Label a mixed corpus by language

    lid-lite-608 labels documents at about 6,800 texts per second on one CPU thread, so a whole archive can be bucketed before anything else runs. Where you already know a source’s language, set it per source instead.

    lid-lite-608
    02

    Restore only the documents that need it

    Run diactag-2.0 over text missing its marks: scraped pages, OCR output, user submissions. It copies the base letters and only predicts marks, so a stray pass can at worst re-decide an accent; it cannot rewrite the sentence. Marks an editor already typed are kept by default.

    diactag-2.0
    03

    Index an accent-folded copy as the match key

    Fold the restored text down to unmarked characters and store that as the search field, keeping the restored text for display. This is pure Unicode (NFD, drop the combining marks), so no model sits on your indexing path beyond the restore.

    04

    Fold the query the same way

    One function, both sides. A query typed with marks and one typed without collapse to the same key, and no model runs on the query path at all, so search latency is untouched.

    / The code

    Running in about ten lines

    The Olaverse SDK wraps the models with sane defaults. If you would rather not add a dependency, the second tab is the same pipeline in plain transformers.

    $pip install "olaverse[deeplearning,onnx]"
    normalise.py
    import unicodedata
    from olaverse.nlp import Diacritizer
    
    # Your corpus language is something you usually know; omit lang= to let the model detect it
    d = Diacritizer(model="diactag-2.0", lang="yor", onnx=True)
    
    def fold(s: str) -> str:
        """Accent-fold to a match key. Pure Unicode, no model."""
        return "".join(c for c in unicodedata.normalize("NFD", s)
                       if unicodedata.category(c) != "Mn").lower()
    
    def index_document(doc):
        # Restore only what's missing its marks
        text = doc["text"] if doc["has_diacritics"] else d.restore(doc["text"])
        return {**doc, "display_text": text, "match_text": fold(text)}
    
    corpus = [
        {"id": 1, "text": "Ṣé ẹranko náà sì gbọ́ ọ?", "has_diacritics": True},    # clean CMS copy
        {"id": 2, "text": "se eranko naa si gbo o?",  "has_diacritics": False},   # scraped / OCR
    ]
    indexed = [index_document(c) for c in corpus]
    # both share one match_text, and doc 2 now displays as 'ṣé ẹranko náà sì gbọ́ ọ?'
    
    # The query path is folding only: no model, no added latency
    key = fold("SE ERANKO NAA")
    [c["id"] for c in indexed if key in c["match_text"]]     # → [1, 2]

    Language coverage

    / 11 LANGUAGES RESTORED

    Every language the models in this pipeline were trained on, with the codes you pass and the codes you get back.

    Yorùbá
    yo · yor
    Igbo
    ig · ibo
    Hausa
    ha · hau
    Vietnamese
    vi · vie
    Polish
    pl · pol
    Turkish
    tr · tur
    Portuguese
    pt · por
    Spanish
    es · spa
    French
    fr · fra
    Italian
    it · ita
    Arabic
    ar · ara

    Restoration covers these eleven. Anything else still benefits from the folding half of the pipeline: it is indexed as typed, with no restoration pass.

    / This is you if
    • You run search over Yorùbá, Igbo, Hausa, Vietnamese, Arabic, or another diacritic-heavy language.
    • Your analytics show a rate of zero-result queries you cannot explain.
    • Your content is correctly written but your users type on a phone keyboard.

    Every figure on this page comes from the published model cards. Download the weights and check us.

    Want this on your data?

    The weights are open, so you can build it yourself this afternoon. If you would rather we tuned it to your domain, evaluated it properly, and handed it over, tell us what you are working on.