Understanding Deep Learning Through Piecewise Fitting
This article explains deep learning using an intuitive piecewise fitting analogy. It covers the minimal model of linear and nonlinear transformations, how hidden units fit local segments of a curve, how training distributes error through backpropagation, the engineering meaning of key hyperparameters, a general cloud deployment workflow, and common pitfalls with a troubleshooting checklist.
1. The Question: Can Deep Learning Be Visualized Like Arithmetic?
Deep learning now underpins search, recommendation, speech, vision, and content generation, yet its internal mechanics are often described in overly abstract terms. One effective way to make it concrete is to view it as piecewise fitting: any complex curve can be split into a few easy-to-describe local segments, then reconstructed from a combination of simple functions. This view is as plain as addition, subtraction, multiplication, and division, but it is enough to carry the core logic of neural networks.
2. A Minimal Working Model: One Input, One Processing Unit, One Output
Reduce the network to its simplest form, keeping only the input X, a processing unit, and the output Y’. The processing unit does two things: it applies a linear transformation first, then a nonlinear one.
X --[ linear: w*x + b ]--> z --[ nonlinear: r(z) ]--> Y'
The linear part handles scaling and shifting; the nonlinear part handles bending and switching. Only by alternating and stacking the two can the model express non-proportional relationships.
3. Linear and Nonlinear: Roles and Boundaries
A linear function has the form y = w*x + b, where the output is a weighted sum of the input plus a bias. Its strengths are simplicity, easy differentiation, and easy optimization; its weakness is that no matter how many layers you stack, the whole remains linear and cannot capture complex patterns.
Nonlinear functions break proportionality and introduce structures such as kinks, saturation, and thresholds, letting the network fold and partition the input space into multiple regions. Common choices include threshold-style activations, saturating activations, and element-wise nonlinearities, which determine how and where the bending happens.
4. Cutting a Curve into Three Segments: A Concrete Demo of Piecewise Fitting
Assume the target curve roughly has three segments: a gentle rise on the left, a plateau in the middle, and a steep rise on the right. Assign each of three processing units to one segment, have each output a local estimate, then sum them with weights to get the overall result:
import numpy as npdef linear(x, w, b): # linear transformationreturn w * x + bdef relu(z): # element-wise nonlinearityreturn np.maximum(0.0, z)def piecewise(x, W, b, V):# W, b: linear parameters per segment; V: combining weights for each segment's outputz = linear(x, W, b) # shape: (num_segments, num_samples)h = relu(z) # bend: zero out the negative half-axisreturn V @ h # combine: weighted sum
Intuitively, each hidden unit “opens a window” along the input axis: it responds linearly inside the window and is flattened by the activation outside it. Stacking multiple windows reconstructs the target curve. Increasing the number of segments (width) fits more complex shapes, while increasing the number of layers (depth) expresses more “folded” structures with fewer units.
5. Training: Assigning Responsibility via Error Backpropagation
Parameters are not set by hand; they are driven by data. The process has four steps:
- Forward propagation: compute Y’ from X to get the current estimate.
- Compute the loss: measure the gap between Y’ and the true Y using mean squared error, cross-entropy, or similar.
- Backpropagation: use the chain rule to distribute the error to each w and b according to contribution.
- Parameter update: take small steps in the direction opposite the gradient, iterating until convergence.
# Pseudocode: general skeleton of gradient descentfor epoch in range(epochs):y_pred = forward(X, params)loss = mean((y_pred - Y) ** 2)grads = backward(loss, params) # chain ruleparams = params - lr * grads # learning rate controls step size
6. Engineering Meaning of Key Hyperparameters
- Depth: determines the complexity of function folding; too deep leads to vanishing gradients and overfitting.
- Width: determines the granularity of segmentation; too wide brings redundancy and wasted compute.
- Activation choice: affects the bending style and gradient propagation efficiency.
- Learning rate and batch size: affect convergence speed and stability.
- Regularization and early stopping: suppress over-memorization of training samples.
7. A General Workflow for Running on the Cloud
Engineering practice usually follows a closed loop of “data—training—evaluation—serving”: on the data side, object storage holds samples and a message queue decouples the data pipeline; on the training side, a container platform elastically scales compute, while logging and monitoring/alerting track loss and resource metrics; on the serving side, an inference API exposes the capability and continuously feeds data back for iteration. The general cloud product categories offered by Baidu AI Cloud can support these stages, and specific choices should be evaluated based on data scale, latency requirements, and cost budget.
8. Common Misconceptions and a Troubleshooting Checklist
- Misconception 1: More layers are always better. In practice, this is constrained by data volume and regularization.
- Misconception 2: Activation functions can be swapped arbitrarily. Different activations are sensitive to initialization and learning rate.
- Misconception 3: A dropping training loss means success. You must also watch the validation set and generalization.
- Troubleshooting order: first check data and label quality, then normalization and initialization, and finally the architecture and hyperparameters.
9. Conclusion
Understanding deep learning as “piecewise fitting plus error allocation” lets you grasp its mechanics with plain intuition: linear transformations handle positioning and scaling, nonlinear activations handle bending and partitioning, and loss and gradients distribute the overall error to every parameter. With this mental model, whether reading papers or tuning engineering systems, you can locate problems faster and make sound trade-offs.
