Dense layer

Linear · node type · Gemm, MatMul, MatMulInteger, QLinearMatMul

Every output is a weighted sum of every input plus a bias: the basic learned building block of most networks.

Also called Fully connected, Linear, Gemm, Affine layer, MatMul

Figure 1. Dense layer inside Gas turbine monitor, a real model in WeightSpace. The 3 outlined nodes are Dense layer; select any node for its shapes and parameters.

What it does

A dense layer multiplies its input vector by a weight matrix and adds a bias vector. Each output unit has one weight per input and one bias, so it can mix all input features in any proportion. Stacked with a nonlinearity in between, dense layers can approximate complicated functions; on their own they only draw straight boundaries. They appear as the last layer of almost every classifier, where each output is the logit for one class, and inside transformers as the projections and the feed-forward block. In ONNX a dense layer is a Gemm, or a MatMul followed by an Add.

Formula

y = W x + byj = Σi Wji xi + bj

Shapes and parameters

Shapes
Input [N, K] (or [..., K] for MatMul, which applies the same matrix to every position), weights [K, M], bias [M]; output [N, M].
Parameters
K × M weights plus M biases. A 4 → 8 hidden layer has 4 × 8 + 8 = 40 parameters; a 2000 → 6 classifier head has 12,006.
Used for
Classifier and regression heads, MLPs for tabular data and control, the Q, K, V and output projections in attention, and the feed-forward block of a transformer.

Figure 2. The typed ports of Dense layer, in the same format as every model drawing. Letters such as N or C stand for any size.

In WeightSpace

This is where most WeightSpace edits land. Catalog models expose biases of their final dense layer (and in one reranker, a few of its weights), within ±8 of the shipped value. The game NPC brains are small dense networks, and every weight and bias in them can be edited.

Where it appears