0
0
TensorFlowml~12 mins

Dataset from tensors in TensorFlow - Model Pipeline Trace

Choose your learning style9 modes available
Model Pipeline - Dataset from tensors

This pipeline shows how to create a dataset directly from tensors, then use it to train a simple model. It starts with raw data in tensors, builds a dataset, trains a model, and makes predictions.

Data Flow - 3 Stages
1Raw tensors
NoneCreate tensors for features and labels5 rows x 3 columns (features), 5 rows x 1 column (labels)
[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0], [10.0, 11.0, 12.0], [13.0, 14.0, 15.0]] (features), [0, 1, 0, 1, 0] (labels)
2Dataset creation
5 rows x 3 columns (features), 5 rows x 1 column (labels)Create tf.data.Dataset from tensors5 elements of (3 features, 1 label)
Dataset element example: (features=[1.0, 2.0, 3.0], label=0)
3Batching
5 elements of (3 features, 1 label)Batch dataset into groups of 23 batches: 2 elements, 2 elements, 1 element
Batch 1: features=[[1.0,2.0,3.0],[4.0,5.0,6.0]], labels=[0,1]
Training Trace - Epoch by Epoch
Loss
0.7 |****
0.6 |*** 
0.5 |**  
0.4 |*   
0.3 |    
     1 2 3 4 5 Epochs
EpochLoss ↓Accuracy ↑Observation
10.6930.40Initial loss is high, accuracy low as model starts learning
20.5800.60Loss decreases, accuracy improves as model learns patterns
30.4800.80Model continues to improve, loss goes down, accuracy up
40.4000.80Loss decreases further, accuracy stabilizes
50.3501.00Model fits data well, perfect accuracy on training set
Prediction Trace - 3 Layers
Layer 1: Input layer
Layer 2: Dense layer with ReLU
Layer 3: Output layer with sigmoid
Model Quiz - 3 Questions
Test your understanding
What is the shape of the dataset after batching?
A3 batches: 2 elements, 2 elements, 1 element
B5 batches: 1 element each
C1 batch: 5 elements
D2 batches: 3 elements, 2 elements
Key Insight
Creating a dataset from tensors allows easy feeding of data into TensorFlow models. Batching helps training efficiency. Loss decreasing and accuracy increasing show the model is learning well.