Skip to content

feat(studio): add Hmong language support and detection in Translate (#18674) - #18737

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
Fahad090NP:fix/18674-translate-hmong-support
Nov 23, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
Fahad090NP:fix/18674-translate-hmong-support

Conversation

@Fahad090NP

@Fahad090NP Fahad090NP commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Related to #18674

Summary

Adds Hmong (hmn) to the Unsloth Translate language catalog and Latin-script language detector (detectTranslateLanguage), so Hmong source text is accurately recognized by Detect language (instead of falling back to null or misclassifying as Polish/Spanish) and can be selected as a source or target language.

Changes

  • studio/frontend/src/features/translate/languages.ts
    • Add { code: "hmn", name: "Hmong" } to TRANSLATE_LANGUAGES.
  • studio/frontend/src/features/translate/detect-language.ts
    • Add Romanized Popular Alphabet (RPA) Hmong function words and particles (kuv, koj, nws, peb, nej, lawv, yog, muaj, tsis, tau, yuav, xav, nyob, mus, ua, hais, pom, paub, kawm, thiab, rau, hauv, txog, lub, tus, cov, tias, vim, zoo, tsaug, ntau, lus, hmoob, etc.) to LATIN.hmn.
  • studio/frontend/tests/translate-detect-language.test.ts
    • Add Hmong test sentence and greeting phrase to SENTENCES.hmn.

Before and After

Before

Before (#18674)

After

After (#18674)

Verification

  • node --experimental-strip-types --test tests/translate-*.test.ts (studio/frontend): 54/54 passed
  • npm run typecheck (studio/frontend): passed (0 errors)

Maintainer follow-ups

Hy-MT2, the default Translate model, is trained on the 38 languages on its model card, and Hmong is not one of them. So languages outside that list are now marked chatOnly:

  • With Hy-MT2 selected, the language picker, the recent tabs and Detect language behave exactly as before; Hmong is not offered and is never reported as detected.
  • With a chat model (any custom GGUF such as Gemma 4), Hmong is offered as a source and target, and Detect language recognises it.
  • Switching to Hy-MT2 while Hmong is picked falls back to the last Hy-MT2 target (or the automatic source); the recent tab is kept for the next chat model.
  • The first-run target taken from the browser locale only ever picks a Hy-MT2 language.
  • Reopening a Hmong history entry while Hy-MT2 is selected keeps the entry labelled Hmong (it shows as stale) and does not retranslate it on its own.

Tests: node --experimental-strip-types --test tests/translate-*.test.ts 56/56, npm run typecheck clean.

…ained on it

Languages outside Hy-MT2's model card are marked chatOnly: the picker, the
recent tabs and Detect language hide them while Hy-MT2 translates, a
chat-only pick falls back to the last Hy-MT2 target when switching to it,
and the browser-locale default target never picks one. Adds more common
Hmong function words for detection.

[skip ci]
danielhanchen added a commit to Fahad090NP/unsloth that referenced this pull request Nov 22, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T16:04:29.426304Z b7a9eff Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 82fe77b230

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


setPrefs: (patch) => {
const prefs = { ...get().prefs, ...patch };
const prefs = fitLanguages({ ...get().prefs, ...patch });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the language metadata of restored translations

After translating English→Hmong with a chat model, selecting Hy-MT2 and reopening that history entry makes restore() call setTarget("hmn"), which now silently falls back to another language, such as en. restore() then builds result and attempt from those coerced preferences while keeping the original Hmong output, so translationIsStale() returns false; read-aloud and outputToSource() consequently treat Hmong text as English. Preserve the history entry's actual language metadata and mark it stale or select a compatible model, rather than recording the fallback target as the language of the saved translation.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 3109555: restore keeps the entry's own from/target on the shown result, so a Hmong entry reopened under Hy-MT2 reads as stale and read aloud / use as source still treat it as Hmong (store test covers it).

Restoring a Hmong translation while Hy-MT2 is selected falls the target back
to a Hy-MT2 language; the shown result now keeps the entry's languages, so
it reads as stale and read aloud / use as source still treat it as Hmong.
danielhanchen added a commit to Fahad090NP/unsloth that referenced this pull request Nov 22, 2026
# Conflicts:
#	studio/frontend/src/features/translate/languages.ts
#	studio/frontend/tests/translate-detect-language.test.ts
#	studio/frontend/tests/translate-page.test.ts
#	studio/frontend/tests/translate-store.test.ts
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3109555498

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +531 to +533
...resultOf(entry.source, get().prefs),
from,
...(target ? { target } : {}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Suppress auto-translation when restoring incompatible history

If autoTranslate is enabled and Hy-MT2 has already served a translation, restoring an English→Hmong entry while its fallback target is French makes shown.target (and therefore attempt.target) "hmn" while prefs.target is "fr". The auto-translation effect in translate-page.tsx (lines 1279–1299) sees that mismatch and schedules a new translation after 800 ms, so merely opening history clears the saved Hmong output from the pane and replaces it with French. Preserve the saved metadata on result, but suppress the automatic run for restores or keep the current-preferences scheduling snapshot separate from the displayed result.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in b7a9eff: only result keeps the entry's languages; attempt matches the settings, so the as-you-type effect sees nothing to rerun and the saved output stays (store test asserts attempt.target == prefs.target after restore).

Only the shown result keeps the entry's languages; the attempt snapshot
matches the settings, so translating as you type leaves the saved output.
danielhanchen added a commit to Fahad090NP/unsloth that referenced this pull request Nov 22, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: b7a9efffce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit that referenced this pull request Nov 22, 2026
… since #18924 (#18942)

## Summary

`Backend tests` (the `(Python 3.13, rest)` shard) is red on `main` since
#18924:

```
tests/test_xformers_stub_diffusion_parity.py:407: in test_xformers_is_never_selected_on_a_rocm_target
E   AssertionError: assert None == 'aiter'
```

Both ROCm wheel parametrizations fail. It shows on unrelated PRs, for
example the staging run for #18737, which only touches translate files.

#18924 made an explicit `aiter` pick on ROCm run the auto pick when
diffusers has no usable local aiter backend
(`_diffusers_aiter_usable()`), so the pick no longer fails mid-render.
That change is correct. #18924 patched `_diffusers_aiter_usable` in its
own tests, but this older parity test still asserted that `aiter` is
always honoured on a ROCm target. On a runner whose diffusers has no
local aiter backend, which is every CI runner, that is no longer true.

## Fix

The test now pins both outcomes explicitly instead of depending on the
runner's diffusers:

- With `_diffusers_aiter_usable` returning True, an `aiter` pick on ROCm
is still `aiter`.
- With it returning False, an `aiter` pick resolves to the same backend
as `auto`.

The xformers assertions the test exists for are unchanged. Only the test
changes.

## Testing

- `tests/test_xformers_stub_diffusion_parity.py`: 2 failed on `main`,
all pass with this change.
- The file plus `tests/test_diffusion_attention.py` and
`tests/test_diffusion_attention_aiter_alias.py`: 193 passed.
- Sabotage: with #18924's fallback (`if alias == "aiter" and
_is_cuda_rocm(target) and not _diffusers_aiter_usable(): alias =
ATTN_AUTO`) removed, the new no-aiter assertion fails for both ROCm
wheels, alongside #18924's own
`test_dead_aiter_on_rocm_is_the_auto_pick` cases.
@danielhanchen
danielhanchen merged commit 5c8475c into unslothai:main Nov 23, 2026
danielhanchen added a commit to Fahad090NP/unsloth that referenced this pull request Nov 23, 2026
# Conflicts:
#	studio/frontend/src/features/translate/detect-language.ts
#	studio/frontend/src/features/translate/languages.ts
#	studio/frontend/tests/translate-detect-language.test.ts
#	studio/frontend/tests/translate-page.test.ts
meefs pushed a commit to meefs/unsloth that referenced this pull request Nov 23, 2026
…nslothai#18723) (unslothai#18738)

Related to unslothai#18723

### Summary
Adds official support and automatic script/language detection in Unsloth
Translate for **Amharic (`am`)** along with popular African continent
languages (**Swahili `sw`**, **Hausa `ha`**, **Yoruba `yo`**, **Igbo
`ig`**, **Zulu `zu`**, **Afrikaans `af`**, and **Somali `so`**).

### Changes
- **`studio/frontend/src/features/translate/languages.ts`**
- Add `am` (Amharic), `sw` (Swahili), `ha` (Hausa), `yo` (Yoruba), `ig`
(Igbo), `zu` (Zulu), `af` (Afrikaans), and `so` (Somali) to
`TRANSLATE_LANGUAGES`.
- **`studio/frontend/src/features/translate/detect-language.ts`**
- Add `[/\p{Script=Ethiopic}/gu, "am"]` to `SINGLE_SCRIPT` so
Ethiopic/Ge'ez script text is recognized as Amharic.
- Add `sw`, `ha` (`"ɓɗƙ"`), `yo` (`"ẹọṣ"`), `ig` (`"ịụṅ"`), `zu`, `af`,
and `so` entries to `LATIN`.
- Exclude the four plain dot-below vowels (`ẹ`, `ị`, `ọ`, `ụ`) used by
Yoruba and Igbo from the Vietnamese `/[ơưđăạ-ỹ]/gu` shortcut
(`/(?![ẹịọụ])[ơưđăạ-ỹ]/gu`) so Yoruba and Igbo are not misclassified as
Vietnamese.
- **`studio/frontend/tests/translate-detect-language.test.ts`**
- Add sentences and short phrases for `am`, `sw`, `ha`, `yo`, `ig`,
`zu`, `af`, and `so` to `SENTENCES`, verifying all supported Translate
languages are recognized without collisions.

### Before and After

#### Before
![Before
(unslothai#18723)](https://raw.githubusercontent.com/Fahad090NP/unsloth/pr-assets/before-18723-amharic.png)

#### After
![After
(unslothai#18723)](https://raw.githubusercontent.com/Fahad090NP/unsloth/pr-assets/after-18723-amharic.png)

### Verification
- `node --experimental-strip-types --test tests/translate-*.test.ts`
(`studio/frontend`): 54/54 passed
- `npm run typecheck` (`studio/frontend`): passed (0 errors)



### Maintainer follow-ups

This branch builds on unslothai#18737 (merged in), which marks languages outside
Hy-MT2's model card as `chatOnly`: they are offered and detected only
when a chat model translates, and with Hy-MT2 (the default) the page
behaves exactly as before. Merge unslothai#18737 first.

Detection: the original word lists were built from the test sentences,
so everyday text in most of these languages was not detected. Measured
on held-out sentences from the Universal Declaration of Human Rights
translations (sentence level):

| Language | main | this PR as submitted | now |
|---|---|---|---|
| Amharic | 0/62 | 62/62 | 62/62 |
| Swahili | 0/83 | 25/83 | 78/83 |
| Hausa | 0/82 | 13/82 | 80/82 |
| Yoruba | 0/86 (85 read as Vietnamese) | 84/86 | 84/86 |
| Igbo | 0/72 (71 read as Vietnamese) | 50/72 | 72/72 |
| Zulu | 0/69 | 4/69 | 61/69 |
| Afrikaans | 0/73 (66 read as Dutch) | 0/73 (66 read as Dutch) | 62/73
|
| Somali | 0/78 | 17/78 | 74/78 |

- The lists now hold each language's common function words; Zulu,
Swahili and Somali also score typical word shapes (noun class and verb
prefixes, long vowels with x / q / dh).
- A new language only scores when the text has evidence no Hy-MT2
language's list holds (one of its own words, letters or word shapes), so
it can never take a verdict away from English, Dutch, French,
Portuguese, Tagalog and the rest. Afrikaans shares only the words
already on the Dutch list and wins on its own words.
- Short Vietnamese phrases ("Mẹ ơi", "Dịch vụ", "Chị bị ho hôm qua") are
Vietnamese again, while Yoruba and Igbo text is no longer read as
Vietnamese.
- No verdict moved for any of the 38 existing languages across 42,597
UDHR sentences in 537 translations, nor across 2,945 English sentences
from the repo docs.

Before / after, translating with a chat model (picker gains the new
languages; Afrikaans was read as Dutch):

![chat
model](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/18738/q_pr18738_pair_01-dfb511b676d4.png)

Before / after with Hy-MT2 1.8B, the default (same 38 languages;
Afrikaans is no longer misread as Dutch):


![Hy-MT2](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/18738/q_pr18738_pair_00-6dad1ed43532.png)

Tests: `node --experimental-strip-types --test
tests/translate-*.test.ts` 59/59, `npm run typecheck` clean.

---------

Co-authored-by: Daniel Han <[email protected]>
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.

2 participants