Skip to content

Commit d986637

Browse files
committed
Add initial documentation for all implemented networks.
1 parent 6bac54d commit d986637

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

Diff for: README.md

+54-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Forward-Forward Neural Networks Library
22

3-
FFLib is a neural network library based on PyTorch that aims to implement
4-
several different types of layers and networks based on the Forward-Forward algorithm.
3+
FFLib is a neural network library based on PyTorch [2] that aims to implement
4+
several different types of layers and networks based on the Forward-Forward algorithm [1].
55
The library also provides a suite of tools for training, validating, testing, debugging and experimenting
66
with Forward-Forward-based networks. We aim to make this library as close as possible
77
to the original design and structure of the PyTorch library.
@@ -31,7 +31,7 @@ and making interactive execution only afterwards.
3131

3232
The Forward-Forward Algorithm was introduced in Geoffrey Hinton's paper
3333
["The Forward-Forward Algorithm: Some Preliminary Investigations"](https://arxiv.org/abs/2212.13345)
34-
with the following abstract:
34+
[1] with the following abstract:
3535

3636
```
3737
The aim of this paper is to introduce a new learning procedure for neural networks and to
@@ -48,6 +48,50 @@ in the positive pass and allow video to be pipelined through the network without
4848
storing activities or stopping to propagate derivatives.
4949
```
5050

51+
## Types of FF Networks
52+
53+
There are 3 different types of Forward-Forward-based Neural Networks implemented in the FFLib:
54+
- [**FFNet**](#ffnet) - [example usage](./examples/ff_net_mnist.py)
55+
- [**FF+C**](#ffc) - [example usage](./examples/ff_c_mnist.py)
56+
- [**FFRNN**](#ffrnn) - [example usage](./examples/ff_rnn_mnist.py)
57+
58+
### FFNet
59+
60+
The basic example of a Neural Network based on the Forward-Forward Algorithm.
61+
In the example file the following network specifications are used:
62+
- 2 Dense layers with 2000 neurons each
63+
- Predicting the MNIST dataset with TryAll probe
64+
- Batch Size of 128
65+
66+
When a dense layer accepts an input, it is first detached from the graph
67+
and normalized before applying the weight multiplication.
68+
Essentially, it's just a linear layer that gets a detached normalized input.
69+
The trick is that each layer optimizes its "goodness"
70+
to be positive for "positive" data and negative for "negative" data.
71+
In the case of FFNet, the input and output has to be combined
72+
and given as an input to the network (to the first layer).
73+
Since there's no output of the network, we have to try all inputs when predicting.
74+
In the FFLib, there are special classes called [probes](./src/fflib/probes/__init__.py).
75+
We use the [TryAll probe](./src/fflib/probes/one_hot.py) to try all possible one-hot labels.
76+
77+
### FF+C
78+
79+
FF+C is a type of hybrid Neural Network that uses both, the Forward-Forward Algorithm
80+
and ordinary backpropagation to avoid the need ot the TryAll probe.
81+
The FF part is used as a feature extractor and it is trained the same way as the original FF network.
82+
The Classifier is another dense layer that as input gets the
83+
concatenated activations from both of the FF Dense layers and tries to predict the one-hot label.
84+
85+
### FFRNN
86+
87+
The Forward-Forward Recurrent Neural Network is the most complex type of FF network implemented
88+
in the FFLib. It is made of a special type of layer called [FFRecurrentLayer](./src/fflib/nn/ff_recurrent_layer.py).
89+
The example file contains an example usage of the FFRNN with 2 FF Recurrent Layers, both with 2000 neurons.
90+
These networks are quite large due to the fact that each layer has not only weights
91+
from the previous layer, but also backward weights from the next layer.
92+
These networks have to be trained with multiple frames per batch, thus
93+
requiring even more time for both, training and inference.
94+
5195
## Contributions
5296

5397
We really appreciate contributions from the community!
@@ -91,6 +135,8 @@ We also recommend installing the VSCode extension
91135
[GitHub Local Actions](https://marketplace.visualstudio.com/items?itemName=SanjulaGanepola.github-local-actions)
92136
to run the workflows from inside VSCode, making the process painless.
93137

138+
Example scenarios are also tested in GitHub Actions by running them from the CLI.
139+
94140
## General Guidelines
95141

96142
Here are a few guidelines to following while contributing on the library:
@@ -100,3 +146,8 @@ Here are a few guidelines to following while contributing on the library:
100146
- Strict formatting style guidelines using `black`
101147
- No recursion (at our abstraction level)
102148
- Nicely documented functions and classes
149+
150+
## References
151+
152+
- [**[1]**](https://arxiv.org/abs/2212.13345) - Hinton, G. (2022). The Forward-Forward Algorithm: Some preliminary investigations.
153+
- [**[2]**](https://pytorch.org/) - PyTorch.

0 commit comments

Comments
 (0)