Emergent Modularity in Pre-trained Transformers
Year: 2023

Abstract:
This work examines the presence of modularity in pre-trained Transformers, a feature commonly found in human brains and thought to be vital for general intelligence. In analogy to human brains, we consider two main characteristics of modularity: (1) functional specialization of neurons: we evaluate whether each neuron is mainly specialized in a certain function, and find that the answer is yes. (2) function-based neuron grouping: we explore finding a structure that groups neurons into modules by function, and each module works for its corresponding function. Given the enormous amount of possible structures, we focus on Mixture-of-Experts as a promising candidate, which partitions neurons into experts and usually activates different experts for different inputs. Experimental results show that there are functional experts, where clustered are the neurons specialized in a certain function. Moreover, perturbing the activations of functional experts significantly affects the corresponding function. Finally, we study how modularity emerges during pre-training, and find that the modular structure is stabilized at the early stage, which is faster than neuron stabilization. It suggests that Transformers first construct the modular structure and then learn fine-grained neuron functions. Our code and data are available at https://github.com/ THUNLP/modularity-analysis.

heading: 1 Introduction
text: Recently, pre-trained Transformers have shown the potential to achieve general intelligence (Brown et al., 2021; Fei et al., 2022; Reed et al., 2022; OpenAI, 2023; Bubeck et al., 2023), which encourages researchers to explore the analogy between
∗ Equal contribution † Corresponding authors
Transformers and human brains (Toneva and Wehbe, 2019; Caucheteux et al., 2021; Caucheteux and King, 2022; Goldstein et al., 2022). These works have shown that the behaviors of Transformers resemble those of human brains. Do the internal structures of Transformers also mirror those of human brains in order to achieve similar behaviors?
Neuroscientists have found that the structure of neuron organization in human brains follows a modular pattern (Bullmore and Sporns, 2009; Meunier et al., 2010), which has two main characteristics. (1) Functional specialization of neurons: each neuron is mainly specialized in a certain function. (2) Function-based neuron grouping: neurons with the same function are clustered in a local region, and each function relies on a specific region. In this work, we wonder whether Transformers also organize neurons in a modular way.
(Q1) Are neurons functionally specialized? The functional specialization of neurons is the basis of modularity. To this end, we propose a novel framework to analyze the functionality of neurons in Transformers. In this framework, we study three representative functions by a unified method, including semantic function (Scarlini et al., 2019a; Suau et al., 2020), knowledge function (Jiang et al., 2020; Dai et al., 2022), and task function (Wang et al., 2022b). Experimental results show that the neurons in pre-trained Transformers become much more specialized than those in randomly-initialized ones after self-supervised learning on large-scale corpora. Moreover, in pre-trained Transformers, there are several groups of neurons, each of which excels in a specific function.
(Q2) Is there a modular structure of neurons? In analogy to human brains, a modular structure should group neurons with the same function together as modules, and each module plays a crucial role in a specific function. Since there are
4066
thousands of neurons in a Transformer, it is impractical to iterate over all possible structures of neurons. We consider the grouping of Mixture-ofExperts (MoE) (Jacobs et al., 1991; Fedus et al., 2022) as a promising candidate, which gracefully partitions neurons into experts and is widely used in Transformers. Moreover, most MoE models are sparsely activated, which is similar to human brains. Specifically, we study two types of MoE models, pre-partitioned MoE (pre-MoE) and postpartitioned MoE (post-MoE). Pre-MoE refers to the model architectures that expand feedforward layers by MoE to improve model capacity before pretraining (Fedus et al., 2022). Post-MoE refers to the models that are converted from vanilla Transformers to their MoE version by partitioning feedforward layers into experts after pre-training (Zhang et al., 2022b). It provides a way to group neurons without changes in parameters and forward pass.
By studying the function distribution on experts, we find that both pre-MoE and post-MoE Transformers have a strong tendency to distribute the neurons excelling in a certain function concentratedly into some experts. Moreover, perturbing the activations of 3% of experts by function leads to performance close to random guessing, which is more significant than perturbing the same amount of individual neurons specialized in the function. Therefore, the MoE structure indeed reflects the modularity of pre-trained Transformers.
(Q3) How does modularity emerge during pretraining? By analyzing the pre-training process, we find that the functions of expert networks are stabilized to a large extent at the early stage (around 15% of the total training steps) for both pre-MoE and post-MoE Transformers, which is faster than the neuron stabilization (around 75% of the total steps). Our findings provide evidence for a coarseto-fine mechanism of pre-training, which first constructs the coarse modular structure and then learns fine-grained neuron functions.

heading: 2 Related Work
text: Interpreting Pre-trained Transformers. Although pre-trained Transformers have achieved great success in the field of NLP (Min et al., 2021; Bommasani et al., 2021), their inner working mechanism is still a black box. Researchers explore interpreting the pre-trained Transformers (Rogers et al., 2020) from different perspectives, such as hidden representations (Liu et al., 2019), attention matri-
ces (Voita et al., 2019; Clark et al., 2019b), and output distributions (Petroni et al., 2019). Among them, studying the behavior of a single neuron is an important branch (Radford et al., 2017; Sajjad et al., 2022; Bills et al., 2023), which is most related to our work. From the neurons in feedforward layers, researchers have found various encoded information such as concepts, facts, and task abilities (Suau et al., 2020; Dai et al., 2022; Wang et al., 2022b). In this work, we study how these neurons are organized to form a modular structure, which is a new interpretation perspective.
Modularity of Neural Networks. Modularity is a widespread property in complex systems, both artificial (Ballard, 1987; Baldwin et al., 2000) and biological (Von Dassow and Munro, 1999; Lorenz et al., 2011; Clune et al., 2013). Previous work mainly focuses on incorporating explicitly designed modules into neural networks (Andreas et al., 2016; Kirsch et al., 2018; Goyal et al., 2021). Recently, Hod et al. (2021); Csordás et al. (2021); Dobs et al. (2022) study whether standard neural networks become modular by themselves, and have discovered some naturally-emerging modular structures of CNNs and LSTMs. Compared to previous work, we extend the modular analysis to pre-trained Transformers, which are expected to be more complex w.r.t. architecture and to contain more knowledge.
Transformers with MoE. Sparse MoE is usually used to enlarge the model capacity of Transformers while keeping the computational efficiency (Lepikhin et al., 2021; Lewis et al., 2021; Fedus et al., 2022). Specifically, for a given input, MoE conditionally selects a subset of experts to process the input and then combines the outputs of these experts to generate the final output. Beyond computation efficiency, MoE is also used to implement modular Transformers (Gururangan et al., 2022; Zhang et al., 2022a; Pfeiffer et al., 2022; Wang et al., 2022a). These works explicitly design extra constraints during pre-training to ensure the modularization of expert networks. However, it is still unclear whether modular experts can emerge naturally in Transformers during pre-training.

heading: 3 Functionality Evaluation
text: In this section, we first introduce the definition of neurons and how to evaluate the functionality of neurons and experts. Then, we briefly introduce the evaluation setups, including the pre-trained models.
Neurons in Transformer. Following Dai et al. (2022); Wang et al. (2022b), we study the neurons in the feedforward networks (FFNs), which account for about two-thirds of Transformer parameters. Previous work has shown that there is rich information in FFNs (Suau et al., 2020; Geva et al., 2021, 2022; Dai et al., 2022; Wang et al., 2022b).
Specifically, the FFN is a two-layer MLP and computes the output by FFN(x) = WOσ(W Ix+ bI) + bO, where W I ∈ Rdff×d,WO ∈ Rd×dff are the weight matrices, bI ∈ Rdff , bO ∈ Rd are the bias vectors, d is the dimensions of input and output, dff is the dimensions of intermediate hidden states, and σ is the activation function. For simplicity, we discard the bias terms in the following part. For fine-grained analysis, we dissect the FFN into neurons and rewrite the FFN equation as
FFN(x) = dff∑
i=1
σ(W Ii,: · x)WO:,i, (1)
where W Ii,: and W O :,i are the i-th row and column of W I and WO, respectively. The FFN output is the sum of the outputs of all neurons. From this perspective, we define a neuron ni as a row vector W Ii,: and a column vector W O :,i . The neuron activation of ni is σ(W Ii,: · x). The number of neurons in an FFN is equal to the intermediate hidden dimension dff .
Sparse Mixture-of-experts in Transformer is a variant of FFN (Lepikhin et al., 2021), which significantly increases the model capacity by adding more parameters and keeps the computational cost affordable. In MoE layers, each expert is an FFN, and the output of the MoE layer is the weighted sum of the outputs of all experts. We can also define neurons of MoE as Equation 1. The neuron-based form of MoE is provided in Appendix A.1.
Predictivity for Functions. To comprehensively study the functions of neurons and experts, we cover three typical functions. For each function, we construct various sub-functions, each of which is a fine-grained version of the function. There are 576 sub-functions in total. Here we introduce the three functions and their sub-functions.
Semantic Function. Semantic function refers to the ability to understand the meaning of input texts. In this work, we focus on how neurons capture the patterns of word senses. We use a large-scale dataset with word-sense annotations, OneSec (Scarlini et al., 2019b), to construct binary classification data for semantic sub-functions. In OneSec, each
sentence has a keyword whose sense is annotated based on Wikipedia1. We first filter out the keywords that have more than one sense in the dataset and then randomly select 100 sentences for each sense. For each sense pair of a word, we construct a binary classification dataset by labeling the sentences with one sense as positive and the sentences with the other sense as negative. Finally, we have 529 semantic sub-functions, each of which is a binary classification problem to distinguish the two senses of a word. For experiments on Switch Transformer in Section 6, we randomly sample 100 semantic sub-functions for evaluation.
Knowledge Function. Knowledge function refers to the ability to memorize factual knowledge. In this work, we focus on the factual triples, which are used to construct knowledge graphs. We define a knowledge sub-function as a binary classification to identify whether a triple is correct. Specifically, we sample several triples from Wikidata as positive instances and randomly replace their head or tail entities to construct negative instances. We group these instances according to their relations and each relation has its corresponding knowledge subfunction. There are 39 knowledge sub-functions from T-REx (Elsahar et al., 2018; Elazar et al., 2021) and each sub-function has 400 instances.
Task Function. Task function refers to the ability to perform downstream tasks. Previous work has shown that training a small part of parameters in pre-trained Transformers can achieve comparable performance to full-parameter fine-tuning (Lester et al., 2021; Hu et al., 2022) so that Transformers are supposed to learn amounts of task knowledge from pre-training. In this work, we use several classification datasets. from GLUE (Wang et al., 2018), including SST-2 (Socher et al., 2013), QQP2, MNLI (Williams et al., 2018), CoLA (Warstadt et al., 2018), MRPC (Dolan and Brockett, 2005), RTE (Dagan et al., 2006), QNLI (Rajpurkar et al., 2016). There are 8 task sub-functions in total because MNLI is split into two binary classification tasks. To stimulate these sub-functions, we adopt the input templates provided by (Raffel et al., 2020) to improve neuron predictivity. For each label class, we randomly sample 1000 instances for evaluation if the number of instances under this class is larger than 1000.
Admittedly, coarse is our function classifica1https://en.wikipedia.org/ 2https://data.quora.com/
First-Quora-Dataset-Release-Question-Pairs
tion. It does not cover all functions learned by pre-trained Transformers, and there are interactions between each pair of functions so there is unavoidable overlap. However, we focus on a unified framework and concrete evaluation approach, and they can be easily generalized to other ways of function classification, meaning that our contribution is independent of function classification. Using this way of classification is simply due to its typicality.
To evaluate the ability of a neuron to capture the pattern of a sub-function, we compute the predictivity of the neuron activations for the sub-function. Following Suau et al. (2020); Wang et al. (2022b), we focus on the sub-functions that can be formulated as a binary classification problem.
We denote the dataset of a sub-function as D = {(si, yi)}|D|i=1, where si is the input sequence and yi ∈ {0, 1} is the label. Since the computation of FFNs is word-wise, we define the activation of the neuron nj of a sequence si as aij = maxxk∈si σ(W I j,: · xk), where si = {x1,x2, . . . ,xl} is the hidden states of si and l is the length of si. Then, we have the pairs of neuron activations and labels, Aj = {(aij , yi)}|D|i=1. Based on Aj , we compute the average precision (AP) (Zhu, 2004) of the neuron activations as the predictivity of the neuron nj . For each expert, we compute the average AP of all neurons in the expert as the predictivity of the expert for the sub-function. Please refer to Appendix A.2 for more details.
Evaluation Setups. We evaluate two kinds of MoE models, pre-partitioned MoE and postpartitioned MoE. (1) Pre-partitioned MoE expands feedforward layers by MoE before pretraining. Switch Transformer (Fedus et al., 2022) is a representative pre-MoE model. The architecture of Switch Transformer is similar to T5 (Raffel et al., 2020) except that Switch Transformer replaces FFNs in the even Transformer layer with MoE layers. (2) Post-partitioned MoE converts a pre-trained vanilla Transformer into its MoE model by partitioning FFNs into experts. Since Zhang et al. (2022b) show that vanilla Transformers have implicit MoE structures by discovering the inner correlation among neurons, we use the same method to MoEfy vanilla Transformers. Note that we only adopt MoEfication to provide a neuron grouping. We do not change any architecture, parameters, forward function (computing all neurons and then summing them up), etc, making the
MoE-fied T5 identical to the original T5. Due to the computational cost, we consider the Switch Transformer with 16 experts and use the same number of experts for the post-MoE models. Since the functionality evaluation does not involve decoding, we only compute the neuron and expert predictivities of the encoders. Besides, we focus on the neurons in MoE layers for Switch Transformer to facilitate the modular analysis in the following sections.

heading: 4 Functional Specialization of Neurons
text: In this section, we analyze the functional specialization of neurons. First, we compare the neuron predictivities of pre-trained models with those of randomly-initialized models at the layer level, which will present a general picture of neuron functions. Second, we study how functions distribute on neurons in each layer.
Neuron predictivities of different layers. At each layer, we compute the best predictivity of neurons for each sub-function and then calculate the average best predictivity among all sub-functions in each function. For comparisons, we also evaluate randomly-initialized models. We report the results in the left part of Figure 1.
From this figure, we have two observations. (1) The average best predictivities of pre-trained neurons are significantly higher than those of randomly-initialized neurons, indicating that the neurons have learned these functions from pretraining and the neurons with top-ranked predictivities indeed excel in corresponding sub-functions. (2) The best predictivity of the task function increases with the layer number while the best predictivities of the semantic and knowledge functions vary little across layers. It suggests that the task function may be more difficult than the semantic and knowledge functions so the higher layers are more suitable for learning the task function. Note that we evaluate the frozen pre-trained models on the tasks without fine-tuning or prompt-tuning and the pre-training data of Switch Transformer do not contain the tasks. Hence, we can exclude the possibility of optimization artifacts (Durrani et al., 2021), which may make the higher layers more related to the task function.
Distribution in each layer. We first identify the neurons with the top predictivity rankings for each sub-function as sub-functional neurons in each layer and then compute the overlap between
<latexit sha1_base64="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aJHeradIHR4=">AAACMXicbVDLSiNBFK32PT6jLgehMAi6Cd2SYVyKblz6igrpEG5XbkxhVXVTdVsNTa/8mtmOX+NO3PoNA1Mds/B1oOBwzr2cuifJlHQUhk/BxOTU9Mzs3I/5hcWl5ZXa6tqFS3MrsCVSldqrBBwqabBFkhReZRZBJwovk5vDyr+8Retkas5pmGFHw7WRfSmAvNStbcSE91Rsww4/u5MkBvzcgnH91Gq0ZbdWDxvhCPwricakzsY47tb+xb1U5BoNCQXOtaMwo04BlqRQWM7HucMMxA1cY9tTAxpdpxidUfItr/S4j/bPEB+p7zcK0M4NdeInNdDAffYq8TuvnVN/r1NIk+WERrwF9XPFKeVVJ7wnLQpSQ09AWOn/ysUALAjyzX1ISbS/weCdSLUG0yvi07KIq8AkKU7Lqq/ocztfycVuI2o2fp006/sH4+bm2E+2ybZZxH6zfXbEjlmLCfbA/rC/7DF4DJ6C5+DlbXQiGO+ssw8IXv8DLFGrZA==</latexit>
<latexit sha1_base64="5UBweJgqeV2wPvP0iLOauF3We0w=">AAACH3icbVDLSgMxFM34rO+qSzfBIuimzEhFl6IblypWhc4gSXqrwSQzJnfUMsx3uLVf407c+jGCmdqFrwOBwzn3cm4Oz5R0GIbvwdj4xOTUdG1mdm5+YXGpvrxy7tLcCmiLVKX2kjMHShpoo0QFl5kFprmCC357WPkX92CdTM0Z9jNINLs2sicFQy8lMcIjFpt8i57tlFf1RtgMh6B/STQiDTLC8VX9I+6mItdgUCjmXCcKM0wKZlEKBeVsnDvImLhl19Dx1DANLimGR5d0wytd2kutfwbpUP2+UTDtXF9zP6kZ3rjfXiX+53Vy7O0lhTRZjmDEV1AvVxRTWjVAu9KCQNX3hAkr/a1U3DDLBPqefqRw7f9g4EGkWjPTLeLTsoirQM6L07LqK/rdzl9yvt2MWs2dk1Zj/2DUXI2skXWySSKyS/bJETkmbSLIHXkiz2QQDIKX4DV4+xodC0Y7q+QHgvdPwk6j+A==</latexit>
the two sets of sub-functional neurons. Formally, assuming that we identify the top k neurons for each sub-function, the overlap score is defined as∑
ni∈N1 I(ni∈N2) k , where N1 and N2 are the sets of neurons for the two considered sub-functions. If the overlap score is high, there is a group of neurons that are good at both sub-functions. In the experiments, we consider the neurons with the top 1% predictivities for each sub-function. Since there are hundreds of sub-functions, it is impossible to display all of them in a figure and we compute the average overlap score between two functions to measure the distribution similarity between different functions. Note that we omit the self-overlap scores, which are always equal to 1. The results are reported in the right part of Figure 1.
From this figure, we observe that: (1) In the pretrained models, the distribution similarity of the same function is significantly larger than that of different functions, which indicates that there are some groups of neurons, each of which is good at a certain function. And, it is not mainly caused by the similarity that naturally exists between subfunctions of the same function because the results of randomly-initialized models do not show such a phenomenon as shown in Appendix A.3. Hence, we conclude that there are some emergent groups of functionally-specialized neurons after pretraining. (2) One neuron may be capable of multiple sub-functions even from different functions. For example, the average overlap score between
the knowledge function and task function is also significantly higher than that of random models so there are some neurons good at both knowledge and task sub-functions.

heading: 5 Finding Modular Structure of Neurons
text: Since MoE is a promising candidate for the modular structure of Transformers, we analyze the MoE structure in this section. First, we verify whether the neurons specialized in a certain function are concentrated in some experts, called functional experts. Second, we perturb the activations of experts corresponding to a certain function. Third, we train the model on different datasets, retaining only functional experts by removing non-functional experts. The last two experiments verify the importance of the experts for their corresponding functions.
Distribution on experts. If experts were not functionally specialized, the sub-functional neurons would be randomly distributed among experts. Hence, we conduct statistical hypothesis testing to evaluate whether the neuron distribution on experts is significantly different from random. Assume that there are N neurons in a layer, nE neurons in each expert, k sub-functional neurons for each subfunction, and M sub-functions in a certain function. The null hypothesis is that the sub-functional neurons of each sub-function are independently and randomly distributed on experts, i.e., the number of sub-functional neurons in each expert follows a hypergeometric distribution with parameters N , K,
Model Pre-trained Partitioning Semantics Knowledge TaskProp. Degree Prop. Degree Prop. Degree
Switch Transformer % Random 0.002 0.037 0.001 0.024 0.001 0.018 ! Random 0.226 1.038 0.052 0.652 0.003 0.066 ! Pre-MoE 0.354 1.490 0.260 1.560 0.219 1.604
T5 % Random 0.016 0.257 0.001 0.031 0.001 0.017 ! Random 0.252 1.203 0.061 1.031 0.007 0.221 ! Post-MoE 0.338 2.000 0.214 2.686 0.120 3.276
Table 1: Proportion of functional experts to all experts and their modularization degree. Higher modularization degrees mean that functional experts have more sub-functional neurons than the expectation of uniform distribution.
and nE . The sum of the numbers of sub-functional neurons on all sub-functions in an expert is denoted by ri.3 The alternative hypothesis is that an expert has a larger ri than expected by chance.
In the experiments, we also treat the neurons with the highest 1% predictivities for each subfunction as its sub-functional neurons. For each function, we compute the p-value of the sum of the hypergeometric distribution for each expert and reject the null hypothesis if the p-value is less than 0.001. We also conduct the same experiment on random partitioning, where the neurons are randomly partitioned into expert-sized clusters, and randomly-initialized counterparts. We regard the experts that reject the null hypothesis as functional experts and report the proportion of functional experts to all experts in each function. And, we also consider the modularization degree, which is defined as the relative ratio of functional neurons in the expert compared to a uniform distribution. The proportion of functional experts and the modularization degree are computed by
Prop. = Ef E , Degree = ri nE /( Mk N ), (2)
where Ef is the number of functional experts, E is the number of experts, rinE is the proportion of functional neurons in the expert, and MkN is the proportion expectation of functional neurons under a uniform distribution. The overall degree is 0 if no functional expert exists, and otherwise is the average degree among all functional experts.
The results are shown in Table 1. From this table, we have three observations. (1) Since the sub-function distributions of pre-trained models are not independent, the proportion of functional
3We do not find a general form for the distribution of the sum of independent hypergeometric distributions. Since K is significantly smaller than N , we approximate the hypergeometric distribution with a binomial distribution.
<latexit sha1_base64="GAL2XLI1QrU9bmsTX/qY9XuEGJo=">AAACLnicbVBNSwMxEM36/W3Vm16CRdBL2ZWKHkU9eFSxKnRLSdKpBpPsksyqZVnw13jVXyN4EK/+CcFs7cGvgcDjvZl5mcdTJR2G4UswNDwyOjY+MTk1PTM7N19ZWDxzSWYFNESiEnvBmQMlDTRQooKL1ALTXME5v94v9fMbsE4m5hR7KbQ0uzSyKwVDT7UryzHCHebrfIM2jAMw9ICh34euaFeqYS3sF/0LogGokkEdtSsfcScRmQaDQjHnmlGYYitnFqVQUEzFmYOUiWt2CU0PDdPgWnn/hoKueaZDu4n1zyDts98ncqad62nuOzXDK/dbK8n/tGaG3Z1WLk2aIRjxZdTNFMWEloHQjrQgUPU8YMJK/1cqrphlAn1sP1y49jcYuBWJ1sx08vikyOPSkPP8pCjzin6n8xecbdaiem3ruF7d3RskN0FWyCpZJxHZJrvkkByRBhHknjyQR/IUPAXPwWvw9tU6FAxmlsiPCt4/AVEPqek=</latexit>
<latexit sha1_base64="o2ve9ulwaIBSaxYtxK9OKyhjJ8k=">AAACLHicbVBNTxsxEPXSL6BfgV6QuFiNKtFLtIuoyhFBDxxTICRSNopmnUliYXtX9iwQrba/plfya3pBqFf+BRLekENJOpKlp/dm5nlekinpKAxvg5UXL1+9frO6tv723fsPH2sbm+cuza3AlkhVajsJOFTSYIskKexkFkEnCtvJxVGlty/ROpmaM5pk2NMwMnIoBZCn+rWtmPCaih34yk8RDf8B5LeRK/u1etgIZ8WXQTQHdTavZr/2EA9SkWs0JBQ4143CjHoFWJJCYbke5w4zEBcwwq6HBjS6XjG7oORfPDPgw9T6Z4jP2H8nCtDOTXTiOzXQ2C1qFfk/rZvTcL9XSJPlhEY8GQ1zxSnlVRx8IC0KUhMPQFjp/8rFGCwI8qE9c0m0v8HglUi1BjMo4pOyiCvDJClOyiqvaDGdZXC+24j2Gt9+7tUPDufJrbJt9pntsIh9ZwfsmDVZiwn2i/1mN2waTIM/wV3w96l1JZjPfGLPKrh/BHLOqPE=</latexit>
experts of pre-trained models with random partitioning is higher than that of random-initialized counterparts. (2) However, the proportion of functional experts of pre-trained models with MoE partitioning is still higher than that with random partitioning. Moreover, the modularization degree of the functional experts in MoE structures is significantly higher than that in random partitioning. It indicates that the experts of both pre-MoE and post-MoE are more likely to intensively include neurons excelling in a certain function. (3) We further compare the predictivities of the functional experts and non-functional experts and find that the functional experts have significantly higher predictivities than the non-functional experts in their corresponding functions. It indicates that our quantification for expert predictivities is consistent with the concept of functional experts. More details are in Appendix A.4.
Perturbation analysis. Furthermore, we conduct perturbation experiments, which are widely used to analyze both biological and artificial neural
networks (Cowley et al., 2022; Wang et al., 2022b), to evaluate the causal effect of experts on model performance. Since T5 is a dense model and Switch Transformer is a sparse model, we use different perturbation methods for them. Specifically, the pre-MoE models only select one expert at each layer, so we choose to perturb the selection function. For the post-MoE models, which select all experts at each layer, we perturb the activation values of the targeting experts. Due to the difference in experiment setups, the perturbation performance is also different and their perturbation results are not comparable.
For T5, we perturb all neuron activations of the target experts by adding random noises to them and evaluate the perturbed models on the downstream tasks. We rank experts according to their sum of the predictivities for several downstream datasets and perturb the top-ranked experts. We regard the datasets used in computing the sum of the predictivities as seen datasets, including SST-2 (Socher et al., 2013), MRPC (Dolan and Brockett, 2005), CoLA (Warstadt et al., 2018), and QQP. To evaluate the generalization ability of the experts, we also perturb them and evaluate the perturbed models on unseen datasets, including MNLI (Williams et al., 2018), QNLI (Rajpurkar et al., 2016), CB (De Marneffe et al., 2019), MultiRC (Khashabi et al., 2018), and BoolQ (Clark et al., 2019a). We compute the average performance of the perturbed models on the seen and unseen datasets, respectively. For comparisons, we also conduct neuron-level perturbation and keep the proportion of perturbed neurons equal to that of expert-level perturbation. There are three kinds of neuron-level perturbations: (1) perturb the neurons that have top-ranked predictivities for a certain dataset, (2) perturb the neurons that have topranked sums of the predictivities for seen datasets, and (3) perturb the neurons randomly. We perturb the neurons in the last four layers where the task function is mainly located as shown in Figure 1. For fine-grained perturbation percentage, we partition FFNs into 96 experts, which is different from that of the other experiments.
We report the average accuracy of the perturbed models on the downstream tasks in Figure 2. From this figure, we have three observations. (1) The experts with high predictivities are very important for the model performance. For example, perturbing 10% of the experts by function in the
last four layers (around 3% of the total experts in the model) decreases the average accuracy by nearly 30% and makes the model perform as random guessing. (2) For neuron-level perturbations, “Avg” perturbation achieves a larger performance drop than single-dataset perturbation, which is expected because intuitively it perturbs the neurons with high overall predictivities. (3) Perturbing experts leads to a more significant performance drop than perturbing individual neurons on both seen and unseen datasets when the perturbation proportion is higher than 6%. It suggests neurons in the experts cooperate instead of working independently so perturbing them will influence the cooperation and lead to a significant performance drop. We conclude single neurons can not perform a function well in lack of the cooperation with modules despite their high overall predictivity.
For Switch Transformer, in the last four layers, we perturb the selection probabilities of experts. We constraint the model to select from a subset of experts by setting the selection probabilities of the other experts to 0 and fine-tune the perturbed models on the downstream tasks with the template in Gao et al. (2021). There are two kinds of perturbations: (1) No Function: we only select the non-functional experts in a certain task, which is equivalent to setting the activations of the functional experts to 0. (2) Function: we only select the functional experts in a certain task. Since the number of functional experts is smaller than that of non-functional experts, we randomly select a subset of non-functional experts for No Function to make the size of the subset equal to that of the functional experts. Besides, we also report the performance of the original model without any perturbation. More details are in Appendix A.2. From Table 2, we observe that avoiding the functional experts leads to an overall performance drop. Furthermore, only selecting the functional experts even achieves a higher performance than the original model.
In summary, we observe that the specialized neurons tend to be located concentratedly in some experts based on function and the functional experts play an important role when the model performs related functions. Hence, it is reasonable to study
<latexit sha1_base64="coici4VCDuPUzL9aaJHeradIHR4=">AAACMXicbVDLSiNBFK32PT6jLgehMAi6Cd2SYVyKblz6igrpEG5XbkxhVXVTdVsNTa/8mtmOX+NO3PoNA1Mds/B1oOBwzr2cuifJlHQUhk/BxOTU9Mzs3I/5hcWl5ZXa6tqFS3MrsCVSldqrBBwqabBFkhReZRZBJwovk5vDyr+8Retkas5pmGFHw7WRfSmAvNStbcSE91Rsww4/u5MkBvzcgnH91Gq0ZbdWDxvhCPwricakzsY47tb+xb1U5BoNCQXOtaMwo04BlqRQWM7HucMMxA1cY9tTAxpdpxidUfItr/S4j/bPEB+p7zcK0M4NdeInNdDAffYq8TuvnVN/r1NIk+WERrwF9XPFKeVVJ7wnLQpSQ09AWOn/ysUALAjyzX1ISbS/weCdSLUG0yvi07KIq8AkKU7Lqq/ocztfycVuI2o2fp006/sH4+bm2E+2ybZZxH6zfXbEjlmLCfbA/rC/7DF4DJ6C5+DlbXQiGO+ssw8IXv8DLFGrZA==</latexit>
<latexit sha1_base64="5UBweJgqeV2wPvP0iLOauF3We0w=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AAACH3icbVDLSgMxFM34rO+qSzfBIuimzEhFl6IblypWhc4gSXqrwSQzJnfUMsx3uLVf407c+jGCmdqFrwOBwzn3cm4Oz5R0GIbvwdj4xOTUdG1mdm5+YXGpvrxy7tLcCmiLVKX2kjMHShpoo0QFl5kFprmCC357WPkX92CdTM0Z9jNINLs2sicFQy8lMcIjFpt8i57tlFf1RtgMh6B/STQiDTLC8VX9I+6mItdgUCjmXCcKM0wKZlEKBeVsnDvImLhl19Dx1DANLimGR5d0wytd2kutfwbpUP2+UTDtXF9zP6kZ3rjfXiX+53Vy7O0lhTRZjmDEV1AvVxRTWjVAu9KCQNX3hAkr/a1U3DDLBPqefqRw7f9g4EGkWjPTLeLTsoirQM6L07LqK/rdzl9yvt2MWs2dk1Zj/2DUXI2skXWySSKyS/bJETkmbSLIHXkiz2QQDIKX4DV4+xodC0Y7q+QHgvdPwk6j+A==</latexit>
the modularity of Transformers by MoE.

heading: 6 Emergence of Modularity
text: In this section, we study the emergence of modularity during pre-training. To this end, we pre-train the base version of T5 and Switch Transformer from scratch. We use the MoEfication partitioning of the last checkpoint as the MoE structure of T5. More details of pre-training are in Appendix A.2.

heading: Emergence Patterns of Functional Experts.
text: We first study the changing curves of the proportion of functional experts and their modularization degree during pre-training, i.e., we apply the same analysis in Section 5 to each checkpoint. The results are shown in Figure 3. We have the following observations. (1) The proportion of functional experts and their modularization degree quickly achieves a high point, and then keeps relatively stable till the end. It indicates that functional experts emerge at the early stage of pre-training. (2) The proportion of functional experts in the Switch Transformer fluctuates significantly at about 20K steps and its stabilization is slower than that of T5. It suggests that the emergence of the modular structure in Switch Transformer is surprisingly more difficult than T5. The reason may be that Switch Transform omits the gradients of unselected experts, which causes the optimization to be harder than that of T5 (Du et al., 2022; Zoph et al., 2022).
Stabilization of Experts and Neurons. Even though clear is the changing curve of the number and modularization degree of functional experts from a global perspective, we still do not know how the predictivities of neurons and experts changes.
There are two kinds of predictivity dynamics. The first is the changing of the absolute predictivities, and the second is the relative order changing of predictivities among all experts or neurons. While it is straightforward to study the absolute predictivities, it is difficult to have a consistent analysis standard due to different scales for different func-
tions and layers. Hence, we focus on the relative order changing of predictivities. Intuitively, some experts or neurons may excel in a sub-function at a certain stage, and maintain this relative dominance as pre-training continues. With this in mind, we study the stabilization of predictivity rankings.
To study the stabilization of predictivity rankings, we quantify the similarity between a layer of two model checkpoints w.r.t. a particular subfunction, which is either at the expert level or at the neuron level. Specifically, for a sub-function, we define such a similarity as Spearman’s rank correlations (Spearman, 1961) between the predictivities of experts or neurons in the considered layer of the two checkpoints. In this way, we measure to what extent the predictivities of the two checkpoints is positively correlated. We measure the similarity between two adjacent (saved) checkpoints as stabilization score, which reflects the trend toward stabilization. Higher similarity indicates a lower changing pace and thus a higher degree of stabilization. For each function, we show the curve of average stabilization score among all sub-functions in it and across all layers, both at the expert level and neuron level. To facilitate our analysis, we also measure it on random partitioning.
We report the result in Figure 4. From this figure, we have four observations. (1) During the pre-training, both experts and neurons are increasingly stabilized. (2) Experts are stabilized to a large extent at the early stage of pre-training. It takes around 15% of the total training steps for the expert predictivities to achieve a stabilization score of 0.9. (3) Expert stabilization is notably faster than both neuron stabilization (around 75% of the total training steps) and the stabilization for random partitioning4. In conclusion, we see strong evidence that coarse-to-fine is the inner mechanism of pre-training. Transformer first learns a modular
4While the numbers of experts and neurons are different, the correlation scores are comparable (De Winter et al., 2016).
<latexit sha1_base64="IiQcAAYHuIDgHl1FpQD455bTZiw=">AAACHHicbVBNS8NAEN34WetX1aOXYBHqpSSi6FH04rEWW8WmlM122i7ubsLuRC0h/8Kr/TXexKvgjxHctD1odWDg8d4Mb+aFseAGPe/TmZtfWFxaLqwUV9fWNzZLW9tNEyWaQYNFItK3ITUguIIGchRwG2ugMhRwE95f5PrNA2jDI3WNwxjakvYV73FG0VJ3AcITphV6kHVKZa/qjcv9C/wpKJNp1Tqlr6AbsUSCQiaoMS3fi7GdUo2cCciKQWIgpuye9qFloaISTDsdX5y5+5bpur1I21bojtmfGymVxgxlaCcl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TrF33Mm4SlIExX6MeqnwUfvF/36XG2AoRg5QZri71WcDaihDl9KESyzdDwoemJaSqm4WXeZZVBjGcXaZF3mF0+n8BdcH9bBRP7xo1JonZXKLZIfskn0SkiPSJGfknLQII5o8kWfy4r14r96b9/4zWvHKnW0yUd7HN85wpBs=</latexit>
structure, where the structure becomes stable at the early stage, and then there is a fine-grained process to learn neuron functions.

heading: 7 Discussion
text: Efficient Pre-training. Large-scale pre-training of Transformers is very expensive (Brown et al., 2021). It is promising to use MoE to reduce the computational cost by activating only a small part of the experts. Our findings have shown the emergent modularity of experts, which demonstrates the reasonableness of the MoE structure. However, as shown in Section 6, Switch Transformer is more unstable than T5 on the modular structure at the beginning. It suggests that we should begin with a dense model and gradually make it sparse instead of directly training a sparse model from scratch, which has been explored in some preliminary works (Nie et al., 2021; Hazimeh et al., 2021).
Model Fusion. Considering there are many pre-trained models on different corpora and even modalities, researchers have started to explore how to fuse them to aggregate different knowledge together. Compared with model ensembling, model fusion has the potential to be more efficient because it does not compute all of the models. Much of the current research in model fusion focuses on weight averaging and achieves some promising results (Li et al., 2022; Matena and Raffel, 2021). However, weight averaging requires two models having the same architecture, which is not always the case. In this work, we discover the modular structure of pre-trained Transformers, which may facilitate the model fusion based on module combinations,
which gets rid of the architecture constraint. Connection between Brains and Pre-trained Transformers. Building an artificial brain that corresponds to the human brain is an important neuroscience problem, e.g., the Blue Brain project (Markram, 2006). Currently pre-trained Transformers show strong power for predicting brain signals (Toneva and Wehbe, 2019; Caucheteux et al., 2021), but more fine-grained connections between the two are still not clear. In analogy to brain regions, we present the modular structure of pre-trained Transformers. It will be interesting to explore the connection between brain regions and the Transformer modules in the future.

heading: 8 Conclusion
text: In this paper, we study the modularity of pretrained Transformers and validate the emergence of modularity. We also study the pre-training process to understand the emergence of modularity and find the coarse-to-fine mechanism of pre-training. We expect our evaluation framework and findings will facilitate and inspire future research in this area.

heading: Limitations
text: The major limitations of our work are as follows: (1) We show that the neuron structure of MoE reveals the presence of modularity in pre-trained Transformers. However, the MoE structure is not the only possible modular structure. To better understand the modular structure of Transformers, we need to explore more types of structures. For example, the number of neurons in each module could be different, and the modular structure could
be hierarchical, where modules are grouped into larger modules. (2) We study three typical functions for language processing: semantic function, knowledge function, and task function. There are many other functions that could be studied, such as the syntactic function, discourse function, etc. Moreover, our categorization of functions may be not suitable for pre-trained Transformers because there are some overlaps between studied functions. A new Transformer-based function categorization may be needed. (3) We transform T5 into its MoE version to study its modular structure while not all dense pre-trained Transformers can be studied in this way because the adopted MoEfication technique (Zhang et al., 2022b) can only transform ReLU-based Transformers. Studying the modularity of other dense pre-trained Transformers, such as BERT, is also important for future research.

heading: Acknowledgements
text: This work is supported by the National Key R&D Program of China (No. 2020AAA0106502) and Institute Guo Qiang at Tsinghua University.
Author Contributions Zhengyan Zhang and Zhiyuan Zeng wrote the code and conducted the experiments. Zhengyan Zhang and Zhiyuan Zeng wrote the initial draft. Yankai Lin, Chaojun Xiao, Xiaozhi Wang, Xu Han, and Zhiyuan Liu, Ruobing Xie significantly edited and improved the paper. Maosong Sun and Jie Zhou provided valuable advice to the research.

heading: A Appendix

heading: A.1 Neurons of MoE
text: In MoE layers, each expert is an FFN, and the output of the MoE layer is the weighted sum of the outputs of all experts, MoE(x) = ∑E i=1 αiFFNi(x), where αi is the weight of the i-th expert and FFNi is the i-th expert. αi is computed by a gating network. Note that the weights of unselected experts are zero, which makes the MoE layer sparse. We can also rewrite the MoE layer into a neuron-based form,
MoE(x) = E∑
i=1
αi ∑
j
σ(W Ii,j,: · x)WOi,:,j
= ∑
i,j
σ(W Ii,j,: · x)αiWOi,:,j , (3)
where W Ii,j,: and W O i,:,j are the j-th row and column of W Ii and W O i in the i-th expert, respectively. The gating weight αi is non-negative and can be viewed as the scaling factor of WOi,:,j . Correspondingly, we define a neuron ni,j as a row vector W Ii,j,: and a column vector W O i,:,j , and the neuron activation of ni,j is σ(W Ii,j,: · x).

heading: A.2 Experimental Details
text: Calculation of AP. AP is the weighted average of precision at different recall levels, which is a common metric for evaluating the performance of binary classification models. Since AP only represents the positive correlation, we compute the APs of both neuron activations and their opposite values, −ai, and take the maximum as the final AP. The final AP ranges from 0.5 to 1, where 0.5 means the neuron is useless for the sub-function and 1 means the neuron is perfect for the sub-function.
Randomly-initialized models. In Section 4, the evaluation of randomly-initialized models is conducted 3 times and we report the average results.
Perturbation analysis on T5. To match the magnitude of neuron activations of T5, we set the variance of the Gaussian noise to be 4. The perturbation analysis is conducted 5 times and we report the average results.
Perturbation analysis on Switch Transformer. In this experiment, the predictivity and thus the functional experts are calculated based on the training set. Since Switch Transformer has not been trained on the considered datasets during pretraining, we train it on 128 randomly-picked training instances. We tune WO in the last four years
as it takes the neuron activations as inputs, plus the routers in MoE layers. The learning rate and batch size are always 2E-4 and 16 respectively and we take Adam (Kingma and Ba, 2015) as the optimizer. The epoch is 100, 300, 50, 100, 300, 150, and 200 for CoLA, MNLI, MRPC, RTE, QNLI, QQP, and SST-2. We run each experiment with 8 different seeds and report the average best performance on the validation set. The result for each dataset is reported in Table 3.
Hyper-parameters of pre-training. The pretraining corpus is OpenWebText (Radford et al., 2019), which contains 40GB of web text. We use the same pre-training task as the official T5 and Switch Transformer, which is masked language modeling. The total number of training steps is 200K and we save the model every 5K steps. We use the same hyper-parameters for pre-training to avoid the effect of hyper-parameters on our analysis, and it is also a common practice when comparing dense and sparse T5s (Zoph et al., 2022). The learning rate is 1e-4. The batch size is 512. The max lengths of encoder inputs and decoder inputs are 512 and 256, respectively. We use 8 NVIDIA A100 GPUs for pre-training. The total pre-training time is around 3 days.
Experiments on random partioning. In Section 5 and Section 6, we do the hypothesis testing on random partitioning, and we also calculate Spearman’s rank correlation between adjacent checkpoints on random partitioning. These random experiments are done 1000 times and we report the average results.

heading: A.3 Function Distribution in Each Layer
text: Following Section 4, we report the distribution similarity of the randomly-initialized models in Figure 5, which is significantly different from that of the pre-trained models.
<latexit sha1_base64="7cZKi+qgi/cbLC6AGwNMDcg5Adg=">AAACMXicbVDLSgMxFM34tr6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PBydHvCrc=">AAACKHicbVBNTxsxFPTSUijQsv249WIRIaWXaBclgiMqlx4hIoCUjSLbeSFW/LGy30LT1f4XruXXcENc+z+Q6g05FMJIlkYz72meh+dKekySh2jlzdvVd2vr7zc2tz583I4/fT7ztnACesIq6y4486CkgR5KVHCRO2CaKzjn06PaP78C56U1pzjLYaDZpZFjKRgGaRh/zRB+Ydnk32mXmZHV9LRTDeNG0krmoMskXZAGWeB4GD9mIysKDQaFYt730yTHQckcSqGg2sgKDzkTU3YJ/UAN0+AH5fz6iu4GZUTH1oVnkM7V/zdKpr2faR4mNcOJf+nV4mtev8DxwaCUJi8QjHgKGheKoqV1FXQkHQhUs0CYcDLcSsWEOSYwFPYshevwBwPXwmodWiqzblVmdSDnZbeq+0pftrNMzvZaabvVOWk3Dn8smlsn38gOaZKU7JND8pMckx4R5De5IX/IbXQb3UX30cPT6Eq02PlCniH6+w+jI6bw</latexit>
<latexit sha1_base64="27r966ahhL/H+ha6Lxy680b+OuU=">AAACH3icbVBNSwMxFMz6WetX1aOXYBH0UnalokfRi0ctrQrdRbLpqwaT7Jq8Vcuyv8Or/TXexKs/RjBbe1DrQGCYeY95mTiVwqLvf3hT0zOzc/OVheri0vLKam1t/cImmeHQ4YlMzFXMLEihoYMCJVylBpiKJVzGdyelf/kAxopEt3GQQqTYjRZ9wRk6KQoRnjDfYbu0vV9c1+p+wx+BTpJgTOpkjLPr2mfYS3imQCOXzNpu4KcY5cyg4BKKaphZSBm/YzfQdVQzBTbKR0cXdNspPdpPjHsa6Uj9uZEzZe1AxW5SMby1f71S/M/rZtg/jHKh0wxB8++gfiYpJrRsgPaEAY5y4AjjRrhbKb9lhnF0Pf1KiZX7g4ZHnijFdC8PW0UeloFxnLeKsq/gbzuT5GKvETQb++fN+tHxuLkK2SRbZIcE5IAckVNyRjqEk3vyTF7I0Bt6r96b9/49OuWNdzbIL3gfX8Cao/c=</latexit>

heading: A.4 Predictivity of Functional Experts
text: We quantify the predictivity of the expert for subfunctions in Section 3 and define functional experts in Section 5, and different are the technical details of quantification and definition. Hence, we conduct an experiment to check their consistency. For a function, we calculate bi as the average predictivity across all sub-functions for each expert ei, and we also denote fi ∈ {0, 1} as whether ei is a functional expert or not. Now we have B = {(bi, fi)}Ei=1, based on which we compute the AP. A high AP indicates a high consistency. We report the average AP across all layers in Table 5.
The average AP is quite high. Therefore, we are confident that the quantification for expert predictivity is consistent with the concept of functional experts.

heading: A.5 Sub-Functioanl Experts
text: Similar to the concept of functional experts discussed in Section 4, we can also define so-called sub-functional experts. Basically, for each subfunction, we conduct statistical hypothesis testing on its sub-functional neurons. We similarly calculate the proportion of sub-functional experts and their modularization degree. We report the average result within each function. The result of the Switch Transformer and T5 used in Section 4 is reported in Table 4. The changing curve of the Switch Transformer and T5 trained by us is reported in Figure 6.

heading: A.6 Organization of Sub-Functions
text: We further study how the model organizes subfunctions into their functional experts5 and how the organization changes during the pre-training. From the perspective of sub-functions, it is basically how a sub-function shares functional experts with others.
For a function, we can list all the sub-functions within it denoted as w1, w2, . . . , wM . The similarity score between each pair of sub-functions can be seen as a matrix S, where Si,j is the similarity score between wi and wj for all 1 ≤ i, j ≤ M .
5Strictly speaking, we did not define functional experts for a sub-function. In this context, the concept of “functional experts” is used to refer to the experts that have high predictivity for a sub-function.
<latexit sha1_base64="coici4VCDuPUzL9aaJHeradIHR4=">AAACMXicbVDLSiNBFK32PT6jLgehMAi6Cd2SYVyKblz6igrpEG5XbkxhVXVTdVsNTa/8mtmOX+NO3PoNA1Mds/B1oOBwzr2cuifJlHQUhk/BxOTU9Mzs3I/5hcWl5ZXa6tqFS3MrsCVSldqrBBwqabBFkhReZRZBJwovk5vDyr+8Retkas5pmGFHw7WRfSmAvNStbcSE91Rsww4/u5MkBvzcgnH91Gq0ZbdWDxvhCPwricakzsY47tb+xb1U5BoNCQXOtaMwo04BlqRQWM7HucMMxA1cY9tTAxpdpxidUfItr/S4j/bPEB+p7zcK0M4NdeInNdDAffYq8TuvnVN/r1NIk+WERrwF9X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FKeVVJ7wnLQpSQ09AWOn/ysUALAjyzX1ISbS/weCdSLUG0yvi07KIq8AkKU7Lqq/ocztfycVuI2o2fp006/sH4+bm2E+2ybZZxH6zfXbEjlmLCfbA/rC/7DF4DJ6C5+DlbXQiGO+ssw8IXv8DLFGrZA==</latexit>
<latexit sha1_base64="5UBweJgqeV2wPvP0iLOauF3We0w=">AAACH3icbVDLSgMxFM34rO+qSzfBIuimzEhFl6IblypWhc4gSXqrwSQzJnfUMsx3uLVf407c+jGCmdqFrwOBwzn3cm4Oz5R0GIbvwdj4xOTUdG1mdm5+YXGpvrxy7tLcCmiLVKX2kjMHShpoo0QFl5kFprmCC357WPkX92CdTM0Z9jNINLs2sicFQy8lMcIjFpt8i57tlFf1RtgMh6B/STQiDTLC8VX9I+6mItdgUCjmXCcKM0wKZlEKBeVsnDvImLhl19Dx1DANLimGR5d0wytd2kutfwbpUP2+UTDtXF9zP6kZ3rjfXiX+53Vy7O0lhTRZjmDEV1AvVxRTWjVAu9KCQNX3hAkr/a1U3DDLBPqefqRw7f9g4EGkWjPTLeLTsoirQM6L07LqK/rdzl9yvt2MWs2dk1Zj/2DUXI2skXWySSKyS/bJETkmbSLIHXkiz2QQDIKX4DV4+xodC0Y7q+QHgvdPwk6j+A==</latexit>
For a given k, we denote O(k)i,j as the top k expert overlap for wi and wj . When Spearman’s rank correlation between Si,: and O (k) i,: (denoted as V (k)i ) is high, it indicates that the sub-functions similar to wi share more functional experts than sub-functions dissimilar to wi do, and vice versa. According to the meaning, we call V (k)i clustering score.
We do a case study on the semantic function of the Switch Transformer, which focuses on understanding word meanings. Since relatively mature is the method of quantifying word similarity, we take S as the word similarity matrix calculated by spaCy (Honnibal and Montani, 2017). Note that the features at the word level are the lowest level of semantic information, so the word similarity reflects the lowest level of similarity between two semantic sub-functions.
We report the curve of ∑K k=1 ∑M i=1 V (k) i
KM for each layer in Figure 7. We also report the result for random partitioning in Figure 8. From this figure, we have the following observations. (1) During pretraining, the clustering score of the lowest MoE layer (Layer 1) quickly achieves 0.6 and then keeps stable till the end. It proves that the pre-training tends to organize sub-functions sharing similar low-
level information into the same functional experts in the low layer. However, the final clustering score of higher MoE layers is close to 0, indicating that high layers do not organize sub-functions based on word similarity. We guess that the reason is that the high layers may process high-level semantic information, which is not related to the word similarity. (3) We see three interesting curves of layers 3, 5, and 11. Their clustering scores achieve a high point when the clustering score of layer 1 first achieves its highest point, and then they continuously decrease to 0. The trend that high layers become increasingly responsible for high-level features may grow faster when the low-layer organization has been established than when the organization is forming.
ACL 2023 Responsible NLP Checklist

heading: A For every submission:

heading: 3 A1. Did you describe the limitations of your work?
text: After the conclusion.
A2. Did you discuss any potential risks of your work? Not applicable. Left blank.

heading: 3 A3. Do the abstract and introduction summarize the paper’s main claims?
text: Abstract and Section 1
7 A4. Have you used AI writing assistants when working on this paper? Left blank.
B 3 Did you use or create scientific artifacts? 5,A.2, A.3
3 B1. Did you cite the creators of artifacts you used? 5,A.2
7 B2. Did you discuss the license or terms for use and / or distribution of any artifacts? These datasets are publicly available and free of use for research purposes.
7 B3. Did you discuss if your use of existing artifact(s) was consistent with their intended use, provided that it was specified? For the artifacts you create, do you specify intended use and whether that is compatible with the original access conditions (in particular, derivatives of data accessed for research purposes should not be used outside of research contexts)? The use is consistent with their intended use.
7 B4. Did you discuss the steps taken to check whether the data that was collected / used contains any information that names or uniquely identifies individual people or offensive content, and the steps taken to protect / anonymize it? We use established public datasets, which should not cause privacy issues.

heading: 3 B5. Did you provide documentation of the artifacts, e.g., coverage of domains, languages, and
text: linguistic phenomena, demographic groups represented, etc.? A.2
3 B6. Did you report relevant statistics like the number of examples, details of train / test / dev splits, etc. for the data that you used / created? Even for commonly-used benchmark datasets, include the number of examples in train / validation / test splits, as these provide necessary context for a reader to understand experimental results. For example, small differences in accuracy on large test sets may be significant, while on small test sets they may not be. A.2,A.3
C 3 Did you run computational experiments? 4,5,6

heading: 3 C1. Did you report the number of parameters in the models used, the total computational budget
text: (e.g., GPU hours), and computing infrastructure used? A.3
The Responsible NLP Checklist used at ACL 2023 is adopted from NAACL 2022, with the addition of a question on AI writing assistance.

heading: 3 C2. Did you discuss the experimental setup, including hyperparameter search and best-found
text: hyperparameter values? A.3

heading: 3 C3. Did you report descriptive statistics about your results (e.g., error bars around results, summary
text: statistics from sets of experiments), and is it transparent whether you are reporting the max, mean, etc. or just a single run? A.3

heading: 3 C4. If you used existing packages (e.g., for preprocessing, for normalization, or for evaluation), did
text: you report the implementation, model, and parameter settings used (e.g., NLTK, Spacy, ROUGE, etc.)? A.7
D 7 Did you use human annotators (e.g., crowdworkers) or research with human participants?

heading: Left blank.
text: D1. Did you report the full text of instructions given to participants, including e.g., screenshots, disclaimers of any risks to participants or annotators, etc.? No response.
D2. Did you report information about how you recruited (e.g., crowdsourcing platform, students) and paid participants, and discuss if such payment is adequate given the participants’ demographic (e.g., country of residence)? No response.
D3. Did you discuss whether and how consent was obtained from people whose data you’re using/curating? For example, if you collected data via crowdsourcing, did your instructions to crowdworkers explain how the data would be used? No response.
D4. Was the data collection protocol approved (or determined exempt) by an ethics review board? No response.
D5. Did you report the basic demographic and geographic characteristics of the annotator population that is the source of the data? No response.

heading: Future Work
text: Studying the modularity of other dense pre-trained Transformers, such as BERT, is also important for future research