Automatic Translating between Ancient Chinese and Contemporary Chinese with Limited Aligned Corpora

The Chinese language has evolved a lot during the long-term development. Therefore, native speakers now have trouble in reading sentences written in ancient Chinese. In this paper, we propose to build an end-to-end neural model to automatically translate between ancient and contemporary Chinese. However, the existing ancient-contemporary Chinese parallel corpora are not aligned at the sentence level and sentence-aligned corpora are limited, which makes it difficult to train the model. To build the sentence level parallel training data for the model, we propose an unsupervised algorithm that constructs sentence-aligned ancient-contemporary pairs by using the fact that the aligned sentence pair shares many of the tokens. Based on the aligned corpus, we propose an end-to-end neural model with copying mechanism and local attention to translate between ancient and contemporary Chinese. Experiments show that the proposed unsupervised algorithm achieves 99.4% F1 score for sentence alignment, and the translation model achieves 26.95 BLEU from ancient to contemporary, and 36.34 BLEU from contemporary to ancient.


Introduction
The ancient Chinese was used for thousands of years. There is a huge amount of books and articles written in ancient Chinese. However, both the form and grammar of the ancient Chinese have been changed. Chinese historians and littérateurs have made great efforts in translating such literature into contemporary Chinese, a big part of which is publicly available on the Internet. However, there is still a big gap between these literatures and parallel corpora, because most of the corpora are coarsely passage-aligned, the orders of sentences are different. To train an automatic translating model, we need to build a sentence-aligned corpus first.
Translation alignment is an important pre-step for machine translation. Most of the previous work focuses on how to apply supervised algorithms on this task using features extracted from texts. The Gale Church algorithm [5,7] uses statistical or dictionary information to build alignment corpus. Strands [17,18] extracts parallel corpus from the Internet. A logarithmic linear model [24] is also used for Chinese-Japanese clause alignment. Besides, features such as sentence lengths, matching patterns, Chinese character co-occurrence in Japanese and Chinese are also taken into consideration. The observation that Chinese character co-occurrence also exists in ancient-contemporary Chinese is also used to ancient-contemporary Chinese translation alignment [11,12].
The method above works well, however, these supervised algorithms require a large parallel corpus to train, which is not available in our circumstance. These previous algorithms did not make good use of the characteristics of ancient-contemporary Chinese pair. To overcome these shortcomings, we design an unsupervised algorithm for sentence alignment based on the observation that differently from a bilingual corpus, ancient-contemporary sentence pairs share many common characters in order. We evaluate our alignment algorithm on an aligned parallel corpus with small size. The experimental results show that our simple algorithm works very well (F1 score 99.4), which is even better than the supervised algorithms.
Deep learning has achieved great success in tasks like machine translation. The sequence to sequence (seq-to-seq) model [21] is proposed to generate good translation results on machine translation. The attention mechanism [1] is proposed to allow the decoder to extract phrase alignment information from the hidden states of the encoder. Most of the existing NMT systems are based on the seq-to-seq model [9,3,21] and the attention mechanism. Some of them have variant architectures to capture more information from the inputs [20,23], and some improve the attention mechanism [13,15,16,8,4,2], which also enhanced the performance of the NMT model. Inspired by the work of pointer generator [19], we use a copying mechanism named pointer-generator model to deal with the task of ancient-contemporary translation task because ancient and contemporary Chinese share common characters and some same proper nouns.
Experimental results show that a copying mechanism can improve the performance of seq-to-seq model remarkably on this task. We show some experimental results in the experiment section. Other mechanisms are also implied to improve the performance of machine translation [10,14].
Our contributions lie in the following two aspects: -We propose a simple yet effective unsupervised algorithm to build the sentencealigned parallel corpora, which make it possible to train an automatic translating model between ancient Chinese and contemporary Chinese even with limited sentence-aligned corpora. -We propose to apply the sequence to sequence model with copying mechanism and local attention to deal with the translating task. Experimental results show that our method can achieve the BLEU score of 26.41 (ancient to contemporary) and 35.66 (contemporary to ancient).

Unsupervised Algorithm for Sentence Alignment
We review the definition of sentence alignment first.
Given a pair of aligned passages, the source language sentences S and target language sentences T , which are defined as S := {s 1 , s 2 , · · · , s n }, T := {t 1 , t 2 , · · · , t m } The objective of sentence alignment is to extract a set of matching sentence pairs out of the two passages. Each matching pair consists of several sentence pairs like (s i , t j ), which implies that s i and t j form a parallel pair.
For instance, if S = {s 1 , s 2 , s 3 , s 4 , s 5 }, T = {t 1 , t 2 , t 3 , t 4 , t 5 } and the alignment result is }. It means source sentence s 1 is translated to target sentence t 1 , s 3 is translated to t 2 and t 3 , s 4 and s 5 are translated to t 4 while s 2 is not translated to any sentence in target sentences. Here we may assume that source sentences are translated to target sentences in order. For instance (s 1 , t 2 ) and (s 2 , t 1 ) can not exist at the same time in the alignment result.
Translating ancient Chinese into contemporary Chinese has the characteristic that every word of ancient Chinese tends to be translated into contemporary Chinese in order, which usually includes the same original character. Therefore, correct aligned pairs usually have the maximum sum of lengths of the longest common subsequence (LCS) for each matching pair. Let ) be the length of the longest common subsequence of a matching pair of aligned sentences consisting of source language sentences s[i 1 , i 2 ] and target language sentences t[j 1 , j 2 ], which are defined as where [empty str] denotes an empty string. The longest common subsequence of an empty string and any string is 0. We use the dynamic programming algorithm to find the maximum score and its corresponding alignment result. Let f (i, j) be the maximum score that can be achieved with partly aligned sentence pairs until s i , t j . To reduce the calculation cost, we only consider cases where one sentence is matched with no more than 5 sentences: ensures that one sentence is matched with no more than 5 sentences and M = 0 holds if and only if one sentence is not matched with any of the sentences. We can preprocess all lcs(s scores and store them for using in algorithm, which has a time complexity of O(mn). The pseudo code is shown in Algorithm 1. Then for every f (i, j), we only need to enumerate i ′ , j ′ for O(1) times and the time complexity of proposal dynamic programming algorithm is O(mn).
When the size of corpus grows, this algorithm will be time-consuming, which means our algorithm is more suitable for passage-aligned corpora instead of a huge text. In reality, we find that when translating a text written in ancient Chinese into contemporary Chinese. Translators tend not to change the structure of the text, namely, a book written in ancient Chinese and its contemporary Chinese version are a passage-aligned corpus naturally. Therefore, we can get abundant passage-aligned corpora form Internet.

Algorithm 1 Dynamic Programming Algorithm to Find the Alignment Result.
Preprocess lcs scores and store them in memory.

Neural Machine Translation Model
Sequence-to-sequence model was first proposed to solve machine translation problem. The model consists of two parts, an encoder and a decoder. The encoder is bound to take in the source sequence and compress the sequence into hidden states. The decoder is used to produce a sequence of target tokens based on the information embodied in the hidden states given by the encoder. Both encoder and decoder are implemented with Recurrent Neural Networks (RNN).
To deal with the ancient-contemporary translating task, we use the encoder to convert the variable-length character sequence into h t , the hidden representations of position t, with an Bidirectional RNN: Where f is a function of RNN family, x t is the input at time step t. The decoder is another RNN, which generates a variable-length sequence token by token, through a conditional language model, Where E is the embedding matrix of target tokens, y t−1 is the last predicted token. We also implement a beam search mechanism, a heuristic search algorithm that expands the most promising node in a limited set, for generating a better target sentence.
In the decoder, suppose l is the length of the source sentence, then the context vector c t is calculated based on the hidden states s t of the decoder at time step t and all the hidden states h = {h i } l i=1 in the encoder, which is also known as the attention mechanism, We adopt the global attention mechanism in the baseline seq-to-seq model, where a t,i is the attention probability of the word in position i of the source sentence in the decoder time step t and h i is the hidden state of position i of the source sentence. Because in most cases ancient and contemporary Chinese have similar word order, instead of the normal global attention in the baseline seq-to-seq model, we apply local attention [13,22] in our proposal. When calculating the context vector c t , we calculate a pivot position in the hidden states h of the encoder, and calculate the attention probability in the window around the pivot instead of the whole sentence, where p t,i is the mask score based on the pivot position in the hidden states h of the encoder.
Machine translation model treats ancient and contemporary Chinese as two languages, however, in this task, contemporary and ancient Chines share many common characters. Therefore, we treat ancient and contemporary Chinese as one language and share the character embedding between the source language and target language.

Copying Mechanism
As is stated above, ancient and contemporary Chinese share many common characters and most of the name entities use the same representation. Copying mechanism [6] is very suitable in this situation, where the source and target sequence share some of the words. We apply pointer-generator framework in our model, which follows the same intuition as the copying mechanism. p t (w), the output probability of token w is calculated as, where p G t is dynamically calculated based on the hidden state s t and the context vector c t , P V t (w) is the probability for token w in traditional seq-to-seq model. a t,i is the attention probability at the time step t in decoder and position i in source sentence which satisfies src i = w, namely the token in position i in source sentence is w. σ is the sigmoid function.
The encoder and decoder networks are trained jointly to maximize the conditional probability of the target sequence. We use cross-entropy as the loss function. We use characters instead of words because characters have independent meaning in ancient Chinese and the number of characters is much lower than the number of words, which makes the data less sparse and greatly reduces the number of OOV. We also can implement the pointer-generator mechanism in summarization on our AT-seq-to-seq model to copy some proper nouns directly from the source language. 3 Experiments

Datasets
Sentence Alignment We crawl passages and their corresponding contemporary Chinese version from the Internet. To guarantee the quality of the contemporary Chinese translation, we choose the corpus from two genres, classical articles and Chinese historical documents. After proofreading a sample of these passages, we think the quality of the passage-aligned corpus is satisfactory. To evaluate the algorithm, we crawl a relatively small sentence-aligned corpus consisting of 90 aligned passages with 4,544 aligned sentence pairs. We proofread them and correct some mistakes to guarantee the correctness of this corpus.
Translating We conduct experiments on the data set built by our proposed unsupervised algorithm. The data set consists of 57,391 ancient-contemporary Chinese sentence pairs in total. We split sentence pairs randomly into train/dev/test dataset with sizes of 53,140/2,125/2,126 respectively. The vocabulary statistics information is in Table 1.

Experimental Settings
Sentence Alignment We implement a log-linear model on contemporary-ancient Chinese sentence alignment as a baseline. Following the previous work, we implement this model with a combination of three features, sentence lengths, matching patterns and Chinese character co-occurrence [24,11,12]. We split the data into training set (2,999) and test set (1,545) to train the log-linear model. Our unsupervised method does not need training data. Both these two methods are evaluated on the test set.
Translating We conduct experiments on both translating directions and use BLEU score to evaluate our model. We implement a one-layer Bidirectional LSTM with a 256-dim embedding size, 256-dim hidden size as encoder and a one-layer LSTM with attention mechanism as decoder. We also implement local attention or pointer generator mechanism on the decoder in our proposed model. We adopt Adam optimizer to optimize our loss functions with a learning rate of 0.0001. The training batch size of our model is 64 and the generating batch size is 32. The source language and target language share the vocabulary.

Experimental Results
Sentence Alignment Our unsupervised algorithm gets an F1-score of 99.4%, which is better than the supervised baseline with all features, 99.2% (shown in Table 2). Our proposal algorithm does not use the features of sentence lengths and matching pattern. If we only adopt the feature of Co-occurrence, the performance of our proposal is 1.1% higher on F1-score than that of the supervised baseline (98.3%). To conclude, our proposal algorithm uses fewer features and use no training data but perform better than the supervised baseline.
Translating Experimental results show our model works well on this task (Table 3). Compared with the basic seq-to-seq model, copying mechanism gives a large improvement, because the source sentences and target sentence share some common representations, we will also give an example in the case study section. Local attention gives a small improvement over the traditional global attention, this can be attributed to shrinking the attention range, because most of the time, the mapping between ancient and contemporary Chinese is clear. A more sophisticated attention mechanism which makes full use of the characteristics of ancient and contemporary Chinese may further improve the performance.

Sentence Alignment
We find that the small fraction of data (0.6%) that our method makes mistakes are mainly because of the change of punctuation. For example, in ancient Chinese, there is a comma "," after "异哉，" (How strange!), while in contemporary Chinese, "怪啊！" (How strange!), an exclamation mark "!" is used, which makes the sentence to be an independent sentence. Since the sentence is short and there is no common character, our method fails to align the sentences correctly. However, such problems also exist in supervised models.

Necessity of Building a Large Sentence-aligned Corpus
From Table 4, we can see that the results are very sensitive to the scale of the training data size. Therefore, our unsupervised method of building a large sentence-aligned corpus is necessary. If we do not build a large sentence-aligned corpus by our sentence alignment algorithm, we will only have limited sentence-aligned corpora and the performance of translating will be worse.

Translating Result
Under most circumstances, our models can translate sentences between ancient Chinese and contemporary Chinese properly. For instance in Table 5, our models can translate "薨 (pass away)" into "去世 (pass away)" or "逝世 (pass away)", which are the correct forms of expression in contemporary Chinese. And our models can even complete some omitted characters. For instance, the family name "刘 (Liu)" in "中山王刘焉 (Liu Yan, King of Zhongshan)" was omitted in ancient Chinese because "中山王 (King of Zhongshan)" was a hereditary peerage offered to "刘 (Liu)" family. And our model completes the family name "刘 (Liu)" when translating. For proper nouns, the seq-to-2seq baseline model can fail sometimes while the copying model can correctly copy them from the source language. For instance, the seq-to-seq baseline model translates "焉 (Yan)" into "刘裕 (Liu Yu, a famous figure in the history)" because "焉 (Yan)" is relatively low-frequent words in ancient Chinese. However, the copying model learns to copy these low-frequency proper nouns from source sentences directly. Translating dates between ancient and contemporary Chinese calendar requires background knowledge of the ancient Chinese lunar calendar, and involves non-trivial calculation that even native speakers cannot translate correctly without training. In the example, "辛卯 (The Xinmao Day)" is the date presented in the ancient form, our model fails to translate it. Our model fails to transform between the Gregorian calendar and the ancient Chinese lunar calendar and choose to generate a random date, which is expected because of the difficulty of such problems.

Conclusion
In this paper, we propose an unsupervised algorithm to construct sentence-aligned sentence pairs out of a passage-aligned corpus to build a large sentence-aligned corpus. We propose to apply the sequence to sequence model with attention and copying mechanism to automatically translate between two styles of Chinese sentences. The experimental results show that our method can yield good translating results.