{'fraction_non_alphanumeric': 0.030200923499313616, 'fraction_numerical': 0.011637339323599151, 'mean_word_length': 4.828877977814148, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 1, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Neural Task Representations as Weak Supervision for Model Agnostic Cross-Lingual Transfer

Natural language processing is heavily Anglo-centric, while the demand for models that work in languages other than English is greater than ever. Yet, the task of transferring a model from one language to another can be expensive in terms of annotation costs, engineering time and effort. In this paper, we present a general framework for easily and effectively transferring neural models from English to other languages. The framework, which relies on task representations as a form of weak supervision, is model and task agnostic, meaning that many existing neural architectures can be ported to other languages with minimal effort. The only requirement is unlabeled parallel data, and a loss defined over task representations. We evaluate our framework by transferring an English sentiment classifier to three different languages. On a battery of tests, we show that our models outperform a number of strong baselines and rival state-of-the-art results, which rely on more complex approaches and significantly more resources and data. Additionally, we find that the framework proposed in this paper is able to capture semantically rich and meaningful representations across languages, despite the lack of direct supervision.


Introduction
Recent advances in Natural Language Processing (NLP) and Deep Learning have enabled systems to achieve human parity in several key research areas such as Speech Recognition (Xiong et al. 2016), Machine Translation (Hassan et al. 2018) and Machine Comprehension (Hu, Peng, and Qiu 2017), while advancing the state-of-the-art for many other tasks. Nevertheless, much of this research revolves around models, methods and datasets that are Anglo-centric. It is estimated 1 that only about 350 million people are native English speakers, while another 500 million to 1 billion speak it as a second language. This accounts for at most 20% of the world's population. With language technologies making inroads into the digital lives of people, it is becoming increasingly imperative to build NLP applications that can understand the other 80% of the world.
Building such systems from scratch can be expensive and time-consuming. Performant NLP models often rely on vast amounts of high quality annotated data, which come at the cost of annotator time, effort and money. Therefore, much of the research community's efforts towards building tools for other languages have relied on transferring existing English models to other languages.
Previous efforts have relied on Machine Translation (MT) to translate training or test data from English to a target language (Wan 2009;Shi, Mihalcea, and Tian 2010). Others have additionally considered bilingual dictionaries to directly transfer features (Mihalcea, Banea, and Wiebe 2007), while some have explored methods such as structural correspondence learning (Prettenhofer and Stein 2010), and cross-lingual representation learning (Huang et al. 2013).
Building state-of-the-art MT systems requires expertise and vast amounts of training data. The best commercial APIs such as Google Translate 2 and Microsoft Translator 3 charge on a per-character basis, and the long-term costs for model transfer can become prohibitive. Meanwhile, bilingual dictionaries can be equally expensive to build if done manually, or contain significant noise, if induced automatically.
In this paper we propose a novel framework to transfer an existing neural English model to another language with minimal cost and effort. The framework leverages task representations -the layer in a neural network model immediately preceding the prediction layer, which we hypothesize captures an abstract semantic representation of the prediciton problem -as a form of weak supervision in unlabeled data. The result is a model that learns a language agnostic neural architecture, jointly with language specific embeddings.
Specifically, the framework: (i) Is model and task agnostic, and thus applicable to a wide range of existing neural architectures. (ii) Needs no target language training data, no translation system or bilingual dictionary -only a parallel corpus. (iii) And has the sole modelling requirement of defining a loss over task representations, thereby greatly reducing the engineering effort involved in model transfer.
Our approach is especially useful when a high quality MT system is not available for a target language or specialized domain. However, we also show in our experiments that it can be used in conjunction with an MT based transfer ap-proach, to produce state-of-the-art results.
We test our framework on transferring an English sentiment classifier, and evaluate on 3 different target languages using a public dataset. Our experiments show that our approach not only outperforms several strong baselines (including an MT system trained on the same parallel data) and previous approaches, but even outperforms the previous state-of-the-art on one language, while relying on a much simpler method and requiring significantly fewer resources. Additionally, our approach is able to learn semantically meaningful cross-lingual representations without the need for any direct supervision.

Related Work
There are several research areas related to work in this paper. Cross-lingual model transfer can be more generally perceived as an instance of domain adaptation. Previous work in this area has explored techniques such as structural correspondence learning (Blitzer, McDonald, and Pereira 2006), and feature sharing via augmentation (Daumé III 2009). Domain adaptation for deep learning has also been tackled, for example with stacked de-noising autoencoders (Glorot, Bordes, and Bengio 2011), a gradient reversal layer for domain differentiation (Ganin and Lempitsky 2014) and generalizations of Convolutional Neural Networks that capture consistencies between domains . (Yosinski et al. 2014) study the transferability of neural network components in the context of image recognition. They suggest that higher layers tend to be more specialized and domain specific, and therefore less generalizable. (Mou et al. 2016) investigate the same problem, but looking more specifically at domain adaptation in NLP. They find that all but the embedding layer tend to be too domain specific to be practically transferable. Nevertheless what we propose in our framework for cross-lingual transfer is the opposite: specifically, sharing the higher layers of a network while maintaining language specific embeddings. Our results demonstrate that this approach is, in fact, successful for our evaluation task of sentiment classification.
Sharing information across domains also pertains to Multi-Task Learning. The deep learning community's work in this area can be broadly separated into two approaches: hard, and soft parameter sharing. In hard parameter sharing, models share a common architecture with some task-specific layers (Zhang et al. 2014;, while in soft parameter sharing tasks have their own sets of parameters that are constrained by some shared penalty (Yang and Hospedales 2016;Misra et al. 2016). Our work fits in the first category, with a shared model that is complemented by language specific embeddings.
Several efforts have focused specifically on cross-lingual model transfer for NLP tasks such as part-of-speech tagging (Das and Petrov 2011), speech recognition (Huang et al. 2013) and semantic role labeling (Padó and Lapata 2009). A number of researchers have also looked at sentiment classification, such as (Wan 2009), (Pan et al. 2011), (Xiao and Guo 2014) and (Zhou, Wan, and Xiao 2016a). While we evaluate our approach of model transfer on sentiment classi-fication, our paper proposes a general framework capable of tackling many different NLP problems in a unified way. Different techniques have been used for cross-lingual transfer, including co-training (Wan 2009), structural correspondence learning (Prettenhofer and Stein 2010), and matrix factorization (Pan et al. 2011;Xiao and Guo 2014). More recently, neural approaches have also tackled the problem of model transfer with approaches such as layer sharing across languages (Huang et al. 2013), and adversarial training .
The closest to our work, in terms of modeling paradigm, is prior research on label projection (Mihalcea, Banea, and Wiebe 2007;Das and Petrov 2011), feature projection (Kozhevnikov and Titov 2014) and weak supervision (Shi, Mihalcea, and Tian 2010;Lee 2013). Our work differs from these methods by being a neural framework that integrates task featurization, model learning and crosslingual transfer in a joint schema, while being flexible enough to accommodate a wide range of target applications.
We also note research on bilingual embeddings, which relates to model transfer by seeking to embed units from different languages in a joint space. Previous solutions include modeling with canonical correlation analysis (Faruqui and Dyer 2014), matrix factorization (Shi et al. 2015) and neural networks (Klementiev, Titov, and Bhattarai 2012). The popular Word2Vec model (Mikolov et al. 2013), for example, has been modified to work for bilingual word embeddings (Gouws, Bengio, and Corrado 2015;, while others have tackled longer units of representations . (Upadhyay et al. 2016) provides a comparison of several of these approaches. Notably, these efforts typically only deal with the first embedding layer of neural networks, rather than full model transfer -which is the problem tackled in this paper.

Model Transfer by Representation Projection
To describe our general framework for cross-lingual neural model transfer we begin by providing the intuition behind the framework, then formalizing it. Finally we show how it can be applied to easily transfer an English sentiment classification model to other languages.

General Framework
Many neural NLP models can be decomposed into three distinct components. The first is an embedding layer, which converts linguistic units (words, characters, etc.) into dense representations. The last is a prediction layer, -often a softmax function -used to produce a probability distribution over the space of output labels. Sandwiched in-between these two is some task-appropriate model architecture. Our general framework is agnostic to the choice of this architecture, which can have an arbitrary network configuration and number of layers. Therefore, let us assume, for the sake of this exposition, that it is a black-box. In particular, we draw attention to the last of these layers (i.e. the one immediately preceding the prediction layer) and call this the task representation layer. These components are depicted in Figure 1. Our approach for model transfer relies on two key hypotheses. First, the black-box network and prediction layer can be shared across languages; this means that the only difference between an English and French model (for example) is the language specific embeddings (shown by color in Figure 1). Second, the task representation layer captures all the information required to make a successful prediction. Now consider a model trained on English labeled examples, and some parallel data. An indication of successful model transfer is that the French model predicts the same thing on the French side of parallel data as the English model does on the English side. We do not really care what this thing is. It can be an actual label (Mihalcea, Banea, and Wiebe 2007), in which case the approach can be referred to as label projection. But we can also try to produce the same task representation in both languages (representation projection), a softer form of weak supervision. This is the core of our framework. We will show in our experiments (see Section 4) that soft representation projection is significantly better than label projection.
We now formalize these intuitions. Consider a task T with some labeled data are English inputs and y i are outputs that take on K possible values. Without loss of generality let us assume that the inputs x i = {e i1 , ..., e il } are sequences of English words 4 . Moreover we have some parallel data .., f jl2 } are parallel English and French sentences respectively.
Let us define English embeddings To enable a shared model architecture, we require that dimensions d of vectors u i and v i be the same. We denote a mapping of the English sequence e j = {e j1 , ..., e jm } to a sequence of vectors as u j and a French sequence f j = {f j1 , ..., f jn } to a sequence of vectors v j . We define a blackbox model M with parameters θ M that takes as input, a sequence of embeddings, and yields a task representation. Specifically, for an English input x i : Finally we consider a prediction layer π with parameters θ π that yields a probability distribution over the K output variables: where π k is the k th neuron of the layer, and we use the shorthand π k i to denote P (ŷ i = k). Our framework then optimizes two losses.
Labeled Loss: Given that we have labeled English data, we optimize the following loss for the combined network: where ∆ L is a loss function defined between π k i and the response variable y i . For example, in the binary case ∆ L might be a cross-entropy loss.
Unlabeled Loss: On the parallel data we use the English task representations generated by the model as weak supervision for the French side. Specifically: where ∆ P is some loss function between task representations yielded on parallel inputs. Since task representations are vectors, the mean-squared error between them -for example -might be an appropriate loss. Figure 2: The hierarchical RNN model architecture that we use to predict sentiment polarity. A sentence RNN is used to convert sequences of word embeddings into sentence representations, which are in turn input into a Review-level RNN to generate a task representation.
Then jointly, our final optimization problem is L = L D L + αL D P , where α is a hyperparameter that controls the mixing strength between the two loss components.
Notice that with this framework there is no requirement for MT, since neither training nor test data is ever translated. Nor are any other resources, such as a pivot lexicon or bilingual dictionary, used. The only requirement is paralled data and the definition of a loss function L D P . The model architecture mathcalM and the labeled loss L D L are properties one would have defined anyway for an English only model.

Training and Prediction
With well defined loss functions ∆ L and ∆ P , training consists of back-propagating errors through the network and updating the parameters of the model. We distinguish two separate scenarios: two-stage training, and joint training.
In two-stage training we first train the labeled loss given by Equation 3 on the labeled English data by finding U * , θ * M , θ * π = arg max U,θ M ,θπ L D L . We then freeze the English embeddings U , and the shared model parameters θ M and θ π .
In the second stage we only update the French embeddings V on the parallel data using the unlabeled projection loss given by Equation 4 by optimizing V * = arg max In contrast, for joint training, we do not freeze any parameters and make joint updates. That is, we optimize At prediction time, all we do is use the model consisting of the parameters V * , θ * M , θ * π . That is, we swap out the English embeddings of the full task model for French ones; this is depicted on the right-hand side of Figure 1.

Example Model Transfer: Sentiment Classification
We now show how the general framework we have described can be used to easily transfer an English sentiment classifier to other languages. All we need is to define the model architecture M and the two loss functions L D L and L D P . But first a note on data granularity. In our exposition of Section 3.1, we referred to inputs as sequences of words. However, in sentiment classification we now consider reviews, which are sequences of sentences -which are in turn, sequences of words. Because our labeled data is chunked into review-sized inputs, the parallel data only needs to be aligned at paragraph, rather than sentence or word level.
Our model architecture M is a hierarchical Recurrent Neural Network (RNN) that is depicted in Figure 2. Hierarchical RNN models for document-level classification have previously proven to be effective (Yang et al. 2016;Zhou, Wan, and Xiao 2016a). For reference, our architecture achieves an F1 score of 0.92 when trained and tested in English on our benchmark dataset (see Section 4.2). The model consists of a Sentence RNN which converts sequences of words into sentence representations, and a Review-level RNN which converts a sequence of sentence representations into a task representation. The variant of RNN we use is Gated Recurrent Units (GRUs) (Cho et al. 2014).
Given the binary nature of the prediction task, the prediction layer is simply a sigmoid layer with one output neuron that computes the probability of a positive label: The labeled loss is a cross-entropy loss: On the parallel side, the unlabeled loss is a mean-squared error loss: where d T is the dimension of the task representation R T , and R T (i) denotes its i th dimension.

Evaluation
We evaluate the transfer of the sentiment classifier we proposed in Section 3.3 to three different languages on a publicly available dataset. We also show how the model may be combined with a simple translation baseline to yield stateof-the-art results. We begin by providing implementation details and describing the data.

Implementation Details
We implement our framework in Keras 5 and Tensor-Flow 6 . The code will be made available by December 2018 at https://github.com/Microsoft/ CLModelTransfer. In our standard model, we set the embedding size to 64, and the encoding size of both sentence-level and reviewlevel GRUs to 256. We use padding and truncation to normalize all input data to a uniform 30 sentences, each with 20 words. We set the dropout factor to 0.5 (Srivastava et al. 2014) for all but the embedding layer. In two-stage training, we train the sentiment classifier on English labeled data for 10 epochs, then freeze its parameters, followed by 10 epochs of training in the parallel data. In the joint training setting, we pre-train the sentiment classifier on English labeled data for 4 epochs, followed by 12 epochs of joint training over labeled and parallel data. The optimizer we use is RMSProp (Tieleman and Hinton 2012). We additionally experimented with varying several of the model hyperparameters 7 . A study of model size is presented in Section 5.1.

Data
We evaluate on the multilingual review dataset from (Prettenhofer and Stein 2010), which consists of Amazon product reviews for books, DVDs and music in 4 different languages: English, German, French and Japanese. Reviews labeled > 3 stars are considered positive, while those with < 3 stars are tagged as negative. The reviews across languages are not aligned in any way.
We use the test portions of the data (consisting of a balanced set of 6000 reviews in each of the three languages) to measure precision, recall, F1 and accuracy in German, French and Japanese. On the English side, we use all available non-test instances from the dataset as labeled training data. This amounts to a total of 111,220 reviews. We apply the logic described above to convert "star-ratings" into binary positive or negative labels.
We use the Europarl corpus (Koehn 2005) for English-German and English-French language pairs to obtain unlabeled parallel data. For each of these, the corpus contains approximately 2 million sentence pairs. In the English-Japanese language pair we use a parallel subtitle corpus (Pryzant et al. 2017), which consists of 3.2 million sentence pairs. The subtitle corpus consists of much shorter elements, which are sometimes text fragments or even individual words.
While all the parallel data is aligned at sentence level, our model does not actually need such fine-grained alignments. Thus we mimic paragraph-level alignment by batching contiguous groups of sentences into pseudo paragraphs. We vary the group size randomly between 15 and 30, and ignore internal alignment structure. As described in Section 4.1, padding and truncation are used to normalize the size of parallel pseudo paragraphs into consistent inputs.

Baselines
We compare against a number of baselines, which we divide into three broad categories.
Translation Baselines We build models over two translation systems. The first is a commercial solution from Microsoft (MSTrans). This system is trained on orders of magnitude more data than is available to us, and is highly tuned.
So, in order to make a fairer comparison, we also train a state-of-the-art Neural Machine Translation (NMT) architecture on the same parallel data available to us (TFTrans). We use an encoder-decoder architecture, which consists of 3 layers of bidirectional LSTMs in both encoder and decoder; the embedding size is set to 128, while the dimensions of the hidden representations in the encoders are set to 512.
We distinguish 2 variants of translations. Training-time Translation (TrnT), which translates the English training data into another language and then trains a sentiment model in that language; and Test-time Translation (TstT), which trains an English sentiment model and uses it to classify reviews that are translated into English at test time.
Finally we also experiment with 2 modeling approaches. The first is a neural model (NN) based on the architecture in Figure 2. The second is a logistic regressor with L2 regularization that is trained on uni-, bi-and tri-gram features.
This yields a total of 8 translation baselines: the crossproduct of 2 types each of translation, training/testing variants, and modeling approaches.
No Translation Baselines We also build 3 baselines that do not rely on translation. The first leverages bilingual embeddings. Specifically we train a bilingual skip-gram model (Bi-SG) on our parallel data sets based on (Luong, , and use the resulting English side embeddings as fixed features in training the English sentiment model. The second and third models are based on Label Projection. This is similar to our architecture for model transfer, but instead of using task representations as soft supervision for the unlabeled loss, we use the predicted label on the English side of the parallel data as hard supervision. We distinguish 2 variants of this approach: 2-stage training, and joint training (see Section 3.2).
Prior Work Baselines Finally, we also compare against prior work. Here we cite (Zhou, Wan, and Xiao 2016b), who have the current state-of-the-art on the Multilingual Amazon Reviews dataset. All previous work on this dataset only reports accuracy scores, so we are only able to cite these numbers. (Zhou, Wan, and Xiao 2016b) report results from a number of different models that we also provide as reference points. Notably, all these approaches require some form of machine translation -either at training time, test time, or both.

CL-SCL:
The cross-lingual structural correspondence learning approach by (Prettenhofer and Stein 2010) that set the original benchmark results for the Multilingual Reviews dataset.

CR-RL: A bilingual embedding method from (Xiao and
Guo 2014) that shares knowledge across languages by having vectors that are part language-dependent, part languageindependent.  Bi-PV: An application of , who propose learning bilingual paragraph vectors by treating paragraph encodings as context.

Bi-DRL:
The bilingual document representation learning model by (Zhou, Wan, and Xiao 2016b), that is the current state-of-the-art. It leverages monolingual and bilingual constraints in order to jointly train a classifier, but requires both training and test data to be translated.

Results
The results of our evaluation are presented in Table 1. There are several interesting findings here. First, the NN model based on MSTrans produces very strong results. In fact, both TrnT and TstT variants of this simple baseline outperform the previous state-of-the-art (Bi-DRL) across all 3 languages. Note that Bi-DRL also uses a commercial translation engine (Google) at both training and test time. These improvements can be attributed to the progress that MT has made; (Prettenhofer and Stein 2010) report results from an MT baseline using Google translate, and the results from 2010 are significantly worse than effectively the same baseline in our work. However, high quality translation comes at a cost. Translating our English training set into one other language costs approximately $1000, based on Microsoft Translator pricing; costs are similar for Google's translation service. Translation at test time is even worse in the long run, since costs are at least amortized in TrnT models. Costs can easily skyrocket, if translation of large datasets into many languages is considered.
Meanwhile, using a state-of-the-art NMT architecture trained on publicly available data (TFTrans) produces significantly worse results. Because of the discrepancies between training and test data, introduced by poorer translations, we notice that LR can sometimes outperform NN models. This is in contrast to MSTrans, where higher translation quality means that NN yields better results. The performance of TrnT and TstT are also reversed vis-à-vis MSTrans and TFTrans; while TrnT performs slightly better in the case of TFTrans, TstT performs better for MSTrans.
The No Translation baselines are worse still. Label projection uses hard supervision that affects model performance dramatically. This is likely because the binary labels we use as weak supervision in parallel data do not necessarily mean anything, and therefore cause the model to learn parameters that cannot generalize to actually meaningful test reviews. Meanwhile, Bi-SG is little better than random. We hypothesize that cross-lingual embeddings -if trained in isolation -are not able to mesh with higher layers of neural networks, which are often fragilely co-ordinated with one another (Yosinski et al. 2014).
Meanwhile, our approach -especially under joint training -performs significantly better. We outperform the No Translation and TFTrans baselines by large margins. The differences are statistically significant, measured by Fisher's Exact Test (p-value = 0.01). We also outperform all prior work, except the state-of-the-art Bi-DRL model. In fact, in Japanese we even outperform Bi-DRL and rival MSTrans-NN on accuracy, and produce the best F1 score. This shows the robustness of our approach, which is less susceptible to language divergence than translation-based models.
In summary, our simple yet flexible framework produces results that are significantly better than other resource reliant, complex models, which require translation or curated dictionaries. We even rival state-of-the-art approaches that rely on high quality commercial translation engines, which have recourse to orders of magnitude more data.

Model Composition with Translation
While we are not able to outperform the MSTrans baseline, we examine if we can improve on it by combining our approach with translation. We test this by training a simple interpolation between our joint model and the MSTrans-NN models on training data. We then evaluate on the test sets.
The results are presented in Table 2. This reveals that we are able to improve upon 2 of the 3 evaluation languages. The differences on German -while higher numerically -are not statistically significant. The results for French and Japanese are state-of-the-art. Thus our approach, while capable even without a translation engine, can also be used in combination with a commercial translator to yield state-of-the-art results.
As a reference, the empirical upper-bound yielded by native training and testing -that is, using train and test data of the same language from the dataset -is about 92% for German and French, and 90% for Japanese. An interesting avenue for future research is to explore better model composition techniques that could potentially close the gap with the upper-bound.

Model Analysis
Next we analyze our models both quantitatively and qualitatively.

Effects of Model Size
We first consider the effects of model size on cross-lingual transfer. We vary the embedding dimensions from 48 to 256 in increments of 16, and encoding dimensions from 256 to 1024 in increments of 64. For each size setting we run a total of 10 experiments and take the average accuracy across runs. The results of this experiment are presented in Figure 3.
They show that there is a general downward trend in accuracy with larger models. This is likely due to two factors.  The first is that we have limited labeled training data, and with more parameters, overfitting is always an issue. Second, the unlabeled loss (Equation 4) is effectively using a vector (noisily generated by the sentiment model on unlabeled data) as weak supervision. The larger this vector, the more noise it may contain, which in turn leads to less reliable supervision.
Thus our framework for model transfer is better suited to more compact models, unless bigger training datasets are available.

Cross-Lingual Word Association
We finally consider the embeddings learned via representation projection. Table 3 shows a few sentiment bearing English words, and their nearest French neighbors (by vector cosine distance on their respective embeddings) in our joint model.
We can see that positive (or negative) sentiment terms in English are close to positive (or negative) terms in French. Note that nearest neighbors are not necessarily accurate translations -the sentiment prediction task does not really require translations; it is sufficient to identify words that echo the same sentiment. Our approach is thus able to pick up on sentiment similarity across languages, without direct supervision and only using the weak fuzzy signal from representation projection.

Conclusion and Future Work
In this paper, we have shown a general framework for transferring neural models from one language to another. The framework leverages the novel idea of representation projection: using intermediate task representations as a form of weak predictive supervision. Notably our task agnostic framework requires little by way of additional resources (a parallel corpus is sufficient) and engineering (the only requirement is a loss function over task representations in parallel data). We show how this framework can be used to easily adapt an existing English neural model for sentiment classification to other languages. We test our approach on three target languages and evaluate on a public dataset of product reviews. The results reveal that our model is able to outperform a number of strong baselines, and rival more complex models that have access to significantly more training resources. When combined with a commercial translation-based model, we produce state-of-the-art results. Finally, our approach is able to learn embeddings that transfer the semantics of sentiment polarity across languages, without the need of direct supervision.
There are several avenues of future work that we plan to tackle. Since what we have proposed in this paper is a framework rather than a single model, we hope to investigate it's application to other problems and domains. Specifically we hope to tackle NLP tasks at different levels of granularity, such as sentence or word level classification problems. Our goal is to also extend the framework in order to accommodate more complex structured prediction problems, such as part-of-speech tagging and dependency parsing, as well as tackle multiple problems at once in a multi-task manner. Finally, we're also excited by the possibility of applying the framework to multi-modal (instead of multi-lingual) transfer, where -for example -one might transfer sentiment understanding to images, without the need for explicit image annotations.