Kahibaro
Discord Login Register

8 Feedforward Networks for Structured Data

What Structured Data Means in This Course

Structured data is the kind of data that fits naturally into rows and columns, like spreadsheets and SQL tables. Each row is one example, and each column is a feature such as age, income, country, number of purchases, or a category code. In this section of the course, the default model you will reach for is a feedforward neural network, often called a multi layer perceptron. It expects each example to be represented as a fixed length vector, so the central job is turning your table into a clean numeric tensor of shape $(N, D)$, where $N$ is the number of rows in a batch and $D$ is the number of input features after preprocessing.

A key distinction in tabular data is between numeric features and categorical features. Numeric features can often be used directly after scaling. Categorical features should not be naively converted to arbitrary integers and treated as numeric magnitudes, they need a representation that preserves category identity without implying order.

The Standard Pipeline: From Table to Tensor

A typical structured data pipeline for deep learning has four conceptual steps. First, you decide what the target is and which columns are inputs. Second, you split columns into numeric and categorical groups. Third, you preprocess numeric columns and encode categorical columns, usually with embeddings. Fourth, you concatenate everything into a single vector per row and feed it into an MLP.

The result is that your model input is a tensor built from two sources. One source is a float tensor for numeric features, typically torch.float32. The other source is one or more integer tensors for categorical features, typically torch.int64, which are used to index embedding tables. After embedding lookup, those become float vectors too, and you concatenate them with the numeric floats.

What Changes Compared to “Basic Models”

Earlier in the course you trained simple models end to end. With structured data, the training loop is usually the same, but the input construction is more deliberate. The most common beginner mistake is to focus on the neural network and ignore data representation. For tabular problems, good representation and consistent preprocessing often matter as much as the architecture.

A feedforward network for structured data assumes each feature position means the same thing in every example. If your preprocessing changes between training and evaluation, your model will silently break.

Input and Output Shapes You Should Expect

For a batch of $N$ examples, numeric features typically form a tensor $X_{\text{num}} \in \mathbb{R}^{N \times D_{\text{num}}}$. Each categorical column $k$ forms an integer tensor $x^{(k)}_{\text{cat}} \in \{0,\dots,C_k-1\}^{N}$, where $C_k$ is the number of categories for that column after you build a vocabulary.

An embedding layer maps each categorical column into a dense vector. If column $k$ uses embedding size $E_k$, then after embedding you get $X^{(k)}_{\text{emb}} \in \mathbb{R}^{N \times E_k}$. Concatenation produces a single design matrix
$$
X = \big[ X_{\text{num}}, X^{(1)}_{\text{emb}}, \dots, X^{(K)}_{\text{emb}} \big] \in \mathbb{R}^{N \times D},
$$
where $D = D_{\text{num}} + \sum_{k=1}^K E_k$.

The model output shape depends on the task. For regression it is often $(N, 1)$ or $(N,)$. For binary classification it is commonly logits of shape $(N, 1)$ or $(N,)$. For multiclass classification it is logits of shape $(N, C)$.

The Main Modeling Choice in This Section

The defining modeling idea here is that categorical variables are usually represented with embeddings rather than one hot vectors when there are many categories, and numeric variables are typically standardized before the network sees them. Once everything is turned into a float vector per row, an MLP can learn nonlinear interactions between features.

The rest of this section will break down the specific tools that make this pipeline work in PyTorch, including scaling numeric columns, embedding categorical columns, constructing an MLP, choosing reasonable hidden sizes, and evaluating tabular tasks with appropriate metrics.

Views: 71

Comments

Please login to add a comment.

Don't have an account? Register now!