{'fraction_non_alphanumeric': 0.030693174947540633, 'fraction_numerical': 0.008926983675356546, 'mean_word_length': 4.684997978164173, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
SplineNets: Continuous Neural Decision Graphs

We present SplineNets, a practical and novel approach for using conditioning in convolutional neural networks (CNNs). SplineNets are continuous generalizations of neural decision graphs, and they can dramatically reduce runtime complexity and computation costs of CNNs, while maintaining or even increasing accuracy. Functions of SplineNets are both dynamic (i.e., conditioned on the input) and hierarchical (i.e., conditioned on the computational path). SplineNets employ a unified loss function with a desired level of smoothness over both the network and decision parameters, while allowing for sparse activation of a subset of nodes for individual samples. In particular, we embed infinitely many function weights (e.g. filters) on smooth, low dimensional manifolds parameterized by compact B-splines, which are indexed by a position parameter. Instead of sampling from a categorical distribution to pick a branch, samples choose a continuous position to pick a function weight. We further show that by maximizing the mutual information between spline positions and class labels, the network can be optimally utilized and specialized for classification tasks. Experiments show that our approach can significantly increase the accuracy of ResNets with negligible cost in speed, matching the precision of a 110 level ResNet with a 32 level SplineNet.


Introduction and Related Work
There is a growing body of literature applying conditioning to CNNs, where only parts of the network are selectively active to save runtime complexity and compute. Approaches use conditioning to scale model complexity without an explosion of computational cost e.g. [1] or increase runtime efficiency by reducing model size and compute without degrading accuracy e.g. [2]. In this paper we present a new and practical approach for supporting conditional neural networks called SplineNets. We demonstrate how these novel networks dramatically reduce runtime complexity and computation cost beyond regular CNNs while maintaining or even increasing accuracy.
Conditional neural networks can be categorized into three main categories: (1) proxy objective methods that train decision parameters via a surrogate loss function, (2) probabilistic (mixture of experts) methods that assign scores to each branch and treat the loss as a weighted sum over all branches, and (3) feature augmentation methods that augment the representations with the scores.
The first group relies on non-differentiable decision functions and trains decision parameters using a proxy loss. Xiong et al. use a loss that maximizes distances between subclusters in their conditional convolutional network [3]. Baek et al. use purity of data activation according to the class label [4], and Biçici et al. use information gain as the proxy objective [5]. While the former approach only allows soft decisions, the latter method uses argmax of a scoring function to sparsely activate branches, which results in discontinuities in the loss function. Bulo et al. use multi-layered perceptrons as decisions, and the network otherwise acts like a decision tree [6]. Denoyer et al. train a tree structured network using the REINFORCE algorithm [7]. 32nd Conference on Neural Information Processing Systems (NIPS 2018), Montréal, Canada.
Ioannou et al. take a probabilistic approach, assigning weights to each branch and treating the loss as a weighted sum over losses of each branch [2]. They sparsify the decisions at test time, leading to gains in speed at the cost of accuracy. Shazeer et al. follow a similar probabilistic approach that assigns weights to a very large number of branches in a single layer [1]. They use the top-k branches both at training and test time, leading to a discontinuous loss function. Another approach treats decision probabilities of a tree as the output of a separate neural network and then trains both models jointly, while slowly binarizing decisions [8]. However, inference still requires a regular network to be densely evaluated to generate the decision probabilities.
Finally, Wang et al. [9] take the approach of creating features from scores, enabling decisions to be trained via regular back-propagation. However, they have only decisions and do not build higher level representations.
Our method is novel and does not fit any of these categories. It is inspired from the recently proposed non-linear dimensionality reduction technique called Additive Component Analysis (ACA) [10]. This technique fits a smooth, low dimensional manifold to data and learns a mapping from it to the input space. We extend this work by learning both the projections onto these manifolds, as well as the mapping to the input space in a neural network setting. We then apply this technique to the function weights in our network. Hence, SplineNets employ subnetworks that explicitly form the main network parameters from some latent parameters, as in the case of Hypernetworks [11]. Unlike that work, we also project to these latent manifolds, conditioned on the feature maps. This makes SplineNet operations dynamic, which is similar to the approaches in Dynamic Filter Networks [12], Phase-functioned Neural Networks [13] and Spatial Transformer Networks [14]. We further condition these projections on previous projections in the network to make the model hierarchical. As these projections replace the common decision making process of selecting a child from a discrete set, this becomes a new paradigm for decision networks, which operates in continuous decision spaces. There is some similarity with Reinforcement Learning (RL) on Continuous Action Spaces [15], but the aim and problem setting for RL is much different from hierarchical decision graphs. For instance, rewards come from the environment in an RL setting, whereas decisions specialize the network and define the loss in our case.
The heart of SplineNets is the embedding of function weights on low dimensional manifolds described by B-splines. This effectively makes the branching factor of the underlying decision graph uncountable, and indexes the infinitely many choices with a continuous position parameter. Instead of making discrete choices, the network then chooses a position, which makes the decision process differentiable and inherently sparse. We call this the Embedding Trick, somewhat analogous to the Reparameterization Trick that makes the loss function differentiable with respect to the distribution parameters [16].
Load balancing is a common problem in hierarchical networks, which translates to under-utilization of splines in our continuous paradigm. The common solution of maximizing information gain based on label distributions on discrete nodes, as used in [5], translates to specializing spline sections to class labels or clusters in our case. We show that maximizing the mutual information between spline positions and labels solves both problems, and in the absence of labels, one can instead maximize the mutual information between spline positions and the input, in the style of InfoGANs [17].
Another common issue with conditional neural networks is that the mini-batch size gets smaller with each decision. This leads to serious difficulties with training due to noisier gradients towards the leaves and learning rate needing adaptation to each node, while also limiting the maximum possible depth of the network. Baek et al. use a decision jungle based architecture to tackle this problem [4]. Decision jungles allow nodes in a layer to co-parent children, essentially turning the tree into a directed acyclic graph [18]. SplineNets also do not suffer from this issue, since their architecture is essentially a decision jungle with an (uncountably) infinite branching factor. We further add a constraint on the range of valid children to simulate interesting architectures.
Our contributions in this paper are: (i) the embedding trick to enable smooth conditional branching, (ii) a novel neural decision graph that is uncountable and operates in continuous decision space, (iii) an architectural constraint to enforce a semantic relationship between latent parameters of functions in consecutive layers, (iv) a regularizer that maximizes mutual information to utilize and specialize splines, and (v) a new differentiable quantization method for estimating soft entropies.

Methodology
CNNs take an input x 1 =x and apply a series of parametric transformations, such that x i+1 =T i (x i ; ω i ), where superscript i is the level index. On the other hand, decision graphs typically navigate the input x with decision functions parameterized by θ i , selecting an eligible node and the next parameters θ i+1 contained within. Skipping non-parametric functions for CNNs and assuming sparse activations for decision graphs, we can describe their behavior with the graphical models shown in Figure 1. Assuming a symmetrical architecture, such that T i j for each node j in layer i has the same form but different weights, a neural decision graph (NDG) can then be described by the graphical model shown on the right. The decision process governed by parameters θ i is used here to determine the next ω i (red arrows) as well as θ i+1 (green arrows). Discrete NDGs then have a finite set of weights choose from at each level with N i nodes, depending on the features x i and choices from the previous level. In this work, we investigate the case where the set of choices is uncountably infinite and parameterized with an index variable, forming a continuous NDG.

Embedding trick
The embedding trick can be viewed as making the branching factor of the underlying NDG uncountably infinite, while imposing a topology on neighboring nodes. Each ω i j in the set of discrete choices is essentially a point in R g i . In the limit of N i →∞, these infinitely many points lie on a low dimensional manifold, as shown in Figure 2 (assuming g i =3). In this work, we assume this manifold is a 1D curve in R g i , parameterized by a position parameter φ i ∈ [0, 1], which is used to index the individual ω i 's. A simple example would be the set of all 5 × 5 edge filters, which form a closed 1D curve in a 25D space. Instead of making a discrete choice from a finite set, the network can then choose a φ i using a smooth, differentiable function. The same process can be applied to the decision parameters θ i j to form another 1D curve in R h i , indexed by the same position parameter φ i , since selecting a node j should implicitly pick both ω i j and θ i j in an NDG. We parameterize these latent curves with B-splines, since they have bounded support over their control points, or knots. This is a desirable property that allows efficient inference by allowing only a small set of knots be activated per sample, and it also makes training more well-behaved, since updates to control points can change the shape of the manifold only locally. Notably, this also efficiently solves the exploration problem, since the derivative of the loss with respect to the spline position exists, and the network knows which direction on the spline should further reduce the energy. The knots are trained offline, while the position parameters are dynamically determined during runtime.
While we only focus on 1D manifolds in this paper, our formulation allows easy extension to higher dimensional hypersurfaces in the same style as ACA, simply by describing surfaces as a sum of splines. This restricts the family of representable surfaces, but leads to a linear increase in the number of control points that need to be learned, as opposed to the general case where one needs exponentially many control points.
B-splines are piecewise polynomial parametric curves with bounded support and a desired level of smoothness up to C d−1 , where d is the degree of the polynomials. The curve approximately interpolates a number of knots, such that S(φ) = K k=1 C k B k (φ). Here, C k , k = 1..K are the knots and B k (φ) are the basis functions, which are piecewise polynomials of the form  (middle) Increasing the number of nodes reveals that the weights lie on a lower dimensional manifold. (right) The embedding trick represents this manifold with a spline, and replaces the discrete decision making process with a continuous projection. position space spanned by φ. Note that they can still be anywhere in the actual space they live in. The degree of the splines also controls how far away the samples can see on the spline, helping with the exploration problem common with conditional architectures.
We apply the embedding trick to both transformation weights ω and decision parameters θ separately, so that a transformer spline S i ω generates the ω i and a decision spline S i θ generates the θ i . The spline S i ω and its knots C i ω,k are in R g i , and S i θ and its knots C i θ,k are in R h i . Figure 3 shows the corresponding graphical models. The model on the left shows a dynamic, non-hierarchical SplineNet, and the model on the right is a hierarchical SplineNet. Here, the orange arrows correspond to the projections, blue arrows indicate representation learning, red arrows are generation of transformation parameters and green arrows are generation of decision weights. The dashed orange arrow indicates a topological constraint, which is used to restrict access to sections of a spline depending on the previous position of the sample, for instance to simulate tree-like behaviour. This can enforce a semantic relationship between sections of consecutive splines, roughly corresponding to mutually exclusive subtrees for instance. Since φ i is analogous to the node index in the discrete case, it can be used to determine the valid children nodes, which corresponds to a sub-range of the positions available for the next spline. Without any topological constraints, the projection becomes simply In this work, we assume a linear projection followed by a sigmoid function, but any differentiable mapping can be used. With topological constraints, we define the new position φ i+1 as a linear combination between the old position and the new projection: Here, δ i is a layer dependent diffusion parameter that controls the conditional range of projections. Setting δ i =1 roughly simulates a decision jungle [18] with an infinite branching factor, which has no restrictions on how far samples can jump between layers. While regular decision jungles maintain only a small number of valid children for each node, SplineNet jungles allow transition to any one of the infinitely many nodes in the next layer. By setting δ i =b 1−i we can also simulate a b-ary decision tree, but it has the issues with mini-batch size discussed earlier, and performs typically worse. A fixed δ i =α spans a novel continuous family of architectures for 0≤α≤1.
Note that while the topological constraint adds a flavor of hierarchical dependency to the network, a proper decision graph should pick different decision parameters for each node. This constraint determines the graph edges between consecutive layers, but it does not have an effect on the decision parameters.

SplineNet operators
Projections Projection D is a mapping from feature map x i to spline position φ i . While any differentiable mapping is valid, we consider two simple cases: (i) a dot product with the flattened feature vector, and (ii) a 1×1 convolution followed by global averaging, which has fewer parameters to learn. In the first case, θ i is a vector in R M i , and the time and memory complexities are both O(M i ). While this is negligible for networks with large dense layers, it becomes significant for all-convolutional networks. For the second case, θ i is a filter in R 1,1,c,1 where c is the number of feature map channels. In both cases, a sigmoid with a tunable slope parameter is used to map the response to the right range. Fully connected layers Fully connected layers have weights ω in the form of a matrix, such that ω i ∈ R M i ×M i+1 . Thus, the corresponding spline must have knots that also lie in the same space. The additional costs compared to a regular fully connected layer besides the projection is the generation of ω via the spline function S i ω , which has a time complexity O(dM i M i+1 ), and a memory complexity Convolutional layers Conventional 2D convolutional layers have rank-4 filter banks in R h,w,c,f as weights ω, where h is the height and w is the width of the kernels, c is the number of input channels, and f is the number of filters (we drop superscript i for simplicity). We propose two different ways of representing filter banks with splines: (i) a single spline with rank-4 knots, or (ii) f splines with rank-3 knots. While the first approach is a single curve between entire filter banks in R h,w,c,f , the second approach uses a spline per filter, each with knots living in R h,w,c . Rank-4 case is straightforward, with a single spline S i ω generating the filter bank as before. The additional time complexity is O(dhwcf ), and the memory complexity is O(K i ω hwcf ). To handle multiple splines with rank-3 filters, we need to project to each spline separately. In the case of dot product decisions, this effectively turns θ i to a matrix of form R f ×M i , such that the projection D(x i ; θ i ) = sigmoid(θ i x i ) results in a φ i ∈ R f . Then, the final filter bank can be generated by: where φ i j is the jth element of φ i that corresponds to the spline S i ω,j , and is the stacking operator that forms the filter bank. The additional time complexity is O(M i f + dhwcf ) and the memory needed is O(M i f +K i ω hwcf ). Adapting the same approach to convolutional decisions is straightforward by changing the decision filter dimensionality to R 1,1,c,f . When plugging many such rank-3 layers together, it may not be possible to diffuse positions coming from the previous layer with the new ones directly using Equation 1, since they may have different sizes. In such cases, we multiply the inherited positions with a learned matrix to match the sizes of positions.

Regularizing SplineNets
The continuous position distribution P (φ i ) plays an important role in utilizing SplineNets properly, e.g. if all φ i 's that are dynamically generated by samples are the same, the model reduces to a regular CNN. Figure 4 shows some real examples of such under-utilization. Meanwhile, we would also like to specialize splines to data, such that each control point handles a subset of classes or clusters more effectively. Both of these problems are common in decision trees, and the typical solution is maximizing the mutual information (MI) I(Y ; Λ) = H(Y ) − H(Y |Λ), where Y and Λ correspond to class labels and (discrete) nodes. In the absence of Y , X can be used to specialize nodes to clusters. In the case of SplineNets, the MI between the class labels and the continuous spline positions is: We choose to use the first form, which explicitly maximizes the position entropy H(φ), which we call the utilization term, and minimizes the conditional position entropy H(φ|Y ), which is the specialization term. Then, our regularizer loss becomes: which should be minimized. The w u and w s are utilization and specialization weights, respectively. To calculate these entropies, the underlying continuous distributions P (φ i ) and P (φ i |Y ) need to be estimated from the N sampled position-label pairs {φ i n , y n } N n=1 . The two most common techniques for this are Kernel Density Estimation (KDE) and quantization. Here, we describe a differentiable quantization method that can be used to estimate these entropies.
Quantization method To approximate P (φ i ) and P (φ i |Y ), we can quantize the splines into B bins and count samples that fall inside each bin. Normalizing the bin histograms can then give us probability estimates that can be used to calculate entropies. However, a loss based on entropy calculated with hard counts cannot be used to regularize the network, since the indicator quantization function is non-differentiable. To solve this problem, we construct a soft quantization function: This function returns almost 1 when position is inside the bin described by the center c b and width w b , and almost 0 otherwise. The parameter υ controls the slope. Figure 5 shows three different slopes used to construct bins. We use this function to discretize the continuous variable φ i with B bins, which turns φ i into the discrete variable Λ i . Thus, the bin probabilities for Λ i = b and the entropy H(Λ i ) become: Pr(Λ i =b) log Pr(Λ i =b).
The specialization term is then: Pr(Λ i =b|Y =c) log Pr(Λ i =b|Y =c).
The effect of using different values of B on P (φ i ) can be seen in Figure 6. Using small B creates artifacts in the distribution, which is why we use B = 50 in our experiments. The effect of specialization can be seen for a 10-class problem (Fashion MNIST) in Figure 7. Here, the top and bottom rows correspond to labeled sample distribution over splines for two consecutive layers, for four different values of w s (columns). Each image has 10 rows corresponding to classes, and 50 columns representing bins, where each bin's label distribution is normalized separately.

Experiments
Architecture SplineNets are generic and can replace any convolutional or dense layer in any CNN.
To demonstrate this, we converted ResNets [19] and LeNets [20] into SplineNets. We converted all convolutional and dense layers into dynamic and hierarchical SplineNet operators, using different decision operators ('dot', 'conv') and knot types ('rank-3', 'rank-4'), and experimented with different number of knots. For ResNet, we relied on the public implementation inside the Tensorflow package with fine-tuned baseline parameters. We modernized LeNet with ReLu and dropout [21]. LeNet has two convolutional layers with C 1 and C 2 filters respectively, followed by two dense layers with H and 10 hidden nodes. We experimented only with models where C 1 =s, C 2 =2s, H=4s for various values of s (depicted as LeNet-s). While the more compact mostly convolutional ResNet is better for demonstrating SplineNet's ability to increase speed or accuracy at the cost of model complexity, LeNet with large dense layers is better suited for showcasing the gains in model size and speed while maintaining (or even increasing) accuracy.
Implementation details We implemented SplineNets in Tensorflow [22] and used stochastic gradient descent with constant momentum (0.9). We initialized all knot weights of a spline together with a normal distribution, with a variance of c/n, where c is a small constant and n is the fan in parameter that is calculated from the constructed operator weight shape. We found that training with conditional convolutions per sample using grouped or depthwise convolutions was prohibitively slow. Therefore we took the linear convolution operator inside the weighted sum over the knots, such that it applies to individual knots rather than their sum. This method effectively combines all knots into a single filter bank and applies convolution in one step, and then takes the weighted sum over its partitions. Note that this is only needed when training with mini-batches; at test time a single sample fully benefits from the theoretical gains in speed.
Hyperparameters A batch size of 250 and learning rate 0.3 were found to be optimal for CIFAR-10. Initializer variance constant c was set to 0.05, number of bins B to 50 and quantization slope υ to 100. We found it useful to add a multiplicative slope parameter inside the decision sigmoid functions, which was set to 0.4. The diffusion parameter had almost no effect on the shallow LeNet, so α was set to 1. With ResNet, optimal diffusion rate was found to be 0.875, but the increase in accuracy was not significant. Regularizer had a more significant effect on the shallow LeNet, with w s and w u set to 0.2 giving the best results. On ResNet, the effect was less significant after fine tuning the initialization and sigmoid slope parameters. Setting w s and w u to 0.05 gave slightly better results. First experiment shows the effect of increasing the number of knots. For these tests we opted for the more compact convolutional decisions and the more powerful rank-3 knots. Figure 8 shows how the accuracy, model size and runtime complexity for a single sample (measured in FLOPS) are affected when going from two to five knots. Evidently, SplineNets deliver on the promise that they can increase model complexity without affecting speed, resulting in higher accuracy. For this setting, both the dynamic and hierarchical models reach nearly 93.4%, while being three times faster than ResNet-110.  Next, we compare all decision and convolution mechanisms for both architectures by fixing K=5.

Spline-ResNet
The results are given in Figure 9. Here, the most powerful SplineNet tested is H(5)-D-R3, with hierarchical, dense projections for each filter, and it matches the accuracy of ResNet-110 with almost half the number of FLOPS. However, a dot product for each filter in every layer creates a quite large model with 42M parameters. Its dynamic-only counterpart has 10M parameters and is three times faster than ResNet-110. With close to 93.5% accuracy, H(5)-D-R4 provides a better trade off between model size and speed with 3.67M parameters. Note that we have not tested more than five knots, and all models should further benefit from increased number of knots.

Spline-LeNet
We trained LeNet-32, LeNet-64 and LeNet-128 as baseline models on CIFAR-10. We used SplineNets with the same parameters of LeNet-32, combined with the more powerful rank-3 knots and dot product decisions. The comparisons in accuracy, runtime complexity and model size are given in Figure 10. Notably, LeNet model size increases rapidly with number of filters, with a large impact on speed as well. Increasing the number of knots in SplineNets is much more efficient in terms of both speed and model size, leading to models that are as accurate as the larger (a) Effect of T and R on number of FLOPS.
(b) Effect of T and R on model size.  Finally, we experimented with Spline-LeNets on MNIST. We augmented MNIST with affine and elastic deformations and trained LeNet-32 as a baseline, which achieved 99.52% on the original, and 99.60% on the augmented dataset. In comparison, H(2)-D-R3 reached 99.61% and 99.65% on the respective datasets. The best score of 99.71% was achieved by H-SN(4) on the augmented dataset with 2.25M parameters. In comparison, CapsuleNets [23] report a score of 99.75% with 8.5M parameters. Higher scores can typically only be reached with ensemble models.

Conclusions and Discussions
In this work, we presented the concept of SplineNets, a novel and practical method for realizing conditional neural networks using embedded continuous manifolds. Our results dramatically reduce runtime complexity and computation costs of CNNs while maintaining or even increasing accuracy.
Like other conditional computation techniques, SplineNets have the added benefit of allowing further efficiency gains through compression, for instance by pruning layers [24,25] in an energy-aware manner [26], by substitution of filters with smaller ones [27], or by quantizing [28,29,30] or binarizing [31] weights. While these methods are mostly orthogonal to our work, one should take care when sparsifying knots independently.
We consider several avenues for future work. The theoretical limit of gains in accuracy from increasing knots is not clear from the results so far, for which we will conduct more experiments. Also there is a large jump in accuracy and model size when switching from rank-4 to rank-3 knots.
To investigate the cases between the two, we will introduce the concept of spline groups, where groups contain rank-3 knots and projections need to be per group rather than per filter. Another interesting direction is using SplineNets to form novel hierarchical generative models. Finally, we will explore methods to jointly train SplineNet ensembles by borrowing from the decision tree literature.