SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Shunya Minami
The Institute of Statistical Mathematics mshunya@ism.ac.jp
Yoshihiro Hayashi
The Institute of Statistical Mathematics  
yhayashi@ism.ac.jp
Kenji Fukumizu
The Institute of Statistical Mathematics fukumizu@ism.ac.jp
Ryo Yoshida
The Institute of Statistical Mathematics  
yoshidar@ism.ac.jp
Supervised transfer learning has received considerable attention due to its potential to boost the predictive power of machine learning in scenarios where data are scarce. Generally, a given set of source models and a dataset from a target domain are used to adapt the pre-trained models to a target domain by statistically learning domain shift and domain-specific factors. While such procedurally and intuitively plausible methods have achieved great success in a wide range of real-world applications, the lack of a theoretical basis hinders further methodological development. This paper presents a general class of transfer learning regression called affine model transfer, following the principle of expected-square loss minimization. It is shown that the affine model transfer broadly encompasses various existing methods, including the most common procedure based on neural feature extractors. Furthermore, the current paper clarifies theoretical properties of the affine model transfer such as generalization error and excess risk. Through several case studies, we demonstrate the practical benefits of modeling and estimating inter-domain commonality and domain-specific factors separately with the affine-type transfer models.
Transfer learning (TL) is a methodology to improve the predictive performance of machine learning in a target domain with limited data by reusing knowledge gained from training in related source domains. Its great potential has been demonstrated in various real-world problems, including computer vision [1, 2], natural language processing [3, 4], biology [5], and materials science [6, 7, 8]. Notably, most of the outstanding successes of TL to date have relied on the feature extraction ability of deep neural networks. For example, a conventional method reuses feature representations encoded in an intermediate layer of a pre-trained model as an input for the target task or uses samples from the target domain to fine-tune the parameters of the pre-trained source model [9]. While such methods are operationally plausible and intuitive, they lack methodological principles and remain theoretically unexplored in terms of their learning capability for limited data. This study develops a principled methodology generally applicable to various kinds of TL.
In this study, we focus on supervised TL settings. In particular, we deal with settings where, given feature representations obtained from training in the source domain, we use samples from the target domain to model and estimate the domain shift to the target. This procedure is called hypothesis transfer learning (HTL); several methods have been proposed, such as using a linear transformation function [10, 11] and considering a general class of continuous transformation functions [12]. If the transformation function appropriately captures the functional relationship between the source and target domains, only the domain-specific factors need to be additionally learned, which can be done efficiently even with a limited sample size. In other words, the performance of HTL depends strongly
on whether the transformation function appropriately represents the cross-domain shift. However, the general methodology for modeling and estimating such domain shifts has been less studied.
This study derives a theoretically optimal class of supervised TL that minimizes the expected  $\ell_2$  loss function of the HTL. The resulting function class takes the form of an affine coupling  $g_{1}(\pmb{f}_{s}) + g_{2}(\pmb{f}_{s})\cdot g_{3}(\pmb{x})$  of three functions  $g_{1},g_{2}$  and  $g_{3}$ , where the shift from a given source feature  $f_{s}$  to the target domain is represented by the functions  $g_{1}$  and  $g_{2}$ , and the domain-specific factors are represented by  $g_{3}(\pmb{x})$  for any given input  $\pmb{x}$ . These functions can be estimated simultaneously using conventional supervised learning algorithms such as kernel methods or deep neural networks. Hereafter, we refer to this framework as the affine model transfer. As described later, we can formulate a wide variety of TL algorithms within the affine model transfer, including the widely used neural feature extractors, offset and scale HTLs [10, 11, 12], and Bayesian TL [13]. We clarify theoretical properties of the affine model transfer such as generalization error and excess risk.
To summarize, the contributions of our study are as follows:
- The affine model transfer is proposed to adapt source features to the target domain by separately estimating cross-domain shift and domain-specific factors.
- The affine form is derived theoretically as an optimal class based on the squared loss for the target task.
- The affine model transfer encompasses several existing TL methods, including neural feature extraction. It can work with any type of source model, including non-machine learning models such as physical models as well as multiple source models.
- For each of the three functions  $g_{1}$ ,  $g_{2}$ , and  $g_{3}$ , we provide an efficient and stable estimation algorithm when modeled using the kernel method.
- Two theoretical properties of the affine transfer model are shown: the generalization and the excess risk bound.
With several applications, we compare the affine model transfer with other TL algorithms, discuss its strengths, and demonstrate the advantage of being able to estimate cross-domain shifts and domain-specific factors separately.
2 Transfer Learning via Transformation Function
2.1 Affine Model Transfer
This study considers regression problems with squared loss. We assume that the output of the target domain  $y \in \mathcal{V} \subset \mathbb{R}$  follows  $y = f_{t}(x) + \epsilon$ , where  $f_{t}: \mathcal{X} \to \mathbb{R}$  is the true model on the target domain, and the observation noise  $\epsilon$  has mean zero and variance  $\sigma^2$ . We are given  $n$  samples  $\{(x_i, y_i)\}_{i=1}^n \in (\mathcal{X} \times \mathcal{Y})^n$  from the target domain and the feature representation  $\pmb{f}_s(\pmb{x}) \in \mathcal{F}_s$  from one or more source domains. Typically,  $\pmb{f}_s$  is given as a vector, including the output of the source models, observed data in the source domains, or learned features in a pre-trained model, but it can also be a non-vector feature such as a tensor, graph, or text. Hereafter,  $\pmb{f}_s$  is referred to as the source features.
In this paper, we focus on transfer learning with variable transformations as proposed in [12]. For an illustration of the concept, consider the case where there exists a relationship between the true functions  $f_{s}^{*}(\pmb{x}) \in \mathbb{R}$  and  $f_{t}^{*}(\pmb{x}) \in \mathbb{R}$  such that  $f_{t}^{*}(\pmb{x}) = f_{s}^{*}(\pmb{x}) + \pmb{x}^{\top}\pmb{\theta}^{*}, \pmb{x} \in \mathbb{R}^{d}$  with an unknown parameter  $\pmb{\theta}^{*} \in \mathbb{R}^{d}$ . If  $f_{s}^{*}$  is non-smooth, a large number of training samples is needed to learn  $f_{t}^{*}$  directly. However, since the difference  $f_{t}^{*} - f_{s}^{*}$  is a linear function with respect to the unknown  $\pmb{\theta}^{*}$ , it can be learned with fewer samples if prior information about  $f_{s}^{*}$  is available. For example, a target model can be obtained by adding  $f_{s}$  to the model  $g$  trained for the intermediate variable  $z = y - f_{s}(x)$ .
The following is a slight generalization of TL procedure provided in [12]:
1. With the source features, perform a variable transformation of the observed outputs as  $z_{i} = \phi(y_{i}, \pmb{f}_{s}(\pmb{x}_{i}))$ , using the data transformation function  $\phi: \mathcal{Y} \times \mathcal{F}_{s} \to \mathbb{R}$ .
2. Train an intermediate model  $\hat{g}(\pmb{x})$  using the transformed sample set  $\{(x_i, z_i)\}_{i=1}^n$  to predict the transformed output  $z$  for any given  $\pmb{x}$ .
3. Obtain a target model  $\hat{f}_t(x) = \psi (\hat{g} (x),\pmb {f}_s(x))$  using the model transformation function  $\psi :$ $\mathbb{R}\times \mathcal{F}_s\to \mathcal{V}$  that combines  $\hat{g}$  and  $\pmb{f}_{s}$  to define a predictor.
In particular, [12] considers the case where the model transformation function is equal to the inverse of the data transformation function. We consider a more general case that eliminates this constraint.
The objective of step 1 is to identify a transformation  $\phi$  that maps the output variable  $y$  to the intermediate variable  $z$ , making the variable suitable for learning. In step 2, a predictive model for  $z$  is constructed. Since the data is limited in many TL setups, a simple model, such as a linear model, should be used as  $g$ . Step 3 is to transform the intermediate model  $g$  into a predictive model  $f_{t}$  for the original output  $y$ .
This class of TL includes several approaches proposed in previous studies. For example, [10, 11] proposed a learning algorithm consisting of linear data transformation and linear model transformation:  $\phi = y - \langle \pmb{\theta},\pmb{f}_s\rangle$  and  $\psi = g(\pmb {x}) + \langle \pmb {\theta},\pmb {f}_s\rangle$  with pre-defined weights  $\pmb{\theta}$ . In this case, factors unexplained by the linear combination of source features are learned with  $g$ , and the target output is predicted additively with the common factor  $\langle \pmb {\theta},\pmb {f}_s\rangle$  and the additionally learned  $g$ . In [13], it is shown that a type of Bayesian TL is equivalent to using the following transformation functions; for  $\mathcal{F}_s\subset \mathbb{R}$ $\phi = (y - \tau f_s) / (1 - \tau)$  and  $\psi = \rho g(\pmb {x}) + (1 - \rho)f_s$  with two varying hyperparameters  $\tau < 1$  and  $0\leq \rho \leq 1$ . This includes TL using density ratio estimation [14] and neural network-based fine-tuning as special cases when the two hyperparameters belong to specific regions.
The performance of this TL strongly depends on the design of the two transformation functions  $\phi$  and  $\psi$ . In the sequel, we theoretically derive the optimal form of transformation functions under the squared loss scenario. For simplicity, we denote the transformation functions as  $\phi_{f_s}(\cdot) = \phi (\cdot ,\pmb {f}_s)$  on  $\mathcal{V}$  and  $\psi_{f_s}(\cdot) = \psi (\cdot ,\pmb {f}_s)$  on  $\mathbb{R}$ . To derive the optimal class of  $\phi$  and  $\psi$ , note first that the TL procedure described above can be formulated in population as solving two successive least square problems;
$$
(i) g ^ {*} := \arg \min  _ {g} \mathbb {E} _ {p _ {t}} \| \phi_ {f _ {s}} (Y) - g (\boldsymbol {X}) \| ^ {2},
$$
$$
\left(i i\right) \min  _ {\psi} \mathbb {E} _ {p _ {t}} \| Y - \psi_ {f _ {s}} (g ^ {*} (\boldsymbol {X})) \| ^ {2}.
$$
Since the regression function that minimizes the mean squared error is the conditional mean, the first problem is solved by  $g_{\phi}^{*}(\pmb{x}) = \mathbb{E}[\phi_{f_s}(Y)|\pmb{X} = \pmb{x}]$ , which depends on  $\phi$ . We can thus consider the optimal transformation functions  $\phi$  and  $\psi$  by the following minimization:
$$
\min  _ {\psi , \phi} \mathbb {E} _ {p _ {t}} \| Y - \psi_ {f _ {s}} \left(g _ {\phi} ^ {*} (\boldsymbol {X})\right) \| ^ {2}. \tag {1}
$$
It is easy to see that Eq. (1) is equivalent to the following consistency condition:
$$
\psi_ {f _ {s}} \big (g _ {\phi} ^ {*} (\pmb {x}) \big) = \mathbb {E} _ {p _ {t}} [ Y | \pmb {X} = \pmb {x} ].
$$
From the above observation, we make three assumptions to derive the optimal form of  $\psi$  and  $\phi$ :
Assumption 2.1 (Differentiability). The data transformation function  $\phi$  is differentiable with respect to the first argument.
Assumption 2.2 (Invertibility). The model transformation function  $\psi$  is invertible with respect to the first argument, i.e., its inverse  $\psi_{fs}^{-1}$  exists.
Assumption 2.3 (Consistency). For any distribution on the target domain  $p_t(x, y)$ , and for all  $x \in \mathcal{X}$ ,
$$
\psi_ {f _ {s}} \left(g ^ {*} (\boldsymbol {x})\right) = \mathbb {E} _ {p _ {t}} [ Y | \boldsymbol {X} = \boldsymbol {x} ],
$$
where  $g^{*}(\pmb {x}) = \mathbb{E}_{p_{t}}[\phi_{f_{s}}(Y)|\pmb {X} = \pmb {x}]$
Assumption 2.2 is commonly used in most existing HTL settings, such as [10] and [12]. It assumes a one-to-one correspondence between the predictive value  $\hat{f}_t(\pmb{x})$  and the output of the intermediate model  $\hat{g}(\pmb{x})$ . If this assumption does not hold, then multiple values of  $\hat{g}$  correspond to the same predicted value  $\hat{f}_t$ , which is unnatural. Note that Assumption 2.3 corresponds to the unbiased condition of [12].
We now derive the properties that the optimal transformation functions must satisfy.
Theorem 2.4. Under Assumptions 2.1-2.3, the transformation functions  $\phi$  and  $\psi$  satisfy the following two properties:
$$
\left( \begin{array}{c} i \end{array} \right) \psi_ {f _ {s}} ^ {- 1} = \phi_ {f _ {s}}.
$$
$$
\left(i i\right) \quad \psi_ {f _ {s}} (g) = g _ {1} (\boldsymbol {f} _ {\boldsymbol {s}}) + g _ {2} (\boldsymbol {f} _ {\boldsymbol {s}}) \cdot g,
$$
where  $g_{1}$  and  $g_{2}$  are some functions.
The proof is given in Section D.1 in Supplementary Material. Despite not initially assuming that the two transformation functions are inverses, Theorem 2.4 implies they must indeed be inverses. Furthermore, the mean squared error is minimized when the data and model transformation functions are given by an affine transformation and its inverse, respectively. In summary, under the expected squared loss minimization with the HTL procedure, the optimal class for HTL model is expressed as follows:
$$
\mathcal {H} = \left\{\boldsymbol {x} \mapsto g _ {1} (\boldsymbol {f} _ {\boldsymbol {s}}) + g _ {2} (\boldsymbol {f} _ {\boldsymbol {s}}) g _ {3} (\boldsymbol {x}) \mid g _ {j} \in \mathcal {G} _ {j}, j = 1, 2, 3 \right\},
$$
where  $\mathcal{G}_1, \mathcal{G}_2$  and  $\mathcal{G}_3$  are the arbitrarily function classes. Here, each of  $g_1$  and  $g_2$  is modeled as a function of  $\pmb{f_s}$  that represents common factors across the source and target domains.  $g_3$  is modeled as a function of  $\pmb{x}$ , in order to capture the domain-specific factors unexplainable by the source features.
We have derived the optimal form of the transformation functions when the squared loss is employed. Even for general convex loss functions, (i) of Theorem 2.4 still holds. However, (ii) of Theorem 2.4 does not generally hold because the optimal transformation function depends on the loss function. Extensions to other losses are briefly discussed in Section A.1, but the establishment of a complete theory is a future work.
Here, the affine transformation is found to be optimal in terms of minimizing the mean squared error. We can also derive the same optimal function by minimizing the upper bound of the estimation error in the HTL procedure, as discussed in Section A.2.
One of key principles for the design of  $g_{1}$ ,  $g_{2}$ , and  $g_{3}$  is interpretability. In our model,  $g_{1}$  and  $g_{2}$  primarily facilitate knowledge transfer, while the estimated  $g_{3}$  is used to gain insight on domain-specific factors. For instance, in order to infer cross-domain differences, we could design  $g_{1}$  and  $g_{2}$  by the conventional neural feature extraction, and a simple, highly interpretable model such as a linear model could be used for  $g_{3}$ . Thus, observing the estimated regression coefficients in  $g_{3}$ , one can statistically infer which features of  $x$  are related to inter-domain differences. This advantage of the proposed method is demonstrated in Section 5.2 and Section B.3.
2.2 Relation to Existing Methods
The affine model transfer encompasses some existing TL procedures. For example, by setting  $g_{1}(\pmb{f}_{s}) = 0$  and  $g_{2}(\pmb{f}_{s}) = 1$ , the prediction model is estimated without using the source features, which corresponds to an ordinary direct learning, i.e., a learning scheme without transfer. Furthermore, various kinds of HTLs can be formulated by imposing constraints on  $g_{1}$  and  $g_{2}$ . In prior work, [10] employs a two-step procedure where the source features are combined with pre-defined weights, and then the auxiliary model is additionally learned for the residuals unexplainable by the source features. The affine model transfer can represent this HTL as a special case by setting  $g_{2} = 1$ . [12] uses the transformed output  $z_{i} = y_{i} / f_{s}$  with the output value  $f_{s} \in \mathbb{R}$  of a source model, and this cross-domain shift is then regressed onto  $x$  using a target dataset. This HTL corresponds to  $g_{1} = 0$  and  $g_{2} = f_{s}$ .
When a pre-trained source model is provided as a neural network, TL is usually performed with the intermediate layer as input to the model in the target domain. This is called a feature extractor or frozen featurizer and has been experimentally and theoretically proven to have strong transfer capability as the de facto standard for TL [9, 15]. The affine model transfer encompasses the neural feature extraction as a special subclass, which is equivalent to setting  $g_{2}(\pmb{f}_{s})g_{3}(\pmb{x}) = 0$ . A performance comparison of the affine model transfer with the neural feature extraction is presented in Section 5 and Section B.2. The relationships between these existing methods and the affine model transfer are illustrated in Figure 1 and Figure S.1
The affine model transfer can also be interpreted as generalizing the feature extraction by adding a product term  $g_{2}(f_{s})g_{3}(\pmb{x})$ . This additional term allows for the inclusion of unknown factors in the transferred model that are unexplainable by source features alone. Furthermore, this encourages the avoidance of a negative transfer, a phenomenon where prior learning experiences interfere with training in a new task. The usual TL based only on  $f_{s}$  attempts to explain and predict the data generation process in the target domain using only the source features. However, in the presence of domain-specific factors, a negative transfer can occur owing to a lack of descriptive power. The additional term compensates for this shortcoming. The comparison of behavior for the case with the non-relative source features is described in Section 5.1.
Figure 1: Architectures of (a) feature extraction, (b) HTL in [10], and (c) affine model transfer.
Algorithm 1 Block relaxation algorithm [19].
Initialize:  $a_0, b_0 \neq 0, c_0 \neq 0$
$$
\boldsymbol {a} _ {t + 1} = \arg \min  _ {\boldsymbol {a}} F (\boldsymbol {a}, \boldsymbol {b} _ {t}, \boldsymbol {c} _ {t})
$$
$$
\boldsymbol {b} _ {t + 1} = \arg \min  _ {\boldsymbol {b}} F (\boldsymbol {a} _ {t + 1}, \boldsymbol {b}, \boldsymbol {c} _ {t})
$$
$$
\boldsymbol {c} _ {t + 1} = \arg \min  _ {\boldsymbol {c}} F (\boldsymbol {a} _ {t + 1}, \boldsymbol {b} _ {t + 1}, \boldsymbol {c})
$$
The affine model transfer can be naturally expressed as an architecture of network networks. This architecture, called affine coupling layers, is widely used for invertible neural networks in flow-based generative modeling [16, 17]. Neural networks based on affine coupling layers have been proven to have universal approximation ability [18]. This implies that the affine transfer model has the potential to represent a wide range of function classes, despite its simple architecture based on the affine coupling of three functions.
3 Modeling and Estimation
In this section, we focus on using kernel methods for the affine transfer model and provide the estimation algorithm. Let  $\mathcal{H}_1, \mathcal{H}_2$  and  $\mathcal{H}_3$  be reproducing kernel Hilbert spaces (RKHSs) with positive-definite kernels  $k_1, k_2$  and  $k_3$ , which define the feature mappings  $\Phi_1: \mathcal{F}_s \to \mathcal{H}_1$ ,  $\Phi_2: \mathcal{F}_s \to \mathcal{H}_2$  and  $\Phi_3: \mathcal{X} \to \mathcal{H}_3$ , respectively. Denote  $\Phi_{1,i} = \Phi_1(\pmb{f}_s(\pmb{x}_i))$ ,  $\Phi_{2,i} = \Phi_2(\pmb{f}_s(\pmb{x}_i))$ ,  $\Phi_{3,i} = \Phi_3(\pmb{x}_i)$ . For the proposed model class, the  $\ell_2$ -regularized empirical risk with the squared loss is given as follows:
$$
F _ {\alpha , \beta , \gamma} = \frac {1}{n} \sum_ {i = 1} ^ {n} \left\{y _ {i} - \langle \alpha , \Phi_ {1, i} \rangle - \langle \beta , \Phi_ {2, i} \rangle \langle \gamma , \Phi_ {3, i} \rangle \right\} ^ {2} + \lambda_ {1} \| \alpha \| _ {\mathcal {H} _ {1}} ^ {2} + \lambda_ {2} \| \beta \| _ {\mathcal {H} _ {2}} ^ {2} + \lambda_ {3} \| \gamma \| _ {\mathcal {H} _ {3}} ^ {2}, \tag {2}
$$
where  $\lambda_1, \lambda_2, \lambda_3 \geq 0$  are hyperparameters for the regularization. According to the representer theorem, the minimizer of  $F_{\alpha, \beta, \gamma}$  with respect to the parameters  $\alpha \in \mathcal{H}_1$ ,  $\beta \in \mathcal{H}_2$ , and  $\gamma \in \mathcal{H}_3$  reduces to  $\alpha = \sum_{i=1}^{n} a_i \Phi_{1,i}, \beta = \sum_{i=1}^{n} b_i \Phi_{2,i}, \gamma = \sum_{i=1}^{n} c_i \Phi_{3,i}$ , with the  $n$ -dimensional unknown parameter vectors  $\pmb{a}, \pmb{b}, \pmb{c} \in \mathbb{R}^n$ . Substituting this expression into Eq. (2), we obtain the objective function as
$$
F _ {\alpha , \beta , \gamma} = \frac {1}{n} \| y - K _ {1} \boldsymbol {a} - \left(K _ {2} \boldsymbol {b}\right) \circ \left(K _ {3} \boldsymbol {c}\right) \| _ {2} ^ {2} + \lambda_ {1} \boldsymbol {a} ^ {\top} K _ {1} \boldsymbol {a} + \lambda_ {2} \boldsymbol {b} ^ {\top} K _ {2} \boldsymbol {b} + \lambda_ {3} \boldsymbol {c} ^ {\top} K _ {3} \boldsymbol {c} =: F (\boldsymbol {a}, \boldsymbol {b}, \boldsymbol {c}). \tag {3}
$$
Here, the symbol  $\circ$  denotes the Hadamard product.  $K_{I}$  is the Gram matrix associated with the kernel  $k_{I}$  for  $I\in \{1,2,3\}$ .  $k_{I}^{(i)} = [k_{I}(\pmb{x}_{i},\pmb{x}_{1})\dots k_{I}(\pmb{x}_{i},\pmb{x}_{n})]^{\top}$  denotes the  $i$ -th column of the Gram matrix. The  $n\times n$  matrix  $M^{(i)}$  is given by the tensor product  $M^{(i)} = k_2^{(i)}\otimes k_3^{(i)}$  of  $k_2^{(i)}$  and  $k_3^{(i)}$ .
Because the model is linear with respect to parameter  $a$  and bilinear for  $b$  and  $c$ , the optimization of Eq. (3) can be solved using well-established techniques for the low-rank tensor regression. In this study, we use the block relaxation algorithm [19] as described in Algorithm 1. It updates  $a, b$ , and  $c$  by repeatedly fixing two of the three parameters and minimizing the objective function for the remaining one. Fixing two parameters, the resulting subproblem can be solved analytically because the objective function is expressed in a quadratic form for the remaining parameter.
Algorithm 1 can be regarded as repeating the HTL procedure introduced in Section 2.1; alternately estimates the parameters  $(\pmb{a},\pmb{b})$  of the transformation function and the parameters  $c$  of the model for the given transformed data  $\{(x_i,z_i)\}_{i = 1}^n$ . The function  $F$  in Algorithm 1 is not jointly convex in general. However, when employing methods like kernel methods or generalized linear models, and fixing two parameters,  $F$  exhibits convexity with respect to the remaining parameter. According to [19], when each sub-minimization problem is convex, Algorithm 1 is guaranteed to converge to a stationary point. Furthermore, [19] showed that consistency and asymptotic normality hold for the alternating minimization algorithm.
In this section, we present two theoretical properties, the generalization bound and excess risk bound.
Let  $(\mathcal{Z}, P)$  be an arbitrary probability space, and  $\{z_i\}_{i=1}^n$  be independent random variables with distribution  $P$ . For a function  $f: \mathcal{Z} \to \mathbb{R}$ , let the expectation of  $f$  with respect to  $P$  and its empirical counterpart denote respectively by  $Pf = \mathbb{E}_Pf(z)$ ,  $P_nf = \frac{1}{n}\sum_{i=1}^n f(z_i)$ . We use a non-negative loss  $\ell(y, y')$  such that it is bounded from above by  $L > 0$  and for any fixed  $y' \in \mathcal{Y}$ ,  $y \mapsto \ell(y, y')$  is  $\mu_\ell$ -Lipschitz for some  $\mu_\ell > 0$ .
Recall that the function class proposed in this work is