Theano HiddenLayer Activation Function
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Theano's HiddenLayer is a core component in building neural networks using the Theano library. Theano, although no longer under active development, laid the foundation for many modern deep learning frameworks such as TensorFlow and PyTorch. It's crucial to understand the workings of its components, such as the HiddenLayer, for historical context and for understanding some foundational aspects of deep learning.
Understanding HiddenLayer in Theano
A HiddenLayer is essentially a fully connected layer that consists of neurons, each receiving input, applying a linear transformation followed by a non-linear activation function. The linear transformation is typically parameterized by weights and biases that are learned during the training of the network. The essential purpose of this layer is to introduce non-linearity into the model, which enhances its ability to make complex predictions.
Components of HiddenLayer
- Weights () and Biases ():
Each neuron in the hidden layer has associated weights and a bias that help in determining the neuron's output.- Weights (): These are parameters associated with every input feature that gets adjusted during training. They're initialized using different strategies such as zero initialization, random initialization, Xavier initialization, etc.
- Biases (): Bias is an additional parameter used to shift the activation function. It helps the model fit the data better by adjusting the output independent of the input.
- Activation Function ():
The non-linear activation function applied to the weighted sum of inputs and bias. Activations like sigmoid, tanh, ReLU are commonly used. The choice of activation function impacts the learning and predictive power of the neural network significantly. - Linear Transformation:
The output of the linear transformation for a neuron is typically given by: where is the scalar input to the activation function, is the input vector, and and are the weights and bias respectively. - Output () from the Activation Function:
The activated output is computed as: where is the chosen activation function.
Common Activation Functions
Sigmoid Function
- Formula:
- Properties:
The sigmoid function maps inputs to a range between 0 and 1, making it useful for binary classification. - Drawbacks:
Susceptible to issues like vanishing gradients for large positive or negative inputs which leads to slow convergence during training.
Hyperbolic Tangent (Tanh)
- Formula:
- Properties:
Outputs values between -1 and 1, centered around zero, which generally leads to faster convergence compared to sigmoid.
Rectified Linear Unit (ReLU)
- Formula:
- Properties:
ReLU introduces non-linearity while maintaining a simple nature, promoting sparsity of activations and computational efficiency. - Drawbacks:
It can suffer from the "dying ReLU" problem, where neurons can become inactive during training if they output zero for any input.
Example: Implementing a HiddenLayer in Theano
Related reading
- Theano simple linear regression runs on CPU instead of GPU
- Things to try when Neural Network not Converging
- This model has not yet been built error on model.summary
- This TensorFlow binary is optimized with IntelR MKL-DNN to use the following CPU instructions in performance critical
- This version of TensorFlow Probability requires TensorFlow version 2.3
- thresholds in roc_curve in scikit learn
- TicTacToe AI Making Incorrect Decisions
- Tied weights in Autoencoder
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.