---
abstract: 'In recent years, substantial work has been done on language tagging of code-mixed data, but most of them use large amounts of data to build their models. In this article, we present three strategies to build a word level language tagger for code-mixed data using very low resources. Each of them secured an accuracy higher than our baseline model, and the best performing system got an accuracy around 91%. Combining all, the ensemble system achieved an accuracy of around 92.6%.'
author:
- |
    Soumil Mandal, Sankalp Sanand\
    \
    Department of Computer Science & Engineering\
    SRM Institute of Science & Technology, Chennai, India\
bibliography:
- 'acl2018.bib'
title: 'Strategies for Language Identification in Code-Mixed Low Resource Languages'
---

Introduction
============

On social media, we can often see bilinguals switching back and forth between two languages, a phenomenon commonly referred to as code-switching or code-mixing [@sridhar:1980syntax]. For processing such type of textual data, we see that traditional approaches perform quite poorly, especially due to mixing of different rules of grammar, ambiguity, typing variances, as well as other types of noises contributed by informality of the social media aspect. Two types of code-mixing can be commonly seen, one where both the languages share a similar mother script, like English and Spanish. The other being where the mother scripts of both the languages being mixed are different, for example English and Hindi. In the first case, typing is done in the respective native scripts, while in the latter, one of the languages is typed in its transliterated form, so as to maintain homogeneity as well as increase ease of typing. Though there are some standard transliteration rules, for example ISO [^1], ITRANS [^2], it’s almost impossible to follow them in real life. Thus, we see variances in transliteration typing, contributed by different phonetic judgments, dialects, informality, etc. which increases the challenges of processing such data even more. Thus, for making any systems for such data, it is extremely important to develop a good language tagger as this will greatly affect the successive modules.

In this article, we present three methods for building language taggers when the amount of code-mixed data available is relatively low. These include usage of convolutional neural networks, data augmentation prior to training, and use of siamese networks. At the end, we have also built an ensemble classifier combining all these 3 methods. The language pairs we worked on are Bengali-English (Bn-En) & Hindi-English (Hi-En) code-mixed data. Both are Indic languages, having Eastern Nagari Script [^3] and Devnagari Script [^4] as their native scripts respectively. Thus, the Bn/Hi tokens are in their phonetically transliterated form in Roman.

Related Work
============

In the earlier days, two major strategies were used, n-grams [@cavnar:1994n] and dictionary look up [@rehurek:2009language]. Several research work has been done in the recent past in order to improve such taggers. @nguyen:2013word used linear chain CRFs with context information limited to bigrams. @das:2014identifying utilized multiple features like word level context, dictionary, n-gram, edit distance as features for their classifier. @jhamtani:2014word created an ensemble model. The first classifier uses edit distance, character n-grams and word frequency, while the second classifier takes output from the first one for current word, along with POS tags of the neighboring tokens. @vyas:2014pos proposed a method which uses logistic regression and code-switching probability. In the first shared task of code-mixed language identification [@solorio:2014overview], the most popular systems used char n-grams combined with rules, as well as CRFs and HMMs. @piergallini:2016word used capitalization along with character n-grams. For arbitrary set of languages, a generalized architecture based on HMM was developed by @rijhwani:2017estimating. @choudhury-EtAl:2017:W17-75 created a model which concatenates character and word embeddings for learning. They also experimented with several curriculum, or order in which the data is presented while training. @mandal:2018language trained character and phonetic embedding models and then combined them to create an ensemble model. To the best of our knowledge, no work has been done where the amount of data used for building the supervised models is low.

Data Sets
=========

We collected Bengali (Bn) words from the code-mixed data prepared in @mandal:2018preparing while Hindi (Hi) words were collected from the data released in ICON 17, tools contest [@patra:2018sentiment]. The number of unique tokens collected for both Bn and Hi each was 6000. As the goal is to train our models using low resource, we decided to set the size of our training data at 1000 unique tokens. To have convincing conclusions, as one may argue that the models depend highly on the selected low amount of words, we decided to train multiple models on batches of size 1000 and take the average of the results on our testing data.

All the experiments in the following sections were performed individually on 8 sets of data, Bn-En (4) + Hi-En (4), and then average was taken. Also, since testing the final models at instance level is more logical, we extracted random 1000 instances of Bn-En and Hn-En type each for final testing. The mean code-mixing index [@das:2014identifying] were 21.4 and 18.7 respectively.

Baseline System
===============

As a baseline, we decided to use the character embedding based architecture described in @mandal:2018language, which uses stacked LSTMs [@hochreiter:1997long] of sizes 15-35-15-1, where 15 is the size of input layer, 1 is the size of output layer, and 35, 25 are the sizes of the hidden layers. Batch size was kept at 64 and epochs were set to 100. Optimizer used was Adam [@kingma:2014adam], loss function was binary cross-entropy and activation function for output cell was sigmoid. Bn/Hi was labeled 0 and En as 1. On a whole 8 models were trained (4 for Bn-En and 4 for Hi-En) using distribution shown in Table \[table 1\], tuned using threshold on development data, and tested. Tuning is a simple method used to convert the sigmoid output into a classification, maximizing the accuracy on the development data by altering the threshold using brute force. For example, if *sigmoid\_out* $\geq$ $\theta$, output 1 (En), else 0 (Bn/Hi). The detailed results along with the average is shown in Table \[table 2\].

We can see that the average accuracy achieved for Bn-En is 80.75% while that for Hi-En is 80.3%.

Convolutional 1D Network
========================

Convolutional neural networks [@lecun:1999object] have been rapidly gaining popularity in the NLP world, especially as it gives quite satisfactory results, but yet is much faster than recurrent units. In the recent years, CNNs have shown amazing results for text classification problems (@johnson:2014effective, @johnson:2015semi). For our experiments, we used the Convolutional 1D variant of CNNs, which is ideal for text. The texts can be thought as images of length 15 (embedding size) and height 1. Thus, n-gram features can be captured using a kernel of size n.

Training
--------

For implementation we used the Keras [@chollet:2015keras] API. The architecture that we employed for training had layers 15-CNN-D(0.2)-CNN-D(0.2)-1. That is, the input layer size is 15, and the output layer size is 1. The hidden layers are CNN units in order, and had filters of size 32. Filters are essentially vectors of weights using which the input is convolved, it provides a measure for how close a patch of input resembles a feature. D(0.2) is the dropout layer, and 0.2 is the dropout rate. This reduces computation cost even further, as well as chances of overfitting. The first CNN unit had kernel size 2 and stride 1 (capturing bigrams), while the second CNN had kernel size 3 and stride 1 (capturing trigrams). Loss function used was binary crossentropy, optimizer used was nadam [@sutskever:2013importance], and activation function for output unit was sigmoid. Batch size was kept at 64 while number of epochs was set to 100 (identical to baseline). Post training, in order to convert the sigmoid outputs to classification, a similar brute force as discussed in baseline system was used.

Evaluation
----------

The results obtained using stacked CNNs are shown below in Table \[table 3\].

A modest improvement can be seen compared to the baseline (about 4%), which translates to $\approx$ 80 more correct predictions.

Data Augmentation
=================

Data augmentation has proven to be a useful strategy when data is limited but supervised models are required to be made (@ragni:2014data, @fadaee:2017data). The idea we will be employing is to increase the amount of data using probabilistic and neural models which will lead to an increase of feature points. Such augmentation has high chances of extracting new features and essential ones which can boost up the system performance. Two methods were tested for augmenting words in order to increase dataset size, one is a simple n-gram based probabilistic generator, another is a neural generator using LSTM. Both the generator models take two parameters, *seed* and *generation length*. The *seed* is the string which the generator takes as the input in order to generate following characters in order to produce the final word. The *generation length* is the length of the string the generator is asked to generate.

N-Gram Generator
----------------

For building the n-gram generator, the classic language modeling approach was taken [@ney:1994structuring], based on Markov assumption. For preparing the data for modeling, the tokens were simply split character wise and stored in an array. Then, the n-gram probabilities were estimated. This is essentially P(*c*~i+1~$\mid$*c*~i~, *c*~i-1~) = *C*(*c*~i+1~, *c*~i~, *c*~i-1~)/*C*(*c*~i~, *c*~i-1~), where *C*(.) counts the number of times the given n-gram occurs. We considered character level unigrams, bigrams and trigrams for modeling words, i.e. 3 generators (each for Bn and Hi). For example, the trigram model can be represented as P(*c*~1~, *c*~2~, ..., *c*~n~) $\approx$ P(*c*~1~)P(*c*~2~$\mid$*c*~1~)$\prod_{i=3}^{n}$P(*c*~i~$\mid$*c*~i-1~, *c*~i-2~). A random function is used to switch randomly between unigram, bigram and trigram. Our n-gram generator had one extra parameter which would control whether the *argmax* character is outputted or the *argsecondmax*, it was determined using a random function. This was done in order to increase variance in generated strings.

LSTM Generator
--------------

In order to increase variance in our augmented data, we decided to make a LSTM based generator. For data preparation, a simple character wise split was done of the existing 1000 tokens. Each word is treated as a separate time series entity. These instances were then numerically mapped with an integer, to create embeddings. Now, simply for preparing the training data, the target is set just by shifting the input sequence by *n* steps. We created 3 generators (each for Bn and Hi), by taking *n* ranging from (1, 3). These generators are essentially learning character based word modeling. Mathematically, given a training sequence (*x*~1~, *x*~2~, ..., *x*~n~), the LSTM uses a sequence of output vectors (*o*~1~, *o*~2~, ..., *o*~n~) to learn a sequence of predictive distributions P(*x*~t+1~$\mid$*x*~$\leq$t~) = *softmax*(*o*~t~). The *softmax* is expressed as P(*softmax*(*o*~t~ = *j*) = exp(o~t~^(j)^)/ $\sum_{\textit{k}}$exp(o~t~^(k)^). Objective of learning is to maximize the total log probability of the training sequence $\sum_{t=0}^{T-1}$log P(*x*~t+1~$\mid$*x*~$\leq$t~). Sampling from this conditional distribution, the next character is generated and is also fed back to the LSTM [@sutskever:2011generating]. Our models were implemented using the Keras [@chollet:2015keras] API. The layer sizes of our LSTM generator was 26-200-26. Activation function used was softmax, loss was categorical cross-entropy, and optimizer used was rmsprop with a learning rate of 0.001. All other parameters were kept at default. Batch size was kept at 32 and number of epochs was set to 50.

Augmentation
------------

Before augmentation, we needed to create a list of *seeds* using which the generators would model words and augment data. For this, we simply extracted 1000 substrings, bigram (100), trigram (300), quadgram (600) from training data having highest frequencies. The *generation length* which we decided upon ranged from (3, 16). This value was passed to the generator functions using a random function generating a value between (3, 16). Using these, 1500 tokens was generated by n-gram and LSTM generator each, i.e. a total of 3000 augmented tokens. Combining this with the 1000 training tokens, the number of tokens in the final training data was 4000 for each language.

Training
--------

The architecture and hyperparameters used for training was identical to that of the baseline system. This was done to keep parity, and make the results obtained post augmentation comparable to that of the baseline system. As neural networks are very parameter sensitive, a change in batch size, or any learning functions will force a very different learning making the results incomparable.

Evaluation
----------

The results of the models trained on augmented data is shown below in Table \[table 4\].

We can see that augmentation has improved the accuracy by a fair amount (about 8%), which translates to $\approx$ 160 more correctly predicted tokens.

Siamese Network
===============

Siamese networks [@bromley:1994signature] are neural networks whose architecture contains two identical sub-networks, which are joined at a single point, and hence the name. The sub-networks have identical configuration, parameters and weights. In such a network, back-propagation and updating is mirrored across both the networks. A unique property of such networks is that even though it takes two inputs, the order doesn’t matter (i.e symmetry). This architecture performs quite well on low resource problems or even one-shot tasks (@koch:2015siamese, @vinyals:2016matching). This is because sharing weights across sub-networks results in requirement of fewer parameters to train, which reduces chances of overfitting. They are quite good, and thus popular where finding similarity or relationship between two comparable things is a concern. In the recent past, it has become popular for finding textual similarity as well (@mueller:2016siamese, @neculoiu:2016learning, @mou:2016transferable).\
\
The siamese network is built around learning a distance metric *dis* between two vectors *x*~1~ and *x*~2~ (each coming from one sub-network), thus the order doesn’t matter, as *dis*(*x*~1~, *x*~2~) should be same as *dis*(*x*~2~, *x*~1~). This key feature is critical to our algorithm. The idea is to consider 1000 Bn/Hi tokens as belonging to one class, and 1000 En tokens belonging to another class. Distance *dis* is assigned following the equation below. $$\textit{dis}(\textit{x}\textsubscript{1}, \textit{x}\textsubscript{2}) = 
     \begin{cases}
       \text{0,} \,\, \textit{x}\textsubscript{1}, \textit{x}\textsubscript{2} \in same class \\
       \text{1,} \,\, \textit{x}\textsubscript{1}, \textit{x}\textsubscript{2} \notin same class \\
     \end{cases}$$ As a siamese network is trained pair wise, i.e. each vector is paired with every other vector once, with respective targets following the *dis* function, the total training data size increases quadratically. For *Z* members each of *C* classes, which is *Z*$\cdot$*C* vectors on a whole, the total number of possible pairs is given by $$\textit{N}\textsubscript{pairs} = \binom{\textit{Z}\cdot\textit{C}}{2} = \frac{(\textit{Z}\cdot\textit{C})!}{2!(\textit{Z}\cdot\textit{C}-2)!}$$ In our case, *Z* = 1000, *C* = 2, which results in a total of 19,99,000 vector pairs for our training data. Thus, we can see a huge increment in the size of training data, thus reducing the chances of overfitting, which is a big problem for neural networks, especially when amount of data is low like in our case.

Architecture
------------

For each of the sub-networks of our siamese network, the layer sizes were 15-128-128-64-D(0.1)-32-D(0.1)-16. Here, 15 is the size of the input layer, while 16 is the size of the output layer. 128-128-64-32 are the sizes of the hidden layers in order. The layers of sizes 128 were GRU cells [@cho:2014learning], while 64-32 were dense networks with feed forward cells. D(0.1) is a dropout layer with rate 0.1 added in between the layers 64-32 and 32-16, in order to reduce overfitting further more, which additionally reduces computing cost as well. The two tensors of sizes (1, 16) from each of the subnetworks are then concatenated, and sent to the output cell. This model was implemented using Tensorflow [@abadi:2016tensorflow].

Training
--------

The whole model was trained to minimize contrastive loss which is given by the equation below $$(1-\textit{Y})\frac{1}{2}(D\textsubscript{w})^2 + (\textit{Y})\frac{1}{2}\{\textit{max(0, m $-$ (D\textsubscript{w})}\}^2$$ Where *D*~w~ is defined as the euclidean distance between the outputs from the two sub-networks, which mathematically can be represented as the equation below. $\lambda$ denotes a very small value, which in our case was 10^-6^. $$\textit{D}\textsubscript{w} = \sqrt[]{\{\textit{G}\textsubscript{w}(\textit{X}\textsubscript{1}) - \textit{G}\textsubscript{w}(\textit{X}\textsubscript{2})\}^2 + \lambda}$$ An L2 weight decay [@van:2017l2] term was also used in the loss to encourage the network to learn less noisy weights and improve generalization. The activation function used for the output cell was sigmoid, and optimizer used was rmsprop with a learning rate of 0.0001 (other values kept at default). Batch size was kept at 128, and number of epochs was set to 10.

Tuning
------

Since our siamese model gives a sigmoid out as well, thus, to convert it into a classifier we had to find a threshold for which the accuracy is maximum. This was done using the development data. A random selection of 100 tokens was done from training data (Bn/Hi) to create our *support set*. Support set is the data with which the network compares the inputs to give a similarity score. Our algorithm essentially takes an input token, compares it with tokens in our support set, and stores the similarity scores in an array. The sum of this array is considered as the final similarity score. As our classifiers output is sigmoid, the range of the sum of this array is (0, 100). This process was done for 2x1000 tokens of our development data. Finally, using a similar brute force technique used for the other models, the $\theta$ for which the accuracy was maximum on the development was calculated (shown in Table \[table 5\]).

Evaluation
----------

For evaluation on our testing data, the algorithm that was used is described below.

similarities = \[\], similarity = 0\

Using the above algorithm, the results on our testing data is shown in Table \[table 5\].

We can see that the siamese architecture has performed quite well as expected, and have achieved accuracies above 89% for both Bn-En and Hi-En. This is an improvement of 9% from our baseline system, i.e. it has correctly predicted $\approx$ 180 tokens more. Also, unlike the other systems, here the accuracy difference between the Bn-En and Hi-En has reduced quite a bit (0.03%). This is probably due to the fact that the threshold was calculated over 100 instances, which normalizes variances to quite an extent.

Ensemble Model
==============

As we had created multiple systems for language tagging, we decided to ensemble them using simple weighted voting technique. It’s basically bootstrap aggregating [@hothorn:2003double] with different weights, based on their accuracies. Weight *w*~n~ associated with classifier *c*~n~ can be calculated as *a*~n~/$\sum_{i=0}^{n}a\textsubscript{i}$, where a~n~ is the respective accuracies on testing data. Thus, $\sum_{i=0}^{n}w\textsubscript{i} = 1$. The class having the greater weight is given as the final output. Using this method, and averaging over all the four data sets, the results obtained are shown in Table \[table 6\].

A slight improvement in accuracy can bee seen, but is still quite important as the tokens are all unique. The accuracy scores achieved, 89.95% and 89.80% are very close to that of @mandal:2018language, which reports an accuracy of 91.71% using character embedding, where $\approx$ 6.6k tokens were utilized for training (6.6x times data used for building our models). Also, recall and precision both have close values, suggesting the model is not biased towards a single language. This is unlike the individual systems, and is quite a good aspect.

Instance Level Testing
======================

To get an estimate on how our trained models will perform in real applications, we tested our trained and tuned models at instance level. This is also important as it maybe the case that the model has failed to learn very commonly used tokens for a certain language, for example articles like ’the’, ’an’, etc which will result in a much reduced accuracy when tested at instance level. The best performing classifiers from each of the methods were chosen for testing. The results obtained are shown below in Table \[table 7\].

From the table, we can see that the all the three models have performed quite well at instance level as well, proving their effectiveness. Here, the impact of the ensemble model is more visible as well, as it as achieved the highest accuracy by $>$ 1% margin.

Summary & Discussion
====================

All the three methods that have been demonstrated, have their own sets of advantages and disadvantages. Though the siamese network has got the overall best scores, the classifier is relatively slow, having a tag time of $\approx$ 1 sec per [^5] token. The Conv1D has the fastest tagging time, but is relatively inferior in terms of performance. Augmentation method performs almost as good as the siamese method, plus is faster, but creating two generators for augmentation is a slightly tedious work. One interesting thing that can be noticed from all the experiments is that for all 4x2 datasets, the results are quite close, suggesting that above a certain amount, the weights learned by the network are quite similar. Recall and precision values are also pretty close to each other, which tells us the architectures doesn’t create very biased models. Also, other than Conv1D, in the other methods (including baseline), we can see precision $>$ recall. This suggests that the models generalized the Indic character patterns quite well, which results in higher number of true positives.

Conclusion & Future Work
========================

In this article, we present experimental results from our ongoing work on building word level language taggers for code-mixed data when the amount of resources is quite low, which is actually the case many a times. We present three effective methods for this, which are Conv1D networks, data augmentation and siamese. Over all, siamese networks gave the best results with an accuracy of 91%. Conv1D and data augmentation performed quite satisfactorily as well and gave accuracies of 88% and 90% respectively. We also create an ensemble classifier combining these, which achieves an accuracy of 92.6%. In future, we would like to explore more methods, especially using memory augmented neural networks [@santoro:2016one]. Using transfer learning (@pratt:1993discriminability, @do:2006transfer) may prove to be an effective solution as well.

[^1]: https://en.wikipedia.org/wiki/ISO\_9

[^2]: https://en.wikipedia.org/wiki/ITRANS

[^3]: https://en.wikipedia.org/wiki/Eastern\_Nagari\_script

[^4]: https://en.wikipedia.org/wiki/Devanagari

[^5]: i5-6300HQ (2.8 GHz) + 16GB RAM
