SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Bong Gyun Kang\*
HyunGi Kim
Dahuin Jung
Sungroh Yoon $^{1,2\dagger}$
$^{1}$  Interdisciplinary Program in Artificial Intelligence, Seoul National University
$^{2}$  Department of Electrical and Computer Engineering, Seoul National University
Continual learning (CL) aims to incrementally learn multiple tasks that are presented sequentially. The significance of CL lies not only in the practical importance but also in studying the learning mechanisms of humans who are excellent continual learners. While most research on CL has been done on structured data such as images, there is a lack of research on CL for abstract logical concepts such as counting, sorting, and arithmetic, which humans learn gradually over time in the real world. In this work, for the first time, we introduce novel algorithmic reasoning (AR) methodology for continual tasks of abstract concepts: CLeAR. Our methodology proposes a one-to-many mapping of input distribution to a shared mapping space, which allows the alignment of various tasks of different dimensions and shared semantics. Our tasks of abstract logical concepts, in the form of formal language, can be classified into Chomsky hierarchies based on their difficulty. In this study, we conducted extensive experiments consisting of 15 tasks with various levels of Chomsky hierarchy, ranging from in-hierarchy to inter-hierarchy scenarios. CLeAR not only achieved near zero forgetting but also improved accuracy during following tasks, a phenomenon known as backward transfer, while previous CL methods designed for image classification drastically failed.
From an early age, humans develop their ability to solve complex logical reasoning problems through lifelong learning. They gradually learn sequential cognitive skills, from basic counting methods to more advanced concepts such as addition, subtraction, and logical operations [2]. Although this sequential learning ability is inherent in humans, deep learning models experience catastrophic forgetting [30], where their performance on previous tasks rapidly declines, after learning a new task. Continual learning (CL) [6, 19] is essential not only for practical purposes but also for developing human-like artificial intelligence that can maintain its performance on previous tasks after learning new tasks. However, existing CL research has been limited to learning streams of structured data with fixed input formats, such as images, where each task involves the same classification task only with different image classes [47, 1, 48]. Current approaches fail to reflect the learning of abstract logical concepts that humans continuously acquire in the real world.
There are three major challenges in naively leveraging existing CL methodologies to continual algorithmic reasoning (AR) tasks. Firstly, in AR tasks, input data contain little information, and the input data and task are decorrelated (Fig. 1b). In traditional image CL, the inherent information in the image itself enables the model to estimate which task the image belongs to [18]. However, in CL for abstract concepts, the input data may be completely decorrelated from the task that the model needs
* luckypanda@snu.ac.kr • The code is available at https://github.com/Pusheen-cat/CLeAR_2023
† Corresponding author (sryoon@snu.ac.kr)
(a) Sequential Tasks of Learning Logics
(b) Input-Task Decorrelation
Figure 1: Introduction of continual learning on algorithmic reasoning (a) showing two representative continuous AR tasks and (b) showing an example of two tasks sharing identical input distribution.
to learn. For example, consider a binary input sequence consisting of 0's and 1's. In the first task, the model needs to determine whether the sum of the sequence is odd or even, while in the second task, it needs to determine the square root of the sequence when treated as a binary number. In this case, the input data distribution is identical for both tasks, thus it is impossible to correctly predict the task based on the input data. Therefore, CL for AR of abstract concepts is better suited to task incremental learning. Moreover, since the input data contains little information, learning data distribution (e.g. contrastive learning based CL) is inapplicable.
Secondly, the dimensions of the datasets of each task can be dynamic in the AR of abstract concepts. In current CL, data has mostly fixed shape and dimension (ex. height, weight, and channel  $H \times W \times C$ ) throughout the tasks [47, 1, 48]. However, ways of representing each "abstract logical concept" as the sequential input-output format are various [11, 26]. For example, when trying to train the model for modular arithmetic, there are various ways to introduce the concepts of numbers and operators to the model. Specifically, all used numbers and operators can be one-hot encoded numbers, and operators can be represented in different dimensions, or numbers can be represented in binary format. Furthermore, input sequences of different tasks result in different dimensions and lengths. Therefore, it is impossible to apply the same model directly to each task's data like the traditional image CL methodology, and additional operations adjusting the data shape are necessary.
Thirdly, the goal of generalization that the AR task aims to achieve is different. In traditional CL, the model learns the input data distribution itself, assuming that the train dataset and test dataset are identical and independently distributed (IID) [45]. However, in AR tasks, the model learns the general rule that generates labels from input distribution. To identify whether the model has appropriately learned to generate the correct answers rather than simply memorizing them, the test set is composed of out-of-distribution (OOD) data [33] that was never seen during training. Therefore, the goal of AR is not generalization performance for IID as in traditional CL, but generalization for OOD [14]. Due to these characteristics, the performance of replay-based CL methods that use a replay buffer to represent the input data distribution decreases. The core of the replay buffer is to extract representative samples or prototypes that can represent the input data distribution [5]. However, unlike a sharp-eared and long-tailed image that represents a cat class, “ $5+8=13$ ” cannot be considered as representative of the concept of arithmetic.
This work. We have developed a CL methodology that can be applied in the aforementioned scenario. We have applied a novel one-to-many mapping strategy to handle input data of different formats, and through this mapping, we have proposed ways to prevent forgetting previous tasks when learning new tasks, and even increased performance on previous tasks during the process of learning new tasks. We conducted extensive experiments on sequential models such as RNN, LSTM, and Tape RNN [12, 15, 17, 43, 11], which have memory, and used AR tasks with various levels of Chomsky hierarchy [11] to conduct extensive experiments on sequential tasks of the same level and different levels.
- We introduce the scenario of CL on AR for the first time. This scenario is of great importance as it is similar to how humans learn logical reasoning abilities incrementally in the real world and has very different characteristics from conventional CL scenarios as described above.
- We introduce new data mapping methods and CL algorithms that are applicable to the aforementioned scenario and have demonstrated high performance not only in catastrophic forgetting but also in knowledge transfer, which is one of the ultimate goals of CL.
- We demonstrated the superiority of our method over the existing CL methods in our proposed CL scenario for AR through extensive experiments on various combinations of AR tasks. We also showed that existing CL methods perform poorly due to the reasons described above.
Continual learning. CL is one of the long-standing challenges in deep learning [35], aiming to preserve the performance of previous tasks while effectively learning new tasks (without access to data from previous tasks) in situations where multiple tasks are learned sequentially. The existing CL methodologies can be broadly classified into three categories based on the methods used to prevent catastrophic forgetting [24]. First, regularization-based methods [19, 22, 21] constrain the model's important parameters for the previous task from changing when learning a new task. Elastic Weight Consolidation (EWC) [19] approximates the Fisher information matrix to learn a loss-minimizing weight space and regularizes the gradient direction to maintain the low loss for previous tasks. Learning without forgetting (LwF) [22] regularizes the loss through knowledge distillation by using the output of previous tasks as pseudo-labels during the learning of new tasks. Second, memory-based methods [5, 27, 4, 37] are further divided into experiment-replay and orthogonal projection methods. Experiment replay (ER) [5] stores small amounts of data from previous tasks in memory to use their information when learning new tasks. The performance of this method depends on the representative sample selected to capture the entire distribution of data. Orthogonal projection methods [27, 4] stores gradient and update weight in a direction orthogonal to the gradient from the previous task. Third, parameter isolation-based methods [39, 28, 40] use different parts of the model's parameters for each task. The parameters used in previous task learning are masked during the learning of the next task, and the model can also be extended as new tasks are introduced.
Knowledge Transfer. Recent CL models aim not only to prevent catastrophic forgetting of previous tasks but also to enhance the overall performance of the entire task by transferring common knowledge between tasks [24]. This is a property that humans, as excellent continual learners, naturally possess, allowing them to learn new tasks more easily from previous experiences and gain a deeper understanding of previously acquired knowledge as they learn new tasks. However, such knowledge transfer is not easy for deep learning models to obtain. Backward transfer refers to improving the performance of previously learned tasks by learning the current task, while forward transfer refers to previously learned tasks helping to learn a new task. Although there have been studies in this area [39, 25], knowledge backward transfer is still hard to achieve [46].
Algorithmic Reasoning. The core of human logical reasoning ability lies in inductive inference [20, 36]. This is the ability to derive general rules from finite examples and use them to infer the correct answers from unseen data. From the perspective of deep learning, this is AR [11, 23], where the model receives a finite number of input-output data and infers the underlying general rule to generate output for input sequences that have not been seen before. There has been much research on program induction [34, 23, 32, 31, 11], however, conventional approaches for serial AR have a critical limitation in that they require prior human knowledge about the task to pre-configure the model [29, 44, 13]. In general deep learning, the model learns through empirical risk minimization of statistical learning theory to achieve the theoretical bound of its performance and estimates the generalization error using test data [45]. An important assumption here is that the train and test data are independent and identically distributed (IID). However, in AR, where the model needs to learn general rules, this assumption is violated [11]. Therefore, in AR tasks, we have to measure the model's performance not only on the train data distribution but also on out-of-distribution (OOD) distribution [11].
Formal Language and Chomsky Hierarchy. Computational problems that generate output through learnable rules can be represented in formal language [41, 8, 38]. Formal language can be classified into hierarchies based on their complexity, which is known as the Chomsky hierarchy [3, 9]. The hierarchy ranges from regular language, which requires the lowest complexity of memory, context-free language, which requires stack-type memory, context-sensitive language, which requires linear tape memory, and recursively enumerable language, which requires infinite tape memory. Research has been conducted on whether various deep learning models can learn each level of formal language in this hierarchy [11, 12, 7]. Results have shown that there is a Chomsky hierarchy bound on the formal language that each deep learning model can learn, whereas models with external memory can learn languages of a high Chomsky hierarchy.
Problem Statement. Our goal is to train a fixed-size model that sequentially learns various abstract logical tasks, following a standard CL scenario. We assumed that predicting the output sequence corresponding to the input sequence, as in [11], is closer to real-world scenarios which are learned through inductive inference than inferring the internal state of automata, as in [26]. There are various methods of representing the same abstract logical concept into an input sequence that a model can understand. However, different forms of input can affect the performance of the model. Therefore, for fairness, we used the data format proposed in the previous paper [11].
In a CL scenario, a sequence of tasks  $\mathbb{T} = \{\text{task } t\}_{t=1}^{T}$  is given one after another. Each task  $t$  is given as a dataset  $\mathbb{D}_t = \left\{(\mathbf{x}_{t,i},\mathbf{y}_{t,i})\right\}_{i=1}^{S_t}$  with  $S_{t}$  sample pairs. Each pair of  $\mathbf{x}_{t,i},\mathbf{y}_{t,i}$  comes from  $\left\{\mathrm{One - hot}(L_{in}^t)\in \{0,1\}^{(|\sum_{in}^t|,l_{in}\leq N)},\mathrm{One - hot}(L_{out}^t)\in \{0,1\}^{(|\sum_{out}^t|,l_{out})}\right\}$ , where  $L_{in}^t\in \left\{\sum_{in}^t\right\}^{l_{in}\leq N}$  and  $L_{out}^t\in \left\{\sum_{out}^t\right\}^{l_{out}}$  is input and output language pair from task  $t$ .  $N$  is given as the input sequence length limit.  $\sum_{in}^t$  and  $\sum_{out}^t$  are corresponding alphabets.
Consider a sequence-to-sequence model  $f_{\theta}(\cdot)$  parameterized by fixed-sized  $\theta$ . To match different sized input  $\mathbf{x}_{t,i}$  of each task to model input, we require a task-wise mapping function  $m_t(\cdot)$ . Also, to project the model output vector to match different sized output  $\mathbf{y}_{t,i}$ , we applied task-wise linear projection head  $h_t(\cdot)$  which consists of a single layer perceptron. After learning a  $k$ -th task, the model is parameterized by  $\theta(k)$ , and the projection head becomes  $h_{t,k}(\cdot)$ .
During training, the model can only access data from the current task. And after training, to evaluate whether the model actually learned the general output sequence generation rule, the model is tested on OOD dataset  $\mathbb{D}_t^{test} = \{\left(\mathbf{x}_{t,i}^{test},\mathbf{y}_{t,i}^{test}\right)\}_{i = 1}^{S_t^{test}}$  which are created in the same method as train dataset from  $L_{in}^{t}\in \left\{\sum_{in}^{t}\right\}^{N < l_{in}\leq M}$  and its corresponding output sequence  $L_{out}^{t}\in \left\{\sum_{out}^{t}\right\}^{l_{out}}$ . After learning a  $k$ -th task, model performance on task  $t$  is measured using an average of per-sequence accuracy of test data, i.e.,  $\mathrm{ACC}_{k,t}^{test}$ .
$$
\mathrm {A C C} _ {k, t} ^ {t e s t} := \frac {1}{\boldsymbol {S} _ {t} ^ {t e s t}} \sum_ {i} A _ {t, i} ^ {k} (\boldsymbol {x}, \boldsymbol {y})
$$
$$
A _ {t, i} ^ {k} (\boldsymbol {x}, \boldsymbol {y}) := \frac {1}{| \boldsymbol {y} |} \sum_ {l} \mathbb {I} \left[ \left(\operatorname {a r g m a x} _ {j} \cdot \boldsymbol {y} _ {j l}\right) = \left(\operatorname {a r g m a x} _ {j} \cdot h _ {t} \left(p _ {\theta (k)} \left(m _ {t} (\boldsymbol {x}))\right)\right) _ {j l}\right) \right]
$$
Following [11], we set the maximum training input sequence length to be 40 ( $N = 40$ ) and sampled input sequence length from the uniform distribution  $\mathcal{U}(1, N)$ . OOD test set input sequence length was sampled from the uniform distribution  $\mathcal{U}(N + 1, M)$  where  $N = 40$  and  $M = 100$ .
Tasks. We conducted a comprehensive evaluation of CL on AR (CL-AR), involving 15 diverse logical reasoning tasks. These tasks exhibit various levels of complexity, resulting in different Chomsky hierarchies. Table 1 shows our AR tasks and the corresponding Chomsky hierarchy. The detailed information for each task is in Appendix A. We conducted three major CL scenarios. (a) High-correlation CL-AR scenario continually learns the same kind of task with varying difficulty. One example is the Modular Arithmetic task with increasing modular value enabling the model to access larger numbers. Another example is the Cycle Navigation task with increasing cycle length. This scenario allows us to interpret the model's behavior upon learning highly correlated reasoning tasks. (b) In-hierarchy CL-AR scenario continually learns various tasks of the same level of Chomsky hierarchy. This scenario allows us to analyze the interaction among tasks of different natures but with similar complexity. (c) Inter-hierarchy CL-AR scenario consists of tasks of different Chomsky hierarchies. This is by far the most challenging scenario for a neural network that has to manipulate its memory structure.
Models. Recently, there have been numerous quantitative studies on whether various architectures of neural networks can learn formal languages. In recent research, it has been shown that regardless of the increase in the number of training data, models have "hard limitations for scaling laws" and cannot learn generalization rules based on the complexity of the task and the inductive bias of the model. Furthermore, to learn high-level tasks, models with external memory are necessary, and the commonly used transformer model has demonstrated very limited AR performance. Therefore, in
Figure 2:  $m_t$  maps this input space to the entire mapping space, which is shared across all tasks. In order to map the entire space, mapping from the input space to the mapping space becomes one-to-many, making an arbitrary point in mapping space to be mapped from a valid input sequence for every task. Also, this mapping function ensures that the distribution of inputs from the input space becomes a uniform distribution in the mapping space.
this paper, we used RNN [12] and LSTM [15], as well as stack RNN [17] and tape RNN [43, 11] which have additional differentiable memory structures added to the standard RNN. The length of the external memory stack and tape in stack RNN and tape RNN was set to 40, and each element had 8 dimensions [11] and dimensions were doubled with CL of more than 5 tasks.
Evaluation Metrics. We adopt generalization accuracy as the basic evaluation metric. Final model accuracy (ACC) is the average accuracy of all tasks after learning all tasks as follows:
$$
\mathrm {A C C} = \frac {1}{T} \sum_ {t = 1} ^ {T} \mathrm {A C C} _ {T, t} ^ {\text {t e s t}} \tag {1}
$$
In order to evaluate not only the catastrophic forgetting but also the model's knowledge transfer capability, we introduced a metric that measures backward/forward knowledge transfer [42, 16]. Backward knowledge transfer (BWT) [27] indicates how much learning on the next tasks has influenced the performance of the previous task. BWT  $>0$  indicates that there has been a transfer of beneficial knowledge to the previous task during the CL process. Forward knowledge transfer (FWT) measures how helpful previously learned knowledge is when learning a new task. FWT is obtained by calculating the difference between the accuracy achieved in the CL scenario and the accuracy achieved by training an independent model (as Table 1). BWT and FWT are expressed as follows:
$$
\mathrm {B W T} = \frac {1}{T - 1} \sum_ {t = 1} ^ {T - 1} \mathrm {A C C} _ {T, t} ^ {\text {t e s t}} - \mathrm {A C C} _ {t, t} ^ {\text {t e s t}}, \quad \mathrm {F W T} = \frac {1}{T - 1} \sum_ {t = 1} ^ {T - 1} \mathrm {A C C} _ {t, t} ^ {\text {t e s t}} - \mathrm {A C C} _ {t} ^ {\text {t e s t}} \tag {2}
$$
CLeAR. We propose a novel CL algorithm for the CL-AR scenario: CLeAR. The CLeAR model is divided into two main parts. The first part is a mapping function  $m_{t}$  that maps sequences sampled from the input data distribution to a shared mapping space. The second part consists of the main model  $f_{\theta}(\cdot)$ , which learns labels from the features in the feature space, and the task-wise single-layer projection head  $h_{t}$ .
$m_{t}$  maps the input sequence sampled from the input space of task  $t$  to a feature space (mapping space), preserving length but changing dimension to fixed size  $D_{map}$ . The input sequence consists of binary values, denoted as  $\{0,1\}^{(D_{in}^t,l)}$ , and the range of the mapping space is expressed as  $\{0,1\}^{(D_{map},l)}$ . As described in Fig. 2,
Algorithm 1 CLeAR-training procedure for a given task t
Trained up to task t-1:  $m_{k},f_{\theta (t - 1)}$  and  $h_{k,t - 1}$ $(1\leq k <   t)$
Dataset of task t:  $\mathfrak{D}_t$
Train:
Train  $m_t$  with  $\mathfrak{D}_t$
$f_{\theta} = f_{\theta (t - 1)}$  and  $h_k = h_{k,t - 1}$ $(1\leq k <   t)$
Freeze  $f_{\theta (t - 1)},h_{k,t - 1}$ $(1\leq k <   t)$
Random initialize  $h_t$
for  $x_{t,i},y_{t,i}\sim \mathfrak{D}_t$  do{Pre-tuning with small samples}
$$
o _ {t, i} \leftarrow h _ {t} \cdot f _ {\theta (t - 1)} \cdot m _ {t} \left(\mathbf {x} _ {t, i}\right)
$$
$$
\mathcal {L} = \mathcal {L} _ {\text {n e w}} \left(o _ {t, i}, y _ {t, i}\right)
$$
Compute  $\nabla \mathcal{L}$  and update  $h_t$
for  $x_{t,i},y_{t,i}\sim \mathfrak{D}_t$  do{Main training}
$\hat{y}_{k,i}\gets \arg \max \cdot h_{k,t - 1}\cdot f_{\theta (t - 1)}\cdot m_t(\mathbf{x}_{t,i})$  for  $k = 1\dots t - 1$
$o_{k,i}\gets h_k\cdot f_\theta \cdot m_t(\mathbf{x}_{t,i})$  for  $k = 1\dots t$
$\mathcal{L} = \lambda \cdot \sum_{k = 1}^{t - 1}\mathcal{L}_{\mathrm{old}}(o_{k,i},\hat{y}_{k,i}) + \mathcal{L}_{\mathrm{new}}(o_{t,i},y_{k,i})$
Compute  $\vec{\nabla}\mathcal{L}$  and update  $f_{\theta},h_{k}$  for  $k = 1\dots t$
Trained up to task t:  $m_{k}$ $f_{\theta}$  and  $h_k$ $(1\leq k\leq t)$
Figure 3: Mapping function is trained using encoder-decoder architecture and under three constraints. First, input sequence is perfectly reconstructed. Second, each column of mapped sequence is decorrelated. Third, each column of mapped sequence has mean of 0.5.
our mapping function  $m_t$  has the following characteristics. First, an arbitrary sample from the input distribution is mapped to one or more points in the mapping space (one-to-many). Second, for any point in the mapping space, a corresponding sample exists in the input space. Third, the mapping of input distribution resembles uniform sampling in the mapping space:  $m_t(input distribution) \approx \mathcal{U}(\{0,1\}^{(D_{map},l)})$ . Therefore, the mapping function of each task expands the input distribution to fill the mapping space fully. Thus, an arbitrary sample drawn from the mapping space can correspond to a valid input sample for any task. This allows the model to consider a single sequence in the mapping space as valid input for each previous task. It is similar to how we can perceive the number 395 in various ways, such as being odd, multiple of 5, or having a sum of digits equal to 17. These mapping functions can be expressed very simply, requiring minimal computational resources in the overall model. Additional details about the mapping function, positional mapping, and specific mapping for each task are explained in Appendix C.
To create such mapping functions, an encoder-decoder structure is considered for tasks where the distribution of alphabets is preserved across all positions of the input language. As shown in Fig. 3, the encoder takes the input sequence sampled from the input space and additional random noise to generate a mapped sequence. Then, the decoder reconstructs the input sequence from the mapped sequence. In this process, each column of the mapped sequence should have a mean of 0.5 and should be decorrelated from each other. The encoder serves as the mapping function, and the decoder is discarded.