\documentclass[english]{jnlp_3.3}
\usepackage{jnlpbbl_2.2}
\usepackage[dvipdfmx]{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{url}
\usepackage{hangcaption_jnlp}
%%%%\usepackage{array}
%%%%\usepackage{udline}
%%%%\setulminsep{1.2ex}{0.2ex}
%%%%\let\underline=\ul
\allowdisplaybreaks

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% author's definition
%%%%\usepackage{color}
%%%%\usepackage[normalem]{ulem}
%%%%\usepackage{comment}
%%%%\usepackage{soul}
%%%%\usepackage{url}
%%%%\newcommand*{\sudoh}{\textcolor{blue}}
%%%%\newcommand*{\red}{\textcolor{red}}
%%%%\newcommand*{\del}{\textcolor{green}}
%%%%\newcommand{\Erase}[1]{\textcolor{bleu}{\sout{\textcolor{bleu}{#1}}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\Volume{28}
\Number{3}
\Month{September}
\Year{2021}
%%%%\Issuetitle{「　　　　」特集号}

\received{2020}{12}{16}
\revised{2021}{3}{23}
%%%%\rerevised{2006}{5}{6}
\accepted{2021}{5}{14}

\setcounter{page}{778}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\esubject{General Paper}
\etitle{Length-constrained Neural Machine Translation \\using Length Prediction and Perturbation into Length-aware Positional Encoding}
\eauthor{Yui Oka\affiref{Author_1}\affiref{Author_2} \and Katsuhito Sudoh\affiref{Author_1} \and Satoshi Nakamura\affiref{Author_1}} 
\eabstract{%
Neural machine translation often suffers from an under-translation problem owing to its limited modeling of the output sequence lengths.
In this study, we propose a novel approach to training a Transformer model using length constraints based on length-aware positional encoding (PE).
Because length constraints with exact target sentence lengths degrade the translation performance, we add a random perturbation with a uniform distribution within a certain range to the length constraints in the PE during the training.
In the inference step, we predicted the output lengths from the input sequences using a length prediction model based on a large-scale pre-trained language model.
In Japanese-to-English and English-to-Japanese translation, experimental results show that the proposed perturbation injection improves the robustness of the length prediction errors, particularly within a certain range.
}
\ekeywords{Positional Encoding, Neural Machine Translation}

\headauthor{Oka et al.}
\headtitle{Perturbation into Length-aware Positional Encoding in NMT}

\affilabel{Author_1}{}{Nara Institute of Science and Technology}
\affilabel{Author_2}{}{Currently with NTT Communication Science Laboratories. This work was completed when she was a graduate student.}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\maketitle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}

In autoregressive neural machine translation (NMT),
a decoder predicts one token at a time, depending on the output tokens generated thus far. 
The length of the output sentence is usually determined based on the prediction of the end-of-sentence token.
This prediction is occasionally made too early, before all of the input information is translated, causing a so-called under-translation.
An under-translation also occurs with Transformer, which is a recent standard NMT method \cite{NIPS2017_7181}.
Transformer has a sinusoidal positional encoding to incorporate the token position information in the sequence into its encoder and decoder.

Figure \ref{aspecrefpe} shows a scatter plot between the reference and NMT output lengths in Japanese-to-English and English-to-Japanese translations in the ASPEC datasets \cite{NAKAZAWA16.621} using a standard Transformer model.
We can see that Transformer often generates outputs shorter than the reference, particularly for long sentences.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% fig. 1
\begin{figure}[t]
\begin{center}
\includegraphics{28-3ia2f1.pdf}
\end{center}
\caption{Scatter plot between reference and Transformer output lengths using ASPEC dataset.}
\label{aspecrefpe}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

To solve this problem, studies have focused on the self-attention mechanism \cite{Beltagy2020Longformer} and on high entropy \cite{DBLP:conf/aaai/ZhaoZZHW19}.
Furthermore, \citeA{lakew_iwslt19} applied length-aware positional encoding to Transformer to control the output lengths.
The authors used the true output lengths in the training and input lengths instead of inference.
However, owing to the difference in sentence lengths between languages, the use of lengths in different languages during training and inference will be inappropriate for solving an under-translation.

This study focuses on the problem of short outputs by an NMT, which causes significant score drops in BLEU and other surface-based automatic evaluation metrics.
We prevent the generation of short sentences by directly outputting long sentences while maintaining the translation accuracy.

In this study, we propose a method for training an NMT model using a perturbation into length-aware positional encoding.
Although the proposed method is also based on length-aware positional encoding as in \citeA{lakew_iwslt19}, we use an output length prediction in the inference instead of the input length.
For an output length prediction, we used a large-scale pre-trained model.
In our pilot experiments, the simple use of length-aware positional encoding and output length prediction did not work.
We propose a method for inducing a perturbation into length-aware positional encoding during training.
The proposed method increases the robustness of the length-constrained NMT decoding on errors in the output length prediction and improves the accuracy of the translation.
In the experiments using the ASPEC Japanese-English dataset, the proposed method outperformed a standard baseline Transformer by 0.4 points in BLEU for an English-to-Japanese translation, and by 0.3 points for a Japanese-to-English translation.
Significant improvements of 3.22 points over the baseline are shown on short sentences within ten subwords in English-to-Japanese translations.
However, in the experiments using the WMT14 German-English dataset \cite{bojar-EtAl:2014:W14-33}, it did not outperform the baseline because of large errors in the output length prediction.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Related Work}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Length-constraints}

Herein, we introduce other length-constraint methods.

There have been some previous studies on constraining the output length in neural sequence-to-sequence models.
\citeA{niehues-2020-machine}
used input and output embeddings to constrain the output length. The input-based variant provided input and output lengths to the encoder during the training time. The output-based variant incorporates the number of remaining output words into the decoder.
In addition, \citeA{kikuchi-etal-2016-controlling} also proposed an approach to giving the remaining length to the model during this decoding process on a summarization task.
Moreover, \citeA{takase-okazaki-2019-positional} proposed two variants of length-aware positional encodings to control the output length for the application of Transformer to the problem of automatic summarization, i.e., length-difference positional encoding (LDPE) and length-ratio positional encoding (LRPE).

There is another method for imposing length constraints outside the NMT model.
\citeA{yang-etal-2018-breaking} proposed a rescoring method for applying length constraints in a beam search during inference, i.e., the so-called BP-$norm$. 
The authors added an additional term $S_{bp}$ to the output score function, which is defined as follows:
\begin{gather}
S_{bp} (x,y) = log bp + S(x,y)/|y| \\ 
\label{eqn:bp-norm}
bp = min \{ e^{1-1/lr}, 1 \} \\
lr = |y|/|y^{*}|
\end{gather}
Here, $x$ and $y$ are the input sentences and hypotheses, and
$|y|$ denotes a given length constraint.
In addition, $bp$ is a brevity penalty placed on a short translation in calculating the translation quality metric BLEU (Papineni, Roukos, Ward, and Zhu 2002), and
$S(x,y)$ is the standard length normalization score \cite{wu2016google} for inference.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Prediction of Target Length in NMT}

The translation with length-constraints requires a prediction of the target sentence lengths. \\
\citeA{yang-etal-2020-predicting-using} proposed a model that concatenates the information of the encoder output and source length and predicts the target sentence length as a classification task.
The translation accuracy was improved through multi-task learning of this length prediction model and the original translation model, or by concatenating the length prediction model output to the output of the original decoder.
Another recent NMT methodology, called non-autoregressive NMT, uses fertility \cite{gu2018nonautoregressive} and iterative edits \cite{NEURIPS2019_675f9820} in non-autoregressive models.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Output Length Control using Positional Encoding}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Positional Encoding with Absolute Position}

Transformer uses a positional encoding (PE) on both the encoder and decoder
to embed positional information into the input and output tokens as real-valued vectors without recurrent connections, as in previous NMT methods based on recurrent neural networks.
In the original Transformer implementation \cite{NIPS2017_7181}, the following sinusoidal PE is used:
\begin{equation}
PE_{(pos,2i)} = sin\left( \frac{pos}{10000^\frac{2i}{d}} \right),
PE_{(pos,2i+1)} = cos\left( \frac{pos}{10000^\frac{2i}{d}} \right),
\label{eqn:pe}
\end{equation}
where $pos$ is the absolute position in the sequence; $2i$ and $2i+1$ represent even and odd dimensions in the PE vector, respectively; and $d$ is the dimension of the embedding. 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Length Difference Positional Encoding}

One of the variants, LDPE, considers the difference in the remaining length to the final position, as follows:
\begin{equation}
LDPE_{(pos,len,2i)} = sin\left( \frac{len-pos}{10000^\frac{2i}{d}} \right),  
LDPE_{(pos,len,2i+1)} = cos\left( \frac{len-pos}{10000^\frac{2i}{d}} \right)
\label{eqn:ldpe}
\end{equation}
where $len$ is the given output sequence length.
It is applied only to the decoder to generate a sequence of a given length.
\citeA{takase-okazaki-2019-positional} used character-based lengths for summarization constraints and revealed that LDPE can effectively control the output length.\footnote{This paper focuses only on LDPE because it works better than the other variant, LRPE, as shown in the literature \cite{takase-okazaki-2019-positional} and our prior study \cite{oka-etal-2020-incorporating}.}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{LDPE-based Output Length Control in NMT}

\citeA{lakew_iwslt19} applied LDPE and LRPE to Transformer-based NMT for controlling the output sequence lengths.
They trained an NMT model using output length constraints based on LDPE and LRPE, along with special tokens representing length ratio classes (short, normal, and long) between input and output sentences.
In terms of inference, they used the length of an input sentence as the length constraint on both LDPE and LRPE.
The purpose of their study is to control the output length to short, normal, and long with respect to the input length using a length ratio token and not to mitigate the under-translation problem.
For our purpose, the input length is not a reliable estimator of the output length because the actual output length varies with the input content and target languages.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Proposed Method}

We tackle the shorter sentence generation problem by using an appropriate output length in inference with a length-constrained NMT model.
However, the simple application of LDPE resulted in a significant decrease in BLEU even with the reference lengths, as shown later in the experimental results.
Motivated by this finding, we propose a novel approach to training an NMT model with length-aware PE that incorporates perturbations into length-aware PE. The length constraints in the inference are provided by the output length prediction using pre-trained models.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Perturbations into Length-aware Positional Encoding}

The transformer-based model with LDPE and LRPE generates a sequence that almost matches the given length constraints \cite{takase-okazaki-2019-positional}.
This characteristic is not always appropriate for machine translation because some translation variants have different lengths.
In this study, we incorporate random perturbation into the length constraints for LDPE during training to improve the robustness of such length variants and possible length prediction errors in the inference.
The perturbation is given as a random integer from a uniform distribution within a certain range.
In the case of a perturbation range of $\left[-2, 2\right]$, we randomly choose an integer from $\left[-2, -1, 0, 1, 2\right]$ for a sentence and add it to all length constraints in the sentence.
The perturbations were given randomly during the training, which means that perturbations were determined randomly and independently for a sentence in different training epochs.

Although the different positional encoding vectors might appear in the same position when a negative value is applied as a perturbation, for simplicity, we do not consider such cases in this study.
The length constraints in the training time were given by the reference lengths.
The perturbations were used only during training.
The proposed perturbation into length-aware positional encoding is given with a length perturbation as follows:
\newpage
\begin{gather}
LDPE_{propose(pos,len,2i)} = sin\left( \frac{len+perturbation-pos}{10000^\frac{2i}{d}} \right).
\\
LDPE_{propose(pos,len,2i+1)} = cos\left( \frac{len+perturbation-pos}{10000^\frac{2i}{d}} \right)
\end{gather}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Output Length Prediction using Pre-trained Models}
\label{proposed_prediction}

As mentioned earlier, \citeA{lakew_iwslt19} used the input length as the length constraint during the inference.
However, the input length is not a good proxy for the output length based on our observation of parallel corpora.
Table \ref{corpusdata} shows the statistics of the parallel corpora used for our experiments (the details of which are described in Section 4.1). 
Such statistics include the difference in mean length and the variance when we use the length of a source language sentence as a proxy of the length of the corresponding target language sentence, as well as the Pearson correlation between these lengths.
All lengths are based on subwords using
SentencePiece \cite{kudo-richardson-2018-sentencepiece} trained using the training portion of the parallel corpora with the joint subword vocabulary in two languages.
As we can see from Table \ref{corpusdata}, there are large differences in the lengths of the sentence pairs.\footnote{We show the detailed dataset histograms in the appendix.} 
We can also identify some differences among the training, development, and test sets.
Thus, we use the output length prediction during the inference.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 1
\begin{table}[b]
\input{02table01.tex}
\hangcaption{Statistics of parallel corpora we applied, i.e., average length difference (Diff), variance (VAR), and the Pearson correlation (Corr) between the source target sentences, and their average lengths. All lengths are based on subwords using SentencePiece.}
\label{corpusdata}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

For the output length prediction, we used a pre-trained language model such as BERT \cite{DBLP:journals/corr/abs-1810-04805}.
The length prediction model uses the CLS vector in the last layer of the encoder of the pre-trained model to predict the output length through an output layer as a regression problem.
The predicted output length is used as the length constraint in the LDPE-based NMT decoder during inference.
Note that the perturbation is not applied.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Experiments}

To investigate the performance of the proposed method, we conducted several translation experiments using the baseline Transformer and length-constrained variants, including the proposed method.
All models were implemented using OpenNMT \cite{klein-etal-2017-opennmt}.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Dataset}

For the experiments, we used ASPEC English-Japanese \cite{NAKAZAWA16.621} and WMT14 English-German \cite{bojar-EtAl:2014:W14-33}, as shown in Table \ref{corpusdata}. We investigated the translation in both directions, that is, En-Ja, Ja-En, En-De, and De-En.
From the ASPEC dataset, we used the first 1 million sentence pairs of the training set along with 1,784 and 1,812 sentence pairs for the development and test sets, respectively.
For the WMT14 dataset, we used a pre-processed dataset distributed by the Stanford NLP group.\footnote{\url{https://nlp.stanford.edu/projects/nmt/}} 
It consists of 4.4 million sentence pairs for training, whose lengths are within 50 words.
We chose newstest2013 (3,000 sentence pairs) and newstest 2014 (2,737 sentences) for the development and test sets, respectively.
All sentences were tokenized into subwords using a SentencePiece model \cite{kudo-richardson-2018-sentencepiece} with a shared subword vocabulary of 16,000 entries in ASPEC and 30,000 entries in WMT14.
Throughout the experiments, we used subword-based lengths in the training and inference.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Setup}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Translation}
\label{hyperparameter}

For the ASPEC En-Ja and Ja-En experiments, we used the hyperparameter settings in OpenNMT-py FAQ\footnote{\url{https://opennmt.net/OpenNMT-py/FAQ.html#how-do-i-use-the-transformer-model}, we show the detailed hyperparameter settings in the appendix.} for all compared methods.
For the WMT14 En-De and De-En experiments, the hyperparameter settings were the same as those in the literature \cite{NIPS2017_7181}.

In the experiments using the standard Transformer, we conducted five independent training runs with different random seeds and chose the best runs and training epochs in the development set to determine the final evaluation models. 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Length Prediction} 

We implemented length prediction models using BERT variants included in HuggingFace Transformers \cite{Wolf2019HuggingFacesTS}, as shown in Table \ref{pretrainmodel}.

Each length prediction model was trained using the source language sentences in the corresponding training set for three epochs, with a mini-batch size of 16 sentences and the Adam optimizer ($learning\_rate$ = 1e-5).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 2
\begin{table}[t]
\input{02table02.tex}
\caption{Pre-trained model used for length prediction in translation experiments}
\label{pretrainmodel}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Evaluation Metrics}

We used BLEU \cite{papineni-etal-2002-bleu} as our main quality evaluation metric.
We also investigated the length ratio (LR) of the output and reference sentences ($LR = tgt\_len/ref\_len$).
In the English-to-Japanese translation, BLEU was calculated using {\tt multi-bleu.perl} on the translation results re-tokenized by applying MeCab \cite{10019716933} after subword detokenization.
In the other translation directions, BLEU was calculated using sacreBLEU \cite{post-2018-call}.

We also calculated the variance of the length difference between the translation results and the references to investigate the effects of the output length constraints, following \cite{takase-okazaki-2019-positional}.
The variance (VAR) on the $n$ sentence pairs is calculated as follows:
\begin{equation}
VAR = \frac{1}{n}\sum_{i=1}^{n}{|l_i - ref\_len_i|}^{2}
\end{equation}
where $ref\_len_i$ is the reference length and $l_i$ is the output length of the $i$-th sentence.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Compared Methods}

We compared the proposed method with other methods during the training and inference.
\subsubsection{Training}
The baseline was a Transformer model consisting of $n\_heads$ = 8 with a standard PE, as shown in Eq.~(\ref{eqn:pe}).
For the proposed method, we compared perturbation range training of different lengths:
no perturbation (i.e., $[0,0]$), and $[-2,2]$, $[-4,4]$, $[-6,6]$, and $[-8,8]$.
The latter two ranges were used only in the WMT14 experiments because of the large variance in length in the training data.
In experiments using the standard Transformer, we conducted five independent training runs with different random seeds and chose the best runs and training epochs in the development set to determine the final evaluation models. 
In experiments using the proposed method, we also chose the best perturbation range in the development set with each length constraint, and then evaluated the perturbated model.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Inference}

We compared three inference-time length constraints:
the predicted length from a simple prediction formula ($ratio\_train$), the length predicted by the proposed length prediction model ($pred\_len$), and the proxy by the input length ($src\_len$).
The $ratio\_train$ formula is given as follows:
\begin{equation}
ratio\_train = src\_len_{test} × \frac{1}{n_{train}}\sum_{i=1}^{n_{train}}{src\_len_{train} / ref\_len_{train}}
\end{equation}

In addition, we attempted two other variants of the output length prediction during the WMT14 experiments, i.e., a prediction of the length difference and the ratio between the input and output ($diff\_pred$ and $ratio\_pred$, respectively) using the same model architecture as $pred\_len$.

We also tested the reference (oracle) lengths ($ref\_len$) to investigate the upper-bound performance using the proposed method.
Note that we did not use the length class tokens used by \citeA{lakew_iwslt19} because our aim was not to control the output length to be shorter or longer.

For the comparison method, we used the BP-norm \cite{yang-etal-2018-breaking} as the length constraint method.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Results}

Tables \ref{bleu11} and \ref{bleu22} show the results in terms of BLEU, length ratio, and variance on ASPEC and WMT14, respectively.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 3
\begin{table}[t]
\input{02table03.tex}
\hangcaption{%
Results in BLEU, length ratio (LR), and length difference variance (VAR) on the ASPEC dataset: {\bf bold} represents better BLEU scores than those of the Transformer when applying the proposed method. BLEU scores with \underline{underlines} represent those that are better than the baseline Transformer in oracle length constraints.}
\label{bleu11}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{BLEU}

Herein, we focus on the BLEU results among the different methods.

First, we discuss the BLEU results using the length prediction.
In ASPEC English-to-Japanese translation, the proposed method with $ratio\_train$ or $pred\_len$ resulted in a slightly better BLEU score (38.6, 38.8) than the baseline Transformer (38.4).
These results are also shown in ASPEC Japanese-to-English translation.
Nevertheless, the difference was not statistically significant in the bootstrap resampling test \cite{koehn-2004-statistical}.
In the WMT14 German-to-English translation, the proposed method using $ratio\_train$, $diff\_pred$ or $ratio\_pred$ slightly improved the BLEU score (31.3, 30.7, or 30.2); by contrast, the baseline BLEU score of Transformer was 30.1.
However, the BLEU scores decreased with $pred\_len$ constraints.
Consequently, this was due to length prediction errors, as discussed in Section \ref{length_prediction_section}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 4
\begin{table}[t]
\input{02table04.tex}
\hangcaption{%
Results of BLEU, length ratio (LR), and length difference variance (VAR) on the WMT14 dataset: {\bf bold} represents BLEU scores better than those of the Transformer when applying the proposed method. BLEU scores with \underline{underlines} represent those that are better than the baseline Transformer in oracle length constraints.}
\label{bleu22}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Next, we focus on the BLEU differences between the use of the length prediction and the proxy by the input length.
In the ASPEC experiments, the proxy by the input length ($src\_len$) resulted in much worse BLEU scores than the length prediction.
By contrast, in the WMT14 German-to-English translation, the use of the input length resulted in a better BLEU score than the baseline (30.1 versus 31.1).
This is because the variance between the input and output lengths was small in the WMT14 test set, as shown in the VAR column in Table \ref{corpusdata}. 
We discuss this issue in detail in Section \ref{length_prediction_section}.

Finally, we discuss the results using the oracle length constraints in comparison with the reference lengths ($ref\_len$).
Better BLEU scores were shown than those of the proposed method with a length prediction.
In WMT14 German-English, the BLEU result was better than the baseline.

Compared with the BP-norm method, our method was the most accurate during the ASPEC experiments.
When using the oracle length ($ref\_len$), our method significantly improved the BLEU score, whereas the BP-norm method slightly improved the BLEU score.
This tendency was almost the same during the WMT14 experiments. 
However, the BP-norm method was the most accurate during the WMT14 German-to-English experiment.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Variance in Length Difference}

The variances in the length difference show that LDPE induced outputs closer to the references than the baseline Transformer in most cases.
Compared with the BP-norm, the variance of the proposed method changes significantly according to the length constraint.
However, the variance of the BP norm does not change significantly depending on the length constraint.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Length Prediction Accuracy}
\label{length_prediction_section}

Table \ref{predict_result0} shows the average difference, variances in the length difference, and the Pearson correlation coefficients between the predicted output lengths and the reference lengths.
From Table \ref{corpusdata}, the mean error was 6.54, the variance was 72.45, and the Pearson correlation was 0.90 between the reference and the source in the ASPEC English-Japanese test set.
The variance of the predicted length ($pred\_len$) was much smaller than the input length (19.92 versus 72.45 in English-to-Japanese, and 37.16 versus 72.45 in Japanese-to-English), and the translation accuracy was improved in the English-to-Japanese and Japanese-to-English translations.
The variance of the simple predicted length ($ratio\_train$) was also smaller than the input length (28.12 versus 72.45 in English-to-Japanese, 41.38 versus 72.45 in Japanese-to-English).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 5
\begin{table}[t]
\input{02table05.tex}
\hangcaption{Average token difference, variance, and Pearson correlation coefficient between the predicted and reference lengths, and between the source and reference lengths (in the number of tokens) in the test set}
\label{predict_result0}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

However, the variance in the WMT14 experiments was much larger than that during the ASPEC experiments.
From Table \ref{corpusdata}, the WMT14 datasets have extremely different length ratios for the training, dev, and test sets.
Therefore, the accuracy of length prediction was poor, which is not a general tendency and is not a language problem.
We can see that the source length worked better than all predicted lengths,
which is why the accuracy of the translation improved when the input length was compared to the predicted length during the WMT14 experiments.
We cannot reveal the reason for the poor length prediction during the WMT14 experiments and reserve this problem for future studies.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Detailed Results in Different Length Ranges}

We further investigated the ASPEC English-to-Japanese results with different group lengths to investigate the effects of perturbations on the length-aware PE
because the length constraints are expected to have a larger impact on shorter sentences, and vice versa.
Note that we excluded the longest length group, which exceeded 80 tokens, because it included three sentences and serious errors in length.
As shown in Table \ref{bleu_tgtlentestset}, the proposed method with a perturbation range of $[-2,2]$ significantly outperformed the baseline Transformer by 3.22 points (50.81 versus 47.59) for BLEU
in the shortest length group with one to ten tokens.
The other setups showed better BLEU results than the baseline, although the differences were not statistically significant.
As another clear finding, the baseline Transformer generated extremely short translation results for long sentences, as shown in the rightmost column, and LDPE resulted in longer outputs.
This finding is helpful for avoiding under-translation problems in NMT.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 6
\begin{table}[t]
\input{02table06.tex}
\hangcaption{%
Detailed results in different length ranges based on number of tokens in reference sentences in ASPEC English-to-Japanese: BLEU values in {\bf bold} outperformed the baseline, and * shows statistically significant difference from the baseline Transformer.}
\label{bleu_tgtlentestset}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Discussion}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Impact of Perturbation Range Size on Translation Accuracy}

We investigated the extent to which the proposed perturbation in length-aware PE can compensate for length prediction errors.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{BLEU}
Tables 7 and 8 show the BLEU, length ratio, and variance on the ASPEC and WMT14 datasets.
In translations using the ASPEC dataset, the proposed method improved the translation accuracy as the perturbation range increased.
However, in a German-to-English translation, the translation accuracy reached its upper limit within a specific perturbation range (for example, a perturbation range of [$-4$,4] (using $ratio\_train$ as the length constraints), [$-6$,6] ($pred\_len$), or [$-6$,6] ($diff\_pred$)), and the translation accuracy decreased when the perturbation range was increased further.
The proposed method improved the translation accuracy as the perturbation range increased in the English-to-German translation but did not outperform the baseline Transformer.
This was also the case with the oracle length constraints ($ref\_len$).
It was occasionally better than the results of the non-perturbed LDPE, which suggests that the perturbation complements the inaccurate length prediction.
This feature suggests that the proposed perturbation complements the slightly inaccurate length prediction.
However, it was insufficient to compensate for the loss if the length prediction error exceeded the perturbation range.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 7
\begin{table}[t]
\input{02table07.tex}
\hangcaption{All perturbation range results for BLEU, length ratio (LR), and variance (VAR) on the ASPEC dataset.}
\label{bleu1}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 8
\begin{table}[p]
\input{02table08.tex}
\hangcaption{All perturbation range results for BLEU, length ratio (LR), and variance (VAR) on the WMT14 dataset.}
\label{bleu2}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Variance in Length Difference }
Although a wider perturbation range increased the variances when we used the oracle length constraints, the results using the predicted and proxy input lengths were mixed.
In the ASPEC experiments, no perturbation LDPE with the oracle length ($ref\_len$) showed extremely small length differences.
This clearly shows that the LDPE successfully controlled the output length.
During the WMT14 experiments, the variances in length error became larger using a larger perturbation range when we used the output length prediction ($pred\_len$ or $ratio\_pred$); however, this was not the case with the use of the input length or the simple predicted length ($src\_len$ or $ratio\_train$).
This suggests that the proposed perturbations in the length-aware PE improved the robustness of the variances in length. 

By contrast, during the WMT14 experiments, some length differences still remained, even with the oracle length constraints.
The relationship between the perturbation range and the variance in the length difference differed from that during the ASPEC experiments.
We discuss this issue later in Section \ref{length_control}.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Influence by Different Subword Tokenization Strategies}
\label{length_control}

During the WMT14 experiments, the NMT model with no perturbation LDPE failed to constrain the output length to within the given length constraints.
One possible concern here is that the token-level sentence length varies with the tokenization method, even if the sentence itself holds the same content.
We investigated the effects of the tokenization method by changing the maximum subword length in the subword tokenization using Sentencepiece \cite{kudo-richardson-2018-sentencepiece}.
Because we used its default maximum subword length (\texttt{--max\_sentencepiece\_length}) of 16 characters during the experiments in Section 5, we attempted lengths of 4 and 8 for the WMT14 dataset to simulate a finer tokenization, resulting in longer token-level lengths.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 9
\begin{table}[b]
\input{02table09.tex}
\hangcaption{BLEU, length ratio (LR), and variance (VAR) results with no perturbation LDPE. All models obtain the correct inference length during the inference steps.}
\label{maxsentencepice}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Table \ref{maxsentencepice} shows the results based on the use of the oracle length constraints, and Figure \ref{wmt14spmspm} shows scatterplots between the MT output and the reference lengths.
Although we can observe differences in the variance in Table \ref{maxsentencepice}, we can also see that the errors are derived from only a couple of outliers, as shown in Figure \ref{wmt14spmspm}. 
Thus, we can conclude that length-aware PE can control the output length in most cases, even if we cannot reveal the reason for such outliers.
From the viewpoint of translation accuracy, BLEU decreases as $max\_sentencepiece\_length$ decreases.
The extremely large decrease in BLEU by $spmlen=4$ was due to a serious repetition in the translation results.
Thus, although we can conclude that the control of the output length is unaffected by the tokenization strategies, it is insufficient to maintain the translation quality.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% fig. 2
\begin{figure}[t]
\begin{center}
\includegraphics{28-3ia2f2.pdf}
\end{center}
\hangcaption{Scatter plot of the output length of each model with no perturbation LDPE during WMT14 translation. All models obtain the correct inference length during the inference steps.}
\label{wmt14spmspm}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Conclusion}

In this study, we proposed a method for training the Transformer model using perturbations in the length-aware PE.
We incorporated random perturbations within a certain range in LDPE during the training.
For inference, we used a length prediction based on a pre-trained model instead of applying the input length.
The proposed method outperformed a standard Transformer in ASPEC English-to-Japanese, Japanese-to-English, and WMT14 German-to-English translations.
We also revealed that the accuracy of the length prediction largely affected the final translation performance for BLEU.
In a future study, we will explore sophisticated length constraints along with a better length prediction method.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\acknowledgment

This paper is an extended version of the manuscript published in the Proceedings of the 28th International Conference on Computational Linguistics \cite{oka-etal-2020-incorporating},
with a further investigation into perturbation length-aware positional encoding and length prediction, and additional experiments conducted on WMT14 English-German.
Part of this work was supported by JSPS KAKENHI (Grant Number JP17H06101).
We would like to thank Katsuki Chousa for his insightful suggestions in an early phase of this work, and Seitaro Shinagawa and Ryo Fukuda for useful discussions.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\bibliographystyle{jnlpbbl_1.6}
\bibliography{02refs}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\appendix
%%%%\renewcommand{\thesection}{\Alph{section}}

\section{The Dataset Histgram}

We drew a histogram of the sentence lengths (training and testing), as shown in Fig.~3.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Fig. 3
\begin{figure}[h]
\includegraphics{28-3ia2f3.pdf} 
\caption{Histogram of sentence lengths in ASPEC En-Ja and WMT14 En-De}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Experimental Details}

We list the Open-NMT FAQ model hyperparameters in Table \ref{hy}.
The Adam optimizer \cite{kingma2014method} is applied using $\beta_{1} = 0.9$ and $\beta_{2} = 0.998$.
The label smoothing is 0.1, the $warmup\_steps$ is 8000,
the batch size is 4096, and 200,000 training steps are used.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 10
\begin{table}[h]
\input{02table10.tex}
\caption{ Hyper-parameters of architecture for Transformer from Open-NMT FAQ.}
\label{hy}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The 1-gram Precision Results}

We show the 1-gram precision results in Tables 11 and 12.
The 1-gram precision results are similar to the BLEU results.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 11
\begin{table}[h]
\input{02table11.tex}
\hangcaption{%
Results for BLEU, 1-gram, length ratio (LR), and variance (VAR) in length error on the ASPEC dataset: {\bf bold} indicates better BLEU scores than those of the Transformer when applying the proposed method. BLEU scores with an \underline{underline} are better than the baseline Transformer in terms of the oracle length constraints.}
\label{bleu111}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% table 12
\begin{table}[h]
\input{02table12.tex}
\hangcaption{%
Results of BLEU, 1-gram, length ratio (LR), and variance (VAR) in length error on the WMT14 dataset: BLEU scores in {\bf bold} are better than those of the Transformer when applying the proposed method. BLEU scores with an \underline{underline} are better than those of the baseline Transformer in terms of the oracle length constraints.}
\label{bleu222}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\vspace{-2\Cvs}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{biography}

\bioauthor[:]{Yui Oka}{%
is a member of the Linguistic Intelligence Research Group at Innovative Communication Laboratory, NTT Laboratories.
She received her MS in engineering in 2021 from the Nara Institute of Science and Technology.
}
\bioauthor[:]{Katsuhito Sudoh}{%
is an associate professor at Nara Institute of Science and Technology.
He received his MS degree and PhD in informatics from Kyoto University in 2002 and 2015, respectively.
He worked in NTT from 2002 to 2017. He is a member of ANLP, IPSJ, ASJ, JSAI, and ACL.
}
\bioauthor[:]{Satoshi Nakamura}{%
is a professor at Nara Institute of Science and Technology. He received his PhD from Kyoto University in 1992. He was Director of ATR SLC Labs and Director General of Keihanna Labs, NICT until 2010. He is a Fellow of ATR, IPSJ, ISCA, and IEEE.
}
\end{biography}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\biodate




\end{document}

