liveBook · Manning

Scalability

As explained in Deep Learning with Python, Third Edition

The practice of increasing model size, data, or training compute to improve performance in machine learning.

Scalability means increasing model size, training data, or compute in pursuit of better machine-learning performance. The practical question is whether the improvement transfers beyond the measured task. section 19.2

Scaling laws describe a predictable relationship between model or dataset size and performance on specific tasks. However, benchmark gains may mainly reflect memorization, while novelty, phrasing sensitivity, and generalizable reasoning remain unresolved. section 19.2

Keep these practical distinctions in mind:

  • Scale input features independently during preprocessing when their value ranges differ. section 4.3.6
  • Prefer a small model with one or two intermediate layers when training data is scarce, reducing severe overfitting. section 4.3.6
  • Treat larger models and datasets as an empirical strategy, not as proof that a different capability or architecture has emerged. section 19.2
  • Scale dot-product attention scores by the square root of vector length to improve softmax-gradient stability. section 15.3.1

Scaling attention scores

In multi-head attention, compute query–key dot products and apply softmax to scores divided by sqrt(head_dim). Longer vectors can produce larger dot products; the scaling factor keeps the softmax gradients more stable. section 15.3.1

query_dense = [layers.Dense(head_dim) for i in range(num_heads)]
key_dense = [layers.Dense(head_dim) for i in range(num_heads)]
value_dense = [layers.Dense(head_dim) for i in range(num_heads)]
output_dense = layers.Dense(head_dim * num_heads)
 
def multi_head_attention(query, key, value):
    head_outputs = []
    for i in range(num_heads):
        query = query_dense[i](query)
        key = key_dense[i](key)
        value = value_dense[i](value)
        scores = np.einsum("btd,bsd->bts", target, source)
        scores = softmax(scores / math.sqrt(head_dim), axis=-1)
        head_output = np.einsum("bts,bsd->btd", scores, source)
        head_outputs.append(head_output)
    outputs = ops.concatenate(head_outputs, axis=-1)
    return output_dense(outputs)
 
multi_head_attention(query=target, key=source, value=source)

Inspect the multi-head attention listing to see scaling applied directly inside the softmax computation. section 15.3.1

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains empirical scaling laws and practical caveats, then applies scaling operationally to feature preprocessing and attention scores.
Examples
Uses regression feature preprocessing, scarce-data model selection, GPT-3 and GPT-4 comparisons, and scaled dot-product attention code.
What you can do after
Evaluate whether scaling improves useful capability, choose smaller models for scarce data, and implement stable attention-score scaling.
How it connects
Connects model size, training data, compute, scaling laws, overfitting, deep learning, Transformers, and attention.

Also explained in

Compare how 27 books explain scalability →

Related concepts

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