---
title: "What is code-switching in NLP and speech recognition?"
description: "Code-switching is mixing two languages or varieties in one conversation or sentence. Why it trips up LLMs, language detection and speech-to-text, with Arabic cases."
url: https://broadrouter.com/glossary/code-switching/
lang: en
updated: 2026-11-16
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# Code-switching

Updated 2026-11-16

Code-switching is the use of two or more languages, or varieties of one language, within the same conversation or sentence, in speech or writing. Examples include Arabic speakers mixing English words into dialect, or moving between Modern Standard Arabic and their dialect.

Also called: code switching, code-mixing, code mixing, language mixing, mixed-language text

Code-switching is normal speech for bilingual people. For software that expects one language per input, it is a common source of errors.

## How it works

Solorio et al. (2014), in the first shared task on code-switched data, define it broadly as a communication act, “spoken or written, where two or more languages are being used interchangeably”. Their task labelled each word of Twitter posts with its language across four pairs: Modern Standard Arabic-Dialectal Arabic, Mandarin-English, Nepali-English and Spanish-English. Seven teams submitted 42 runs. Word-level identification was hardest for [MSA](https://broadrouter.com/glossary/msa/) versus dialect, because the two are closely related, and easiest for Spanish-English and Nepali-English.

Arabic users switch in several ways at once:

-   **Dialect and MSA.** The MADAR paper notes that in unscripted settings where MSA is expected, such as TV talk shows, speakers repeatedly switch between their dialect and MSA.
-   **Arabic and English or French.** Darwish (2014) observes that many Arabic speakers are bilingual and mix English or French with Arabic inside sentences.
-   **Scripts.** Typed messages can mix Arabic script, Latin script and [Arabizi](https://broadrouter.com/glossary/arabizi/) in one line.

A typical Gulf chat message mixes all of these:

```text
عندي meeting بكرة الساعة 3، can we move it?
("I have a meeting tomorrow at 3, can we move it?")
```

The Arabic words are dialect, “meeting” is English inside an Arabic clause, and the sentence ends in English. A language detector, a tokenizer and a speech model each have to cope with that switch.

## Why it matters

-   **Speech-to-text.** A transcription request usually takes one `language`. An English product name inside Arabic speech may come out in Arabic script, in Latin script or misheard. Agree a convention and score [word error rate](https://broadrouter.com/glossary/word-error-rate/) against it, or you will count style differences as errors.
-   **Routing and search.** A language detector that picks one label per message will mislabel mixed messages, so Arabic intents can land in the English flow.
-   **LLM prompts.** Tell the model the input may mix languages and say which language to answer in. Otherwise it may mirror whatever language came last.

## On BroadNet Inference

BroadNet’s docs say to always send `language` with transcription, `ar` for Arabic and `en` for English, and warn that without it Arabic can be transliterated into Latin letters. They do not document a mixed-language setting. For Arabic speech with English words, send `language=ar` to [BroadNet Transcribe Arabic](https://broadrouter.com/models/cohere-transcribe-arabic/) and test on real recordings; the [dialect speech recognition article](https://broadrouter.com/blog/arabic-dialect-speech-recognition/) covers building that test set. For mixed text in chat, [Qwen3.8 27B](https://broadrouter.com/models/qwen3.8-27b/) is the model BroadNet reports testing on Arabic dialects.

## Questions

### Is code-switching the same as code-mixing?

In practice both names describe more than one language in a single message or conversation, and they cause the same problems for language tools. This glossary treats them as one term.

### Which language do I send for Arabic audio with English words in it?

On BroadNet, send language=ar for audio that is mainly Arabic. Decide in advance whether English words should stay in Latin script, and check a sample of transcripts.

### Can LLMs understand code-switched text?

Usually, for common pairs such as Arabic and English, but quality varies by model and dialect. Say in the prompt that input may mix languages, name the reply language, and test with real messages from your users.

## See also

-   [Modern Standard Arabic (MSA)](https://broadrouter.com/glossary/msa/) (term)
-   [Arabizi](https://broadrouter.com/glossary/arabizi/) (term)
-   [Speech-to-text](https://broadrouter.com/glossary/speech-to-text/) (term)
-   [Word error rate](https://broadrouter.com/glossary/word-error-rate/) (term)
-   [Dialectal Arabic](https://broadrouter.com/glossary/dialectal-arabic/) (term)
-   [Arabic speech-to-text API, step by step](https://broadrouter.com/guides/arabic-speech-to-text-api/) (guide)
-   [Transcribe WhatsApp voice notes to text with an API](https://broadrouter.com/guides/transcribe-whatsapp-voice-notes/) (guide)
-   [Arabic dialect speech recognition: Gulf, Egyptian, Levantine, Maghrebi](https://broadrouter.com/blog/arabic-dialect-speech-recognition/) (article)
-   [Arabizi and LLMs: handling Franco-Arabic with numbers like 3 and 7](https://broadrouter.com/blog/arabizi-llm-handling/) (article)
-   [Multilingual speech-to-text API: 14 languages, one endpoint](https://broadrouter.com/blog/multilingual-speech-to-text-api/) (article)

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=glossary-code-switching&utm_content=page-cta) ·

**Sources**

-   [Solorio et al., Overview for the First Shared Task on Language Identification in Code-Switched Data (2014, ACL Anthology) (checked 2026-11-16)](https://aclanthology.org/W14-3907/)
-   [Bouamor et al., The MADAR Arabic Dialect Corpus and Lexicon (LREC 2018, ACL Anthology) (checked 2026-11-16)](https://aclanthology.org/L18-1535/)
-   [Darwish, Arabizi Detection and Conversion to Arabic (ANLP 2014, ACL Anthology) (checked 2026-11-16)](https://aclanthology.org/W14-3629/)
-   [BroadNet Inference API reference, transcription (language parameter) (checked 2026-11-16)](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=glossary-code-switching&utm_content=sources)
