AI Training Outputs - Matrix-Based Files
What form do the outputs take when an AI model is trained?
Unlike traditional programs that involve writing code to create an executable file, an AI model saves the learned weights and biases to a file.
These weights and biases are stored in the form of matrices
, numerical arrays that act as parameters
for the AI model to process input data and make predictions.
Representation of Weights
Once training is complete, each layer of an artificial neural network has defined weights and biases, stored in matrix form.
Weights in a neural network are generally represented as matrices of the shape (number of output neurons, number of input neurons)
.
For example, if a neural network has 3 input neurons and 2 output neurons, its weight matrix would have the shape (2, 3)
.
In this case, each row represents the weight vector for one output neuron, with each output neuron having individual weights for the 3 input neurons.
This is how it would look in code:
weights = [
[0.12, -0.87, 0.45], # Weights for the first output neuron (3 input neurons)
[-0.23, 0.44, 0.56] # Weights for the second output neuron (3 input neurons)
]
In the example above, the weights for the first output neuron are [0.12, -0.87, 0.45]
, representing the weights for the 3 input values.
Similarly, the weights for the second output neuron are [-0.23, 0.44, 0.56]
, connected to the 3 input values.
Weights and Biases in a 2-Layer Neural Network
Let's look at a practical example for a 2-layer neural network.
This network processes two input values, passes them through 3 neurons in a hidden layer, and ultimately produces 2 outputs.
-
First Layer: 2 input neurons → 3 hidden layer neurons (weight matrix size: (3×2))
-
Second Layer: 3 hidden layer neurons → 2 output neurons (weight matrix size: (2×3))
Weights and biases of such a network can be represented as follows:
weights = [
[[0.12, -0.87], # First layer weights (3×2)
[-0.23, 0.44],
[0.31, 0.92]
],
[[0.76, 0.33, -0.21], # Second layer weights (2×3)
[-0.51, 0.67, 0.89]]
]
biases = [
[0.05, -0.12, 0.34], # First layer biases (3 hidden layer neurons)
[0.11, -0.43] # Second layer biases (2 output neurons)
]
These values are stored in matrix (2D array) form and are utilized by the AI model during training and prediction.
Output of Training: Matrix-Constructed Files
Once the AI model has been trained, these matrix data are saved in specific file formats like .h5
, .pt
, .pkl
, .bin
, etc.
For instance, deep learning frameworks like TensorFlow
and PyTorch
enable saving and loading trained models using file formats as follows:
-
TensorFlow (Keras): Saved as
.h5
file -
PyTorch: Saved as
.pt
or.pth
file
That is, the output of AI training constitutes mathematically optimized number matrices to connect input and output, and storing these into a file allows for reuse at any time.