Code-Switching and Mixed-Language Text › Generating Code-Switched Output

Michael BrenndoerferNovember 26, 20263 min read
Language AI HandbookAll chapters
Part 26 of 67Multilingual Language Models and Cross-Lingual Transfer
Chapter 188Code-Switching and Mixed-Language Text › Generating Code-Switched Output
Reading section 8 of 13 · Generating Code-Switched Output · 3 minSection 8 of 13 · 3 min

Section 8 of 13 · 3 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

A bilingual support assistant may need to reply in the mix and register a user requests. Decide which combinations, scripts, and styles the task supports, then evaluate sample replies with readers from the intended setting.

An autoregressive model predicts each next token from the prompt and preceding output available within its context window. Test whether changing the prompt, recent user turn, or example replies changes the target language proportions.

What the prompt has to specify

A prompt for code-switched output should specify at least four things.

  • The language pair. "Hinglish" is not enough; specify the Hindi, English, romanized-or-Devanagari script, and the register.
  • The switching pattern. Say whether switches may occur between sentences, within sentences, or both.
  • The length. Compare like-length answers when you measure switch placement or language proportions.
  • An anchor. Include example turns that demonstrate the target mix and register. Test their effect against a prompt without those examples.

A prompt that names all four looks like this:

Code
CollapseExpand
You are a bilingual assistant for users in urban North India.
Reply in Hinglish: Hindi syntax and function words written in Latin
script, mixed with English content words. Switch within sentences,
not only between them, and roughly 40 percent of the words should be
English. Do not reply in pure English or pure Hindi, even if the user
does. Keep replies to two or three sentences.

Example turn:
  User: bhai laptop ki battery kharab ho gayi, kya karun
  Assistant: Pehle charger aur cable check karo, yaar. Agar woh theek
  hai to battery calibration try karo, aur agar phir bhi issue hai
  to service center hi jana padega.

User: mujhe ek naya phone lena hai, budget 20k

The example turn illustrates script, register, and switch placement. Use the separately labeled response exercise to measure how close an answer comes to the rough 40% English target. Compare prompts with and without the example on matched inputs.

Drift

Include four checks in the generation evaluation:

Language collapse. Compare the language distribution for the whole reply with its trailing window. The hand-written fixture below contains one reply that starts mixed and ends in English.

Turn-dependent collapse. Vary the last user turn while holding earlier turns fixed. Check whether the reply still follows the requested conversation-wide language policy.

Register mismatch. Ask target readers whether formal Devanagari Hindi mixed with English suits a request written in casual romanized Hindi. Review the register even when language and script labels match their targets.

Script and spelling inconsistency. Check changes in script separately from spelling variation such as mujhe and mujhey. Test whether your lexical matcher handles the variants the application accepts.

Use separate checks for label proportions, switch placement, spelling, and register. Report the checks and their known limits. CMI measures language-label balance and cannot by itself establish naturalness or the position of a shift.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy