liveBook · Manning

Weighted average

As explained in Inside Deep Learning: Math, Algorithms, Models

An average in which each term is multiplied by a weight before summation.

A weighted average multiplies each feature representation hᵢ by an attention weight αᵢ, then sums the results: x̄ = Σᵢ αᵢ · hᵢ. In PyTorch, the weights must be reshaped to align with the feature tensor for pairwise multiplication. section 10.1.3

An attention-based implementation follows this path:

  • Extract one representation hᵢ for each item with a feature-extraction or backbone network. section 10.1.3
  • Multiply corresponding weights and representations, then sum across the item dimension to produce one combined representation. section 10.1.3

Combining a three-item bag

For a bag containing three digit images, the backbone produces three feature vectors and the attention network assigns each a score. The Combiner forms one representation from their weighted sum, which feeds the classifier.

How Inside Deep Learning: Math, Algorithms, Models covers it

How deep it goes
Explains the formula, tensor alignment, normalization, and Combiner implementation, but stops short of deriving the attention scores.
Examples
Demonstrates three digit images, learned attention scores, feature vectors, and a plotted weighted bag representation workflow.
What it assumes
Assumes familiarity with feature vectors, neural networks, tensor dimensions, and pairwise multiplication.
What you can do after
Apply it via PyTorch by building a Combiner that aggregates normalized attention-weighted feature vectors.
How it connects
Connects weighted averages to attention mechanisms, feature extraction, Softmax normalization, tensor shapes, and classification.

Also explained in

Compare how 5 books explain weighted average →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Inside Deep Learning: Math, Algorithms, Models. The section links point to the parts of the book it draws on.