# Declarative, generic definition and effective implementation of transfer learning algorithms

Tayeb Diab, Mohamed Graiet, Mario Südholt

► To cite this version:

Tayeb Diab, Mohamed Graiet, Mario Südholt. Declarative, generic definition and effective implementation of transfer learning algorithms. AIAI 2025 - 21st International Conference on Artificial Intelligence Applications and Innovations, Jun 2025, Limassol, Cyprus. pp.1-14. hal-05005665

HAL Id: hal-05005665

https://hal.science/hal-05005665v3

Submitted on 7 Apr 2025

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Declarative, generic definition and effective implementation of transfer learning algorithms*†

Tayeb Diab¹, Mohamed Graiet², Mario Südholt³

¹University of Mascara; Mascara, Algeria

²Higher Inst. of CS and Math. of Monastir (ISIMM); Monastir, Tunisia

³STACK team; IMT Atlantique, LS2N, Inria, Orange; Nantes, France

April 2025

## Abstract

Machine learning, especially deep learning, has become essential in many application domains. However, deep learning relies on artificial neural networks that often face resource-related limitations. For instance, data is often proprietary, model training can be costly, and using these models may be constrained by limited computational or storage resources. Transfer learning offers a solution to overcome these constraints by "transferring" a model from a source domain to a target domain, potentially in a different context. This transfer takes various forms: models can be adapted with minor structural changes (e.g., "fine-tuning"), reduced in size (e.g., "knowledge distillation"), or retrained with modified training and testing datasets (e.g., "domain adaptation").

This paper first motivates the need for a generic definitional framework and implementation support for transfer learning through a literature review. We then introduce Generic Transfer Learning (GTL), our proposal of such a framework. GTL supports the declarative definition of transfers through network transformations and dataset manipulations and includes corresponding Python implementation support. We finally present a case study demonstrating how to define and implement a transfer using GTL in the health domain.

**Keywords:** Machine learning, deep learning, neural network, transfer learning

## 1 INTRODUCTION

Machine Learning [1], more particularly deep learning, has become a cornerstone in numerous application domains today. Deep learning relies on artificial neural networks (ANNs) that are widely used in various machine learning methods, including supervised learning algorithms using Convolutional Neural Networks and Recurrent Neural Networks, as well as unsupervised learning using autoencoders and Generative Adversarial Networks. ANNs are typically structured in terms of sequences of layers, comprising neurons interconnected

*Author version; accepted at the 21st Int. Conf. on Artificial Intelligence Applications and Innovations, IFIP, Chypre, June 2025; copyright: Springer

†This work has been funded partially through the French 2030 projects SPIREC (ANR-23-PECL-0006) and OTPaaS (BPIfrance).
in various ways, including full and reduction interconnection strategies for implementing
sampling and polling strategies. Trained with massive datasets, these networks infer new
properties, e.g., through data classification or generation of new data.

However, deep learning [2] (DL) faces significant resource-related challenges that can severely restrict its applicability in certain contexts. Three key limitations are particularly noteworthy: (i) data often remains proprietary, hindering model development for many users; (ii) the size of models and associated resource requirements for storage, training, and deployment may be prohibitive for some users; (iii) models developed on powerful cloud servers may not be usable on resource-limited edge and IoT infrastructures.

Transfer Learning [3] (TL) promises a solution to some of these challenges by transferring
knowledge represented by a model for a source domain to a target domain. Transfers en-
compass various approaches, from minor structural adjustments (e.g., fine-tuning a model),
to large modifications like model reduction for knowledge distillation [4], or retraining the
model on a different dataset.

TL is subject to, in particular, *three major problems*. First, the lack of a standardized notational framework leads to a varying and partially incompatible terminology used to describe TL algorithms. Parameters, for instance, most frequently designate the weights of a network that are optimized during training. However, some articles also include biases or even normalizing layers of Convolutional Neural Networks (CNNs) in the set of parameters. Second, the absence of a common definitional framework often leads to imprecise and difficult-to-understand TL definitions in research papers. Third, the lack of general implementation support frequently results in ad hoc TL implementations using standard DL frameworks.

All of these issues often result in complex and difficult-to-understand definitions and implementations of transfer algorithms. This trend has also motivated the quest for new programming abstractions and even programming languages, such as the recently proposed Bend and Mojo languages that strive to simplify AI programming beyond standard AI frameworks, such as TensorFlow or Keras. Similarly, we are striving for new abstractions for transfer learning.

To address these issues, we introduce *Generic Transfer Learning (GTL)*, an approach
providing a unified notational and definitional framework for TL over neural networks,
along with corresponding general implementation support.

Concretely, we provide four contributions:

1. A motivation of current issues in the definition and implementation of TL through an analysis of a set of representative articles on transfer learning.

2. A set of basic modifiers that form a unified vocabulary for the precise description of transfers and a corresponding language to concisely and declaratively define and program TL methods.

3. A corresponding Python-based framework for implementing transfers.

4. A definition and evaluation of a case study of GTL in the context of an existing application of TL to Malaria cell identification.

The paper is organized as follows: Section 2 motivates our approach by analyzing various representative state-of-the-art TL methods. Section 3 presents a precisely-defined GTL framework, followed by its implementation in Section 4. A use-case demonstrating the efficacy of GTL is presented in Section 5. Finally, Section 6 concludes the paper.
# 2 MOTIVATION AND RELATED WORK

The following two subsections discuss recent advancements in TL methodologies. Since we are interested in general mechanisms for the modeling and implementation of TL methods, we focus on studies that strive to generalize TL approaches or to provide means for the construction of TL methods.

## 2.1 Generalizing TL

Almost all existing TL approaches that explicitly present some concept of *generic* TL, notably [5, 6, 7, 8, 9, 10], propose solutions that exhibit a generic nature within *only* one application context that results in one TL method, which is still specific. In contrast, in our approach, *generic* TL refers to a much more general approach: the provision of general declarative notations to define and implement network and data transformations for a wide range of different TL methods.

Intriguingly, Long et al. [11] propose a "generalization" of TL methods based on the integration of two objective functions: the maximization of empirical likelihood and the preservation of geometric structure, into a unified optimization problem. However, their approach ultimately results in only one, once again specific, TL method, contrasting with our proposed method.

## 2.2 Constructive TL

Analyzing the literature on transfer learning, it turns out that TL approaches are essentially defined in one of two ways. A few articles (see in particular [3]) provide general, typically mathematical, constraints on the neural networks and the associated functions (activation, loss, etc.) that determine how a learning approach is defined or transformed: these approaches typically define transfers in an implicit and non-constructive manner. The second, much larger body of work (see e.g., [12, 13, 14, 15, 16, 17, 18, 19]) consists in using constructive approaches to define how model structures and behavioral parameters of learning methods are modified by transfers. This method is often used, in particular, by approaches that employ transfer learning for concrete applications. In the following we present an analysis of this body of work, whose constructive techniques we strive to generalize.

Table 1 presents the TL algorithms used by a set of approaches published in major venues. We have found these approaches to be representative to the much larger set of approaches we have investigated: the larger set of approaches use the same mechanisms and, in particular, the operators that we present here. The table offers an informal description of each approach and details the steps employed for the implementation of the corresponding transfer. In the table, $Ml_s$ and $Ml_t$ denote, respectively, the source and target machine learning methods, ie., the model and associated data used. Note that the level of precision (or rather imprecision) of the definition of the transfers is comparable to that found in most of the corresponding publications.
<table><caption>Table 1: TL applications and their implementations</caption><thead><tr><td>Ref.</td><td>Title</td><td>Description</td><td>Implementation</td></tr></thead><tbody><tr><td>[12]</td><td>Transfer learning with ResNet-50 for malaria cell-image classification</td><td>- Mls: ResNet50 model trained on public data.<br/>- Mlt: model classifying the cell-images on infected or non infected with Malaria parasite.<br/>- Principle: changing the model structure and behavior parameters.</td><td>- Freeze all model layers<br/>- Delete the last layer<br/>- Add a fully-connected layer with 2 neurons at the end<br/>- Define the output activation function as "sigmoid"<br/>- Randomly initialize the last layer<br/>- Define the optimizer as "SGD"<br/>- Define the loss function as "CCE"<br/>- Retrain the model with malaria data</td></tr><tr><td>[13]</td><td>Learning and transferring mid-level image representations using convolutional neural networks</td><td>- Mls: model pre-trained on ImageNet dataset.<br/>- Mlt: model classifying Pascal VOC data.<br/>- Principle: changing the model structure and behavior parameters and increasing target data size.</td><td>- Replace the last layer with 2 layers randomly initialized<br/>- Increase the size of two layers from 4096 to 6144 neurons.<br/>- Freeze first 5 convolution layers and 2 fully-connected layers<br/>- Unfreeze last 2 fully-connected layers<br/>- Use sliding window strategy to increase data<br/>- Retrain the model using the target data and new data</td></tr><tr><td>[14]</td><td>FedHealth: A Federated Transfer Learning Framework for Wearable Healthcare</td><td>- Mls: model trained on public dataset (cloud).<br/>- Mlt: model classifying patients healthcare data.<br/>- Principle: Changing the model behavior parameters.</td><td>- Freeze n layers<br/>- Unfreeze others (m)<br/>- Change the objective function to the sum of two standard loss functions and 'lCORAL' function<br/>- Define the learning rate as 0.01<br/>- Define optimization function as "SGD"<br/>- Retrain the model using the target dataset</td></tr><tr><td>[15]</td><td>Deep convolutional neural networks for computer-aided detection: CNN architectures, dataset characteristics and transfer learning</td><td>- Mls: model pre-trained on ImageNet dataset.<br/>- Mlt: model classifying medical images.<br/>- Principle: changing the model behavior parameters.</td><td>- Unfreeze all l layers except the last one<br/>- Fine-tune all layers with learning rate 10 times smaller than default<br/>- Replace the output layer with a fully-connected layer providing the number of intended target classes<br/>- Retrain the model with target data</td></tr><tr><td>[16]</td><td>How transferable are features in deep neural networks?</td><td>- Mls: model pre-trained on half of ImageNet data.<br/>- Mlt: model classifying the 2<sup>nd</sup> half of ImageNet.<br/>- Principle: Change the behavior parameters.</td><td>Two TL methods:<br/>a) Freeze first n layers and randomly initialize others (m)<br/>b) Unfreeze all layers and randomly initialize others (m)<br/>Then:<br/>- Retrain the network using target data</td></tr></tbody></table>
# 3 GENERIC TRANSFER LEARNING (GTL) METHOD

We have motivated above that TL approaches are typically defined in terms of modifications to the structure or behavior of networks, or the datasets used for training, testing or validation.

The main point of our work is to provide general support for the definition of transfers in terms of *precisely-defined modifiers* that enable their declarative and concise expression and implementation. In this section, we introduce our set of modifiers for TL and a corresponding framework for the precise definition of TL methods.

## 3.1 Learning method modifiers

We first introduce three sets of modifiers for the definition of transfers and illustrate how several transfers can be expressed using them.

We propose to formulate TL algorithms in terms of sequences of instructions that modify the source model and/or the training/test/validation data. An instruction is expressed in terms of modifiers that change elements of the model or dataset, for example, weight modifications, removing layers, and adding new training data.

Following our analysis of TL approaches in the previous section, we propose *three classes of modifiers*: model modifiers, data set modifiers and retraining modifiers. Our set of modifiers comprises those explicitly used in the related work we analyzed in addition to some other modifiers that we have found to be useful to express transfers.

### 3.1.1 Model modifiers

Model modifiers are operations that modify the source model in two different ways, structurally or behaviorally. Table 2 introduces the corresponding set of modifiers, providing, for each modifier, an identifier, its informal meaning and several reference articles that have used the modifier. The last field may indicate "Proposed" which means that this modifier is useful for some transfer definition but has not been used in the set of articles we have analyzed.

**Structure modifiers** Modifiers of this class modify the structural elements such as the number of layers and neurons per layer. A huge number of transfer learning algorithms use this kind of operations.

For instance, Oquab et al. [13] aim to reuse layers trained on the ImageNet dataset to compute mid-level image representation for images in the PASCAL VOC dataset. Among the modification operations, they replace the last layer of the model with two layers, which can respectively be performed using the (-l) and (+l) modifiers we propose. After that, they retrain the model with the PASCAL VOC dataset, which can be expressed using our *rt* modifier (see Table 4).

**Behavior modifiers** Behavior modifiers include operations that change the behavior of the model during and after the retraining process. Notably, the freezing layers *fzl* modifier (in Table 2) blocks the modification of pre-trained weights and unfreezing (*ufzl*) enables modification during model retraining (*rt* in Table 4).
<table><thead><tr><th colspan="3">Structure modifiers</th></tr><tr><th>Modifier</th><th>Meaning (informal)</th><th>Refs</th></tr></thead><tbody><tr><td><b>+l</b></td><td>Add a layer or a list of layers at a specific position (layer index) in the model</td><td>[13], [15], [12]</td></tr><tr><td><b>-l</b></td><td>Delete a layer or a list of layers related to the given position(s)</td><td>[13], [15], [12]</td></tr><tr><td><b>+n</b></td><td>Add a neuron or a list of neurons at a specific position in the model. Neuron position is defined by a layer index and a neuron index within this layer</td><td>[13]</td></tr><tr><td><b>-n</b></td><td>Delete a neuron or a list of neurons related to the given position(s)</td><td>Proposed</td></tr></tbody></table>

<table><caption>Table 2: Model modifiers</caption><thead><tr><th colspan="3">Behavior modifiers</th></tr><tr><th>Modifier</th><th>Meaning (informal)</th><th>Refs</th></tr></thead><tbody><tr><td><b>il</b></td><td>Randomly initialize weights of a specific layer or a list of layers (by position(s))</td><td>[16], [12]</td></tr><tr><td><b>fzl</b></td><td>Freeze weights of a specific layer or a list of layers (by position(s))</td><td>[14], [13], [16], [12]</td></tr><tr><td><b>ufzl</b></td><td>Unfreeze weights (ie., use the pre-trained weights) of a specific layer or a list of layers (by position(s))</td><td>[14], [13], [16], [15]</td></tr><tr><td><b>in</b></td><td>Randomly initialize weights of a specific neuron or a list of neurons (by position(s))</td><td>Proposed</td></tr><tr><td><b>*A</b></td><td>Modify the network activation function of the model</td><td>Proposed</td></tr><tr><td><b>*G</b></td><td>Modify the output layer activation function of the model</td><td>[12]</td></tr></tbody></table>

<table><caption>Table 3: Dataset modifiers</caption><thead><tr><th colspan="3">Dataset modifiers</th></tr><tr><th>Modifier</th><th>Meaning (informal)</th><th>Refs</th></tr></thead><tbody><tr><td><b>aind</b></td><td>Add a set of data to the input data set to use it to retrain the modified model</td><td>[13]</td></tr><tr><td><b>ssd</b></td><td>Select a subset of the source data (from the source domain)</td><td>Proposed</td></tr><tr><td><b>std</b></td><td>Select a subset of the target data (from the target domain)</td><td>Proposed</td></tr></tbody></table>
<table><caption>Table 4: Retraining modifiers</caption><thead><tr><th colspan="3">Retraining modifiers</th></tr><tr><th>Modifier</th><th>Meaning (informal)</th><th>Refs</th></tr></thead><tbody><tr><td><strong><em>dfl</em></strong></td><td>Define the loss (objective) function</td><td>[14]</td></tr><tr><td><strong><em>dfo</em></strong></td><td>Define the optimization function</td><td>[12]</td></tr><tr><td><strong><em>dfr</em></strong></td><td>Define the model regularization function</td><td>Proposed</td></tr><tr><td><strong><em>dfα</em></strong></td><td>Define the learning rate α</td><td>[15]</td></tr><tr><td><strong><em>rt</em></strong></td><td>Retrain the modified model</td><td>[14], [13], [16], [15], [12]</td></tr></tbody></table>

Fine-tuning techniques are typically defined using these modifiers. Yosinsky et al. [16], for example, present a TL approach based on a (typical) fine-tuning technique where network retraining can be expressed using these three modifiers. They perform the fine-tuning process multiple times while changing the number of frozen layers in the network. Similarly, Shin et al. [15] use a fine-tuning technique where all CNN layers are fine-tuned except the last fully-connected layer that is randomly initialized and freshly trained: this approach can be formulated using the *il* and *rt* modifiers, respectively.

### 3.1.2 Data modifiers

Modifier s in this category are applied to datasets during the TL process. Such modifiers can enlarge the source dataset or select a subset of a dataset for the retraining process (see Table 3).

Oquab et al. [13], e.g., use, in addition to the structure modifiers discussed above, the *aind* modifier to increase the source data size by employing a sliding window strategy to extract around 500 square patches from the original dataset and add them to the input data set for retraining.

### 3.1.3 Retraining modifiers

This category of modifiers enables the modification of the model retraining process parameters. These modifiers are also frequently used to define fine-tuning techniques. After the execution of model and/or data modifiers, retraining modifiers are applied to update the default parameters of retraining. These parameters include the loss and optimization functions and learning rate. The complete list of retraining modifiers is shown in Table 4.

Chen et al. [14], e.g., propose a TL technique based on the loss function of correlation alignment $l_{CORAL}$. The idea of this technique is to fine-tune the source model using a set of modifiers, mainly, defining a new objective function (as can be done using the *dfl*) that is the sum of the two loss functions of the source and target domains and an L2-SP based regularization $l_{CORAL}$ function.

Reddy and Juliet [12] use TL for Malaria cell-image classification. They define a set of operations to modify the ResNet50 model then retrain it using the Malaria cell-image dataset. They use two modifiers, namely *dfo* to change the optimization function during the retraining process and, the model modifier *\*G*, that changes the output activation function of the model.
<figure><img src="image_2.png" /><figcaption>Figure 1: Overview of the GTL method</figcaption></figure>

## 3.2 The GTL method

Beyond the analysis of TL approaches in terms of modifiers our second goal is to define a generic approach to declaratively define and implement a large range of TL approaches.

We introduce Generic Transfer Learning (GTL) that embodies such an approach. GTL allows for the definition of TL configurations that feature modifier-based transfer expressions.

Fig. 1 provides an overview of the GTL system: a source model along with source data are transformed, based on (transfer) configurations into a target model and updated target data that are used for training and validation. The updated target data may be constructed from elements of the source data, the original target data and other new external data.

Intuitively, GTL configurations come in two forms: typically, TL algorithms are expressed in structured, declarative ways using modifier compositions. In order to support arbitrary TL algorithms, we also support transfers expressed using general Python programs.

### 3.2.1 Definitional framework

GTL (see Def. 1) defines a TL approach as a transformation of an input learning method into an output method ($Ml_{in} \to Ml_{out}$) that is parameterized by a general machine learning type $MlT$ and a specific configuration $Cf$.

**Definition 1 (GTL).** The Generic Transfer Learning method is a function of the following type:

$$GTL: MlT \to Cf \to Ml_{in} \to Ml_{out}$$

where $MlT$ is a machine learning type, $Cf$ a transfer learning onfiguration; $Ml_{in}/Ml_{out}$: are input/output machine learning method (i.e., two pairs of model and dataset)

The parameters of a GTL definition are the following:

$$ \begin{aligned} MlT &= \sup | \text{unsup} \\ Cf &= [C | P] \\ C &= \text{mf} | \text{mf} \circ C \\ P &= \epsilon | \text{PythonProg} | \text{pyrep}(C) | P[P] \end{aligned} $$

The first parameter (machine learning type $MlT$) differentiates major categories of ML methods (model and data) used during transfer learning. In this paper we consider two learning method categories:

* **sup** - supervised learning: labels are associated to target data, so that the network training can be improved by comparing the expected labels with the computed ones.
* unsup - unsupervised learning: does not support a priori target labels. Currently, the GTL tool supports unsupervised learning using autoencoders which are neural networks used to learn a compact representation of data by reducing its dimensionality.

The configurations Cf are the core concept for TL definitions. They are defined as sequences $[C | P]$ consisting of (declarative) modifier compositions C or (turing-complete) Python programs P.

A modifier composition consists of a single modifier mf (cf. the previous section and Def. 2) or a composition of modifiers mf ◦ C.

Transfer programs P may be empty $\epsilon$, may consist of arbitrary Python programs PythonProg. Here PythonProg is a non-terminal that permits the derivation, of arbitrary Python programs. and may also include (Python representations of) modifier compositions C. Such compositions may be embedded in standard Python programs by means of contextual expressions with holes $P[\cdot]$, where · denotes a "hole" (notation well-known in the field of programming language semantics) in a program P that may be filled.

Besides the machine learning type and TL configuration, GTL requires a third argument: the input method $Ml_{in}$, a pair grouping the source model $M_{in}$ and source dataset $Dt_{in}$.

### 3.2.2 Semantics of learning method modifiers

We are now in the position to precisely define the learning method modifiers that have been introduced in Tables 2, 3 and 4. Overall, this provides GTL with a firm semantic grounding and GTL-based transfers with precise definitions, in contrast to almost all existing transfer methods defined in the literature.

**Definition 2 (Modifier).** A modifier mf of a ML method is a function of type :

$$Ml \rightarrow Arg \rightarrow Ml$$

A modifier mf transforms a ML method $Ml = (M, D)$, a pair of a model and dataset, using modifier-specific arguments Arg into a result method.

The sets of modifiers presented in Sec. 2 have been chosen in order to form a domain-specific language (DSL) for the definition of transfers that is intuitive and easy-to-use. The corpus of articles used to derive the proposed DSL was selected based on a review of major venues in machine learning and transfer learning research. We have focused on work that explicitly define transfer learning mechanisms, introduce generalizable frameworks, or propose modifications applicable across multiple domains.

Figure 2 shows a formal definition of three fundamental learning method transformers, that is how they modify the structure, behavior and data sets of ML methods in terms of standard operations of discrete mathematics. For instance, the **layerT** transformation allows structural changes such as adding or removing layers, while **freezeT** modifies trainable parameters by freezing or unfreezing selected layers. The **dataT** transformation, on the other hand, supports dataset augmentation and selection strategies used in domain adaptation. These transformers can be straightforwardly used to define our transfer modifiers precisely.

In Fig. 2, the models m of the input learning methods $M = (m, d)$ are represented as lists of layers (e.g., $[l_i]_{1 \le i \le n}$).

The layer transformer **layerT**($M$)($ls, s, e$) modifies the layer structure of m to

$$([l_j | 1 \le j < s] + ls + [l_k | e \le k \le n])$$
<table><caption>Figure 2: Definition of three learning method transformers</caption><thead><tr><th>Transformer</th><th>Definition</th><th></th></tr></thead><tbody><tr><td>layerT(M)(ls, s, e)</td><td>([l<sub>j</sub>|1 &le; j &lt; s] + ls + [l<sub>k</sub>|e &le; k &le; n], d)</td><td>; M = ([l<sub>i</sub>]<sub>1&le;i&le;n</sub>, d)</td></tr><tr><td>freezeT(M)(l, f)</td><td>l = ([n<sub>k</sub>], not f)</td><td>; M = (l = [l<sub>i</sub>]<sub>1&le;i&le;n</sub>, d), l<sub>j</sub> &isin; l, l<sub>j</sub> = ([n<sub>k</sub>], f)</td></tr><tr><td>dataT(M)(d')</td><td>(m, (d &cup; d') - (d &cap; d'))</td><td>; M = (m, d)</td></tr></tbody></table>

and provides a unified definition for the addition, removal and replacement of layers, because the layer list *ls* may replace or not some existing layers depending on the values of positions *s* to *e*. As an example, **layerT(M)**([*l*<sub>*n*</sub>], 1, 4) replaces the layers no. 2 and 3 of *M* by the new layer *l*<sub>*n*</sub>.

Layer un/freezing is defined by the transformer **freezeT(M)**(*l*, *f*) which states that the freezing state *f* of one of the layers *l*<sub>*j*</sub> is flipped, i.e., changed to **not** *f*.

The data modification operation **dataT(M)**(*d*) permits to add new elements from a set *d'* to a given set *d* and eliminate, at the same time, elements from *d* that also exist in *d'* using standard set theoretic operations: $(d \cup d') - (d \cap d')$

# 4 GTL IMPLEMENTATION

In addition to a definitional framework, we have also implemented the GTL software tool and library that enable the concise and declarative implementation of a large range of transfer learning approaches for deep neural networks.

GTL is provided in the form of a Python library built using the **Keras** (2.15.0) and **Tensorflow** (2.15.0) frameworks.

## 4.1 GTL architecture

Fig. 3 presents the architecture of GTL. A *user-defined GTL expression* defines the TL configuration which is parsed (step 1 in the figure) into an internal representation that uses modifier expressions to define transfers (step 2). GTL expressions are formulated using a simple DSL that enables the programming of sequences of terms that define the transfer modifiers (see Tables 2, 3 and 4). Each modifier in the

<figure><img src="image_3.png" /><figcaption>Figure 3: GTL architecture and process</figcaption></figure>

GTL expression is configured by a set of arguments. For example, the "Delete Layer" modifier (–l) allows the removal of a list of layers given as an argument. The expression *li*: "–l(*li* = [3, 6])" deletes the third and sixth layers from the model.

The GTL core component then applies this expression using its library of modifier implementations to first transform a potentially pre-trained input model and dataset. Note that the input data (step 3) may include not only the source data initially used to train the input model but also include other data, in particular, data from the target domain of the TL approach.
Finally, a *neural model* and a *dataset* for its training (and/or test, validation) is generated (step 4). The output dataset, i.e., the input dataset for the generated model, may consist of data from the source, target and external datasets.

## 4.2 GTL implementation

From a programming point of view, GTL consists of a set of classes and functions that enable the implementation of transfer learning algorithms between domains in a generic way. The main component of the GTL core consists of the classes implementing the learning method modifiers.

Fig. 4 shows an excerpt of the modifier class hierarchy. This hierarchy relies on two main super-classes: (i) **MLModifier**: the type of modifiers and (ii) **Operation**: the type of the operation to be executed on the model or data: creation (addition), deletion or modification of model or data elements.

<figure><img src="image_4.png" /><figcaption>Figure 4: GTL Class Diagram</figcaption></figure>

GTL modifiers are grouped into three categories (that closely mimic those introduced in Sec. 2).

* **ModelModifier**: classes modifying the model at the level of structure and content (*LayerModifier*, e.g., permits to add/delete layers).

* **DataModifier**: classes modifying the training/test/validation dataset

* **RetrainingModifier**: classes modifying retraining parameters, such as loss functions (modifiable by **DefineLossFunction**) and optimization functions.

# 5 USE CASE: MALARIA CELL IDENTIFICATION

In this section, we present an application of GTL to a previously published transfer learning approach in the health domain. Reddy and Juliet [12] have shown how to use deep learning to identify malaria-infected human cells. They employ transfer learning to modify and optimize an existing ResNet50 model for malaria identification and retrain the generated model using the Malaria cell image dataset. Their TL process is detailed in the first row of Table 1.

Using GTL, the transfer method proposed by Reddy and Juliet can be defined using the expression in Figure 5 (comments explain modifier arguments).

By applying the modification operations defined in that GTL expression on the ResNet50 input model, we obtain exactly the same output model (same structure and number of parameters) as the output model of the original publication, see Figs. 6 and 7. Only the presentation of the models is slightly different.

Figures 8 and 9 show a comparison between the original method [12] and the GTL definition. As seen in the loss and accuracy figures, the two methods exhibit very similar
<figure><img src="image_5.png" /><figcaption>Figure 5: GTL expression for malaria cell identification</figcaption></figure>

<figure><img src="image_6.png" /><figcaption>Figure 6: Original output model [12]</figcaption></figure>

<figure><img src="image_7.png" /><figcaption>Figure 7: Output model using GTL</figcaption></figure>

<figure><img src="image_8.png" /><figcaption>Figure 8: Original results [12]</figcaption></figure>

<figure><img src="image_9.png" /><figcaption>Figure 9: Results using GTL</figcaption></figure>
behaviors. The concrete values are somewhat different over training especially during the first epochs due to several factors that are external to our control: (i) the learning rate has not been defined in the original publication [12]; (ii) the new added output layer (Dense) is randomly initialized in the two methods, and (iii) the difference in the order of images in the dataset used in the original paper (once again not specified) and our implementation.

Note that we can define all of these parameters in a concise and declarative fashion. We conclude by the observation that the GTL method defined this TL method in a precise and concise fashion, with reproducible execution results.

# 6 CONCLUSION

Transfer learning is highly beneficial for many machine learning tasks because it may overcome many challenges like limited computational and storage resources, as well as lack of publicly available data. However, current TL methods yield complex transfer strategies. Further, published transfer algorithms often use imprecisely-defined concepts, fail to defined important elements (hyperparameters, ...) and use algorithms defined in (often ambiguous) plain language.

In this paper, we have motivated the usefulness of a general definitional framework and provided a corresponding set of fundamental modifiers for learning methods that have been integrated into a domain-specific language for the precise and declarative definition of transfer methods. We have also provided a corresponding tool and Python library for the implementation of transfers. The effectiveness of the GTL method has been shown by a use case, a transfer used in a previous publication for malaria cell identification.

In the future, we aim to add modifiers for other transfer learning methods and to investigate how to ensure correctness properties of transfer learning.

# References

[1] T M Mitchell. *Machine Learning*. McGraw-Hill, New York, NY, USA, 1997.

[2] Y LeCun, Y Bengio, and G Hinton. Deep learning. *Nature*, 521(7553), 2015.

[3] S J Pan and Q Yang. A survey on transfer learning. *IEEE Transactions on knowledge and data engineering*, 22(10):1345-1359, 2010.

[4] G Hinton, O Vinyals, and J Dean. Distilling the knowledge in a neural network. *arXiv preprint arXiv:1503.02531*, 2015.

[5] K R Weiss et al. A survey of transfer learning. *J. Big Data*, 3:9, 2016.

[6] Yucheng L, Yanjuan G, Chenyun D, et al. A transfer learning based cross-subject generic model for continuous estimation of finger joint angles from a new user. *IEEE J. Biomed. Health Informatics*, 27(4):1914-1925, 2023.

[7] K. T. Chui, V. Arya, et al. Facilitating innovation and knowledge transfer between homogeneous and heterogeneous datasets. *J Innov. & Knowledge*, 8(2):100313, 2023.

[8] T Lu, F Yu, et al. A generic intelligent bearing fault diagnosis system using convolutional neural networks with transfer learning. *IEEE Access*, 8, 2020.
[9] Z Wang, X Liu, et al. A general deep transfer learning framework for predicting the flow field of airfoils with small data. *Computers & Fluids*, 251:105738, 2023.

[10] M Long, J Wang, et al. Adaptation regularization: A general framework for transfer learning. *IEEE Trans. Knowl. Data Eng.*, 26(5):1076-1089, 2014.

[11] M Long, J Wang, et al. Transfer learning with graph co-regularization. *IEEE Trans. Knowl. Data Eng.*, 26(7):1805-1818, 2014.

[12] A Reddy and D Juliet. Transfer learning with ResNet-50 for malaria cell-image classification. In *Int. Conf. on Commu. and Signal Proc. (ICCSP)*. IEEE, 2019.

[13] M Oquab, L Bottou, et al. Learning and transferring mid-level image representations using convolutional neural networks. In *Proceedings of the IEEE conference on computer vision and pattern recognition*, pages 1717-1724, 2014.

[14] Y Chen, X Qin, et al. Fedhealth: A federated transfer learning framework for wearable healthcare. *IEEE Intelligent Systems*, 35(4):83-93, 2020.

[15] H-C Shin, H R Roth, et al. Deep convolutional neural networks for computer-aided detection: Cnn architectures, dataset characteristics and transfer learning. *IEEE transactions on medical imaging*, 35(5):1285-1298, 2016.

[16] J Yosinski, J Clune, et al. How transferable are features in deep neural networks? *Advances in neural information processing systems*, 27, 2014.

[17] P Vakli et al. Transfer learning improves resting-state functional connectivity pattern analysis using convolutional neural networks. *Gigascience*, 7(12), 2018.

[18] N M Khan, N Abraham, and M Hon. Transfer learning with intelligent training data selection for prediction of alzheimer's disease. *IEEE Access*, 7, 2019.

[19] Y Gao, Y Zhang, H Wang, et al. Decoding behavior tasks from brain activity using deep transfer learning. *IEEE Access*, 7:43222-43232, 2019.