Downloads · 30 days
21
26% of all-time downloads
Amna-Shahzad/code-switching-codesaviours-si26-Amna
code-switching-codesaviours-si26-Amna is a token classification model from Amna-Shahzad. Use it when you need labels on individual words, such as names. It is set up for transformers. The card lists the license as apache-2.0.
text Input Sentence │ ▼ XLM-RoBERTa Tokenizer │ ▼ XLM-RoBERTa Encoder │ ▼ Token Classification Head │ ▼ URD / ENG / MIX text Aaj mujhe ghar jana hai ↓ URD text Aaj weather amazing hai ↓ weather → ENG amazing → ENG tex…
Downloads · 30 days
21
26% of all-time downloads
All-time downloads
80
Public
Parameters
277M
2.2 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors1.1 GB · 98%
From the Hugging Face model README
README.md---
language:
- en
- ur
tags:
- token-classification
- code-switching
- roman-urdu
- urdu
- english
- multilingual
- xlm-roberta
- text-classification
- code-mixing
license: apache-2.0
base_model: FacebookAI/xlm-roberta-base
pipeline_tag: token-classification
---
# Urdu-English Code-Switching Detection
A fine-tuned **XLM-RoBERTa** model for identifying whether individual words in code-switched text are **Urdu, English, or Mixed**.
This model was developed as part of the **CodeSaviours SI-26** project by **Amna Shahzad** at **Code Saviours (SMC-PRIVATE) Limited**.
---
## Overview
Code-switching is the practice of using words or expressions from multiple languages within the same sentence or conversation.
In social media and informal communication, Urdu and English are frequently mixed together. This is especially common in:
- YouTube comments
- WhatsApp messages
- Twitter/X posts
- Instagram content
For example:
> `Aaj weather bohat amazing hai`
A human reader can easily understand the sentence, but automatically determining the language of each word can be challenging.
This model addresses this problem by classifying individual words into three categories:
| Label | Meaning |
|------|---------|
| `URD` | Urdu |
| `ENG` | English |
| `MIX` | Mixed Urdu-English / code-switched word |
---
# Project Objective
The primary objective of this project is to develop a language identification model capable of detecting the language category of individual words in **Urdu-English code-switched text**.
The model can be used as a component in larger NLP systems for:
- Code-switching analysis
- Urdu-English language identification
- Social media text analysis
- Multilingual NLP
- Roman Urdu processing
- Language-aware text preprocessing
- Code-mixed sentiment analysis
- Urdu-English text normalization
---
# Model
The model is based on:
**XLM-RoBERTa Base**
XLM-RoBERTa is a multilingual Transformer model designed to process text across multiple languages.
For this project, the pretrained model was fine-tuned using a **token-classification architecture**.
### Architecture
```text
Input Sentence
│
▼
XLM-RoBERTa Tokenizer
│
▼
XLM-RoBERTa Encoder
│
▼
Token Classification Head
│
▼
URD / ENG / MIX
The model performs classification at the token/word level rather than assigning a single label to the complete sentence.
The model uses three labels:
URDRepresents words identified as Urdu.
Example:
Aaj mujhe ghar jana hai
↓
URD
ENGRepresents English words.
Example:
Aaj weather amazing hai
↓
weather → ENG
amazing → ENG
MIXRepresents words that contain or combine Urdu and English characteristics.
Example:
downloadkarna
may be classified as:
MIX
Note: The exact behavior of
MIXdepends on the annotation guidelines used during dataset creation.
The model was trained on a manually collected dataset of 175 sentences.
| Split | Number of Sentences |
|---|---|
| Training | 140 |
| Testing | 35 |
| Total | 175 |
The dataset consists of Urdu-English code-switched sentences collected from multiple real-world communication platforms.
The collected examples were sourced from:
The purpose of using multiple sources was to capture different styles of informal Urdu-English communication.
An example of code-switched text:
Aaj meeting bohat important hai
Possible token-level classification:
Aaj → URD
meeting → ENG
bohat → URD
important → ENG
hai → URD
Another example:
Mujhe ye file downloadkarni hai
Possible classification:
Mujhe → URD
ye → URD
file → ENG
downloadkarni → MIX
hai → URD
The pretrained xlm-roberta-base model was fine-tuned for token classification.
| Parameter | Value |
|---|---|
| Base Model | xlm-roberta-base |
| Task | Token Classification |
| Number of Labels | 3 |
| Training Samples | 140 |
| Testing Samples | 35 |
| Epochs | 5 |
| Training Batch Size | 16 |
| Evaluation Batch Size | 8 |
| Learning Rate | 5e-5 |
| Optimizer | AdamW |
| LR Scheduler | Linear |
| Weight Decay | 0.0 |
| Warmup Steps | 0 |
| Gradient Accumulation | 1 |
| Random Seed | 42 |
| Evaluation Strategy | Epoch |
| Save Strategy | Epoch |
| Best Model Selection | Validation Loss |
The model achieved an overall token-level accuracy of:
This result was obtained on the held-out test set containing 35 sentences.
| Metric | Result |
|---|---|
| Overall Accuracy | 99.70% |
| Training Samples | 140 |
| Testing Samples | 35 |
An overall accuracy of 99.70% means that approximately 99.7% of the evaluated tokens were assigned the correct language label according to the test annotations.
Because the dataset is relatively small, this result should be interpreted cautiously. Evaluation on a larger and more diverse dataset would provide a stronger estimate of real-world generalization.
This model is intended for research and educational purposes involving:
It can also be used as a preprocessing component for downstream applications such as:
Code-Switched Text
│
▼
Language Identification
│
┌────┼────┐
▼ ▼ ▼
URD ENG MIX
│
▼
Downstream NLP Task
Install the required libraries:
pip install transformers torch
Then load the model:
from transformers import (
AutoTokenizer,
AutoModelForTokenClassification,
pipeline
)
model_name = "Amna-Shahzad/code-switching-codesaviours-si26-Amna"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForTokenClassification.from_pretrained(
model_name
)
classifier = pipeline(
"token-classification",
model=model,
tokenizer=tokenizer,
aggregation_strategy="simple"
)
Run the model on a sentence:
text = "Aaj meeting bohat important hai"
results = classifier(text)
for result in results:
print(
result["word"],
"->",
result["entity_group"]
)
Example output:
Aaj -> URD
meeting -> ENG
bohat -> URD
important -> ENG
hai -> URD
The exact output may vary depending on tokenization and model predictions.
The overall development process consisted of the following stages:
Code-switched Urdu-English sentences were collected from real-world sources including social media and messaging platforms.
The collected sentences were organized and annotated according to the three target categories:
URD
ENG
MIX
The dataset was divided into:
140 Training Sentences
+
35 Testing Sentences
The text was tokenized using the XLM-RoBERTa tokenizer.
Labels were aligned with the corresponding subword tokens generated by the tokenizer.
xlm-roberta-base was fine-tuned using the prepared training dataset.
The trained model was evaluated on the held-out test set.
The model achieved:
99.70% overall token-level accuracy.
Although the model achieved high accuracy on the current test set, there are several limitations to consider.
The dataset contains only 175 sentences, which is relatively small for training and evaluating a robust multilingual NLP system.
Only 35 sentences were used for testing. Therefore, the reported 99.70% accuracy may not fully represent performance on unseen real-world data.
The data was collected primarily from informal communication platforms. Performance may differ on:
Roman Urdu does not have a single standardized spelling system. The same Urdu word may be written in several different ways.
For example:
bohat
boht
bahut
bohut
Such variations can make language identification more difficult.
Words combining Urdu and English can be ambiguous and may require contextual understanding.
Several improvements can be explored in future versions:
Increase the dataset from hundreds of sentences to thousands or more.
Include additional sources such as:
Develop more detailed annotation guidelines for ambiguous and mixed words.
Compare XLM-RoBERTa with other multilingual and language-specific Transformer models.
Evaluate the model using:
Generate additional realistic variations of Roman Urdu and code-switched sentences.
Evaluate the model on completely unseen domains and larger external datasets.
Model:
Amna-Shahzad/code-switching-codesaviours-si26-Amna
Base Model:
xlm-roberta-base
Task: Token Classification
Labels:
URD
ENG
MIX
Training Dataset: 140 sentences
Testing Dataset: 35 sentences
Overall Accuracy: 99.70%
Amna Shahzad
CodeSaviours SI-26
Code Saviours (SMC-PRIVATE) Limited
This model is intended for research and educational use.
Please review the licensing terms of the underlying xlm-roberta-base model and any datasets used before using this model in a commercial application.
This project builds upon the work of the XLM-RoBERTa authors and the open-source Hugging Face Transformers ecosystem.
Special thanks to the developers and researchers who make multilingual NLP models and tools publicly available.