This is a simple implementation of a Recurrent Neural Network (RNN) in pure C.
It demonstrates the concept of forward propagation over a sequence of time-series inputs without using any external libraries.
rnn-c/
βββ include/ # Header files
β βββ rnn.h # RNN structure and declarations
β βββ utils.h # Utility functions (e.g., matrix multiplication)
βββ src/ # Source code
β βββ rnn.c # RNN logic (init, forward, print)
β βββ utils.c # Math utility implementation
βββ data/ # Example input data (optional)
β βββ sample_input.txt
βββ main.c # Program entry point
βββ Makefile # Build configuration
βββ README.md # This file
- GCC or compatible C compiler (e.g.
gcc,clang) make(for building the project)
git clone https://github.com/nomadsdev/rnn-model-with-c.git
cd rnn-cmakeThis compiles all .c files and generates an executable named rnn.
./rnnTime step 0: Output: 0.4938
Time step 1: Output: 0.4962
Time step 2: Output: 0.4975
The program performs forward propagation across 3 time steps using a hardcoded input sequence (0.1, 0.5, 0.9) and prints the output of the RNN at each step.
To change the input sequence:
- Open
main.c - Modify the
inputs[]array:
float inputs[] = {0.2f, 0.4f, 0.6f, 0.8f};- Rebuild the project:
make clean && make
./rnnHere are some ideas for improving this base project:
- β Add Backpropagation Through Time (BPTT)
- π Loss function and training loop
- π Load input from file (
sample_input.txt) - π§ Increase model complexity (e.g., stacked RNN layers)
- πΎ Save and load weights to/from file