liveBook · Manning

Data representation

As explained in Deep Learning with PyTorch, Second Edition

An internal data encoding produced or consumed by a model.

A data representation is a form of information a model can use. An image, for example, must be encoded as numbers before a neural network can process it. The network then transforms those numbers toward an output, such as a class label. In PyTorch, tensors hold the input, intermediate, and output data. section 3.1 section 3.0

Intermediate representations are collections of floating-point numbers learned for a task. An early stage of image recognition might respond to edges or textures; a deeper stage might capture ears or eyes. Each stage’s representation depends on its input and the preceding layer’s weights. section 3.1

This differs from handcrafting features. To distinguish handwritten 1s from 0s, a person might design edge-direction filters or count enclosed holes. A deep-learning model instead refines useful features from examples and target labels, reducing—but not eliminating—the need for manual feature engineering. section 1.2

Flattening an image into features

A 32 × 32 image with three color values per pixel can be flattened into 3,072 input features. A fully connected classifier can transform those values into 512 hidden features and then two output features for two classes. Flattening makes the image usable as a vector, but this model does not inherently know which pixels were neighbors. section 7.2.2

# In[6]:
import torch.nn as nn

n_out = 2

model = nn.Sequential(
            nn.Linear(
                3072,      #1
                512,       #2
            ),
            nn.Tanh(),
            nn.Linear(
                512,
                n_out,    #3
            )
        )

The PyTorch listing makes that representation path concrete: nn.Linear maps 3,072 inputs to 512 hidden features, nn.Tanh adds a nonlinearity, and a second nn.Linear produces two outputs. section 7.2.2

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Explains floating-point intermediate representations and a worked classifier, but defers handling image spatial structure.
Examples
Uses handwritten-digit features and a 32 × 32 image flattened for a two-class PyTorch classifier.
What it assumes
Introduces floating-point encoding and tensors before relying on basic neural-network layers in the classifier example.
What you can do after
Apply it via PyTorch tensors and nn.Sequential to follow image values through hidden features to class outputs.
How it connects
Connects representations to feature engineering, tensors, neural-network layers, and image classification.

Also explained in

Compare how 4 books explain data representation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.