Implementing Feedback Alignment in Tensorflow
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Feedback alignment is a learning rule that replaces the exact backpropagated transpose with fixed random feedback matrices. It is mostly useful for research and experimentation, not as a drop-in replacement for ordinary model.fit. In TensorFlow, the clean way to implement it is a custom training loop where you compute the hidden-layer update explicitly.
What Changes Compared With Backpropagation
In standard backpropagation, the error signal for a hidden layer uses the transpose of the next forward weight matrix. In feedback alignment, that backward path is replaced with a fixed random matrix B that is never trained.
For a two-layer network:
- the forward pass still uses trainable
W1andW2 - the output layer gradient is computed normally
- the hidden layer receives its error signal through
B, notW2transposed
That means automatic differentiation does not “become” feedback alignment automatically. You have to write the custom update rule yourself.
Set Up the Variables Explicitly
A simple TensorFlow implementation starts with raw tf.Variable objects.
The matrix B is the fixed feedback matrix. Its shape matters: it maps output-layer error back into hidden-layer units.
Write a Custom Training Loop
The core of the method is the manual hidden-layer update.
The key line is hidden_signal = tf.matmul(d_logits, B) * relu_grad. In ordinary backpropagation you would use the transpose of W2 there instead.
Evaluate the Learned Model
Once training is done, evaluate the network normally.
For toy problems, feedback alignment can often learn a useful mapping. But it is usually less stable and less efficient than standard backpropagation.
Why a Custom Loop Matters
TensorFlow’s high-level training APIs assume standard gradients. Feedback alignment is a different credit-assignment rule, so you need a training loop where you control the update directly. That is the real implementation boundary.
This is also why feedback alignment is mostly used for experiments and papers rather than mainstream training pipelines. The implementation is not hard, but it is a deliberate departure from the default optimization machinery.
Common Pitfalls
- Expecting automatic differentiation to produce feedback alignment automatically.
- Giving the fixed matrix
Bthe wrong shape. - Forgetting activation derivatives, such as the ReLU mask, in the hidden update.
- Comparing one noisy feedback-alignment run against a polished backprop baseline and drawing strong conclusions too quickly.
- Treating feedback alignment as a production default rather than a research-oriented learning rule.
Summary
- Feedback alignment replaces exact transposed feedback with a fixed random matrix.
- In TensorFlow, the clean implementation is a custom training loop with manual updates.
- The output layer still uses an ordinary gradient; the hidden-layer signal is the approximation.
- Matrix shapes and activation derivatives still matter just as much as in standard training.
- Use feedback alignment as an experiment or teaching tool, not as a default optimizer path.

