Skip to content

Support GlotLID language and script identification - #2281

Open
ccyyy1023 wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
ccyyy1023:fix/glotlid-language-script
Open

Support GlotLID language and script identification#2281
ccyyy1023 wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
ccyyy1023:fix/glotlid-language-script

Conversation

@ccyyy1023

@ccyyy1023 ccyyy1023 commented Jul 30, 2026

Copy link
Copy Markdown

Summary

  • preserve complete FastText labels after removing the __label__ prefix, including GlotLID language-script labels such as eng_Latn
  • support case-insensitive filtering by either language (eng) or exact language-script pair (eng_Latn)
  • document GlotLID usage and add focused regression tests

Why

FastTextLangId previously extracted only the final two characters of a model label. For a GlotLID prediction such as __label__eng_Latn, this produced TN and discarded both the language and script information.

The updated parsing preserves the model label and lets users choose between language-level and language-script-level filtering while retaining the existing confidence cutoff behavior.

Validation

  • pytest -q tests/stages/text/filters/fasttext/test_fasttext_filters.py — 10 passed
  • pytest -q tests/stages/text/modules/test_filters.py tests/stages/text/filters/fasttext/test_fasttext_filters.py — 85 passed, 1 skipped
  • pytest -m 'not gpu' -q tests/stages/text — 780 passed, 5 skipped, 53 deselected, 1 xfailed
  • ruff check and ruff format --check on the changed Python files

Fixes #2276

Signed-off-by: ccyyy1023 <2637034749@qq.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ccyyy1023
ccyyy1023 marked this pull request as ready for review July 30, 2026 02:16
@ccyyy1023
ccyyy1023 requested a review from a team as a code owner July 30, 2026 02:16
@ccyyy1023
ccyyy1023 requested review from praateekmahajan and removed request for a team July 30, 2026 02:16
label, score = model.predict([pp], k=1)
score = score[0][0].item()
lang_code = label[0][0][-2:].upper()
lang_code = label[0][0].removeprefix("__label__")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Standard labels change casing

When a pipeline using lid.176 persists the language score, preserving the raw model label now stores en instead of the previously documented EN, causing existing downstream comparisons against uppercase language codes to stop matching.

Knowledge Base Used: Text Curation Stage Library

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is fine and being documented.

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds GlotLID language-script support while retaining standard FastText compatibility.

  • Preserves complete model labels after removing the __label__ prefix.
  • Adds case-insensitive language-only and exact language-script filtering.
  • Documents GlotLID usage and adds focused parsing, filtering, and pipeline regression tests.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously discussed casing change is explicitly documented as intended behavior.

Important Files Changed

Filename Overview
nemo_curator/stages/text/filters/fasttext/fasttext_filters.py Preserves complete FastText labels and supports case-insensitive language or language-script matching without an eligible follow-up defect.
tests/stages/text/filters/fasttext/test_fasttext_filters.py Adds focused coverage for complete-label parsing, matching semantics, confidence cutoffs, and filter-stage integration.
fern/versions/main/pages/curate-text/process-data/language-management/language.mdx Documents preserved model-label casing, GlotLID setup, and language-versus-script filtering behavior.

Reviews (4): Last reviewed commit: "Merge branch 'main' into fix/glotlid-lan..." | Re-trigger Greptile

Signed-off-by: ccyyy1023 <2637034749@qq.com>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Aug 1, 2026
raise ValueError(msg)
self._model_path = model_path
self._lang_code = lang.upper() if lang else None
self._lang_code = lang.casefold() if lang else None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._lang_code = lang.casefold() if lang else None
self._lang_code = lang if lang else None

how about we change the behavior slightly. When we are doing the comparison we can use casefold but the lang_code that is returned in the dataframe does not need the casefold.

lang_code = label[0][0][-2:].upper()
lang_code = label[0][0].removeprefix("__label__")
if "_" not in lang_code:
lang_code = lang_code.upper()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment as above, instead of using the underscore to decide about case sensitivity we can just not do it at all. And just use casefold for the comparison. Make sense?

Comment thread tests/stages/text/filters/fasttext/__init__.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have mocked fasttext tests in https://github.com/NVIDIA-NeMo/Curator/blob/main/tests/stages/text/modules/test_filters.py . I think it makes sense to move them to this new file, can you do that?

Comment thread tests/stages/text/filters/__init__.py
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Aug 3, 2026
Signed-off-by: ccyyy1023 <2637034749@qq.com>
@ccyyy1023

Copy link
Copy Markdown
Author

Hi @sarahyurick, I’ve addressed all of your review comments in fa849db:

  • preserved the model label’s original casing and use casefold() only for comparisons
  • removed the copyright headers from the empty __init__.py files
  • moved the mocked FastText tests into the dedicated FastText test module
  • updated the related documentation

The targeted tests pass (87 passed, 1 skipped), and I also ran the full non-GPU text test suite, with the environment-related cases rerun successfully.

Could you please take another look when you have a chance?

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Aug 4, 2026
@sarahyurick

Copy link
Copy Markdown
Contributor

/ok to test 90c2ed8

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support GlotLID for language/script identification.

3 participants