Inside the honeybee nest

A honeybee nest is both a nursery and a food store. How is that shared space organized?

We use a masked-convolutional neural network to predict a cell’s contents from its neighbors and its position in the nest. Masking excludes the cell’s own contents from the input, so the model must use the surrounding pattern rather than copy the answer.

We trained models with seven combinations of spatial axes and evaluated their predictions in intact and shuffled nests. Full 3D context gave the highest predictive likelihood in control colonies; physical and simulated shuffling reduced predictive likelihood to 2D levels.

PhotographWe photographed both sides of every comb at each observation.
SegmentWe trained a neural network to label cell contents.
ReconstructWe aligned both sides of each comb to reconstruct the nest.
Across timeWe repeated the reconstruction across the season.

Cell contents across the nest

Colony DD1

We reconstructed cell-content maps across repeated observations of colony DD1. The figures link each mapped cell to the local neighborhood and global position used by our model.

Opening one real nest…

How the model predicts a cell

Local context + global position

Our model combines features of the surrounding cells with a learned representation of global position. Together, these inputs determine the predicted probabilities for the masked cell’s contents.

The masked cell determines the displayed neighborhood and coordinates.

The four stages show how our model computes a prediction.

1Local context

Which spatial directions help predict a cell’s contents?

Height and width run within comb sides; depth runs across them. Each option shows the inputs to a separately trained model configuration.

3D includes neighbors within and across comb sides, and global position along all three axes.

100%

26 neighbor positions3 × 3 × 3 kernel, minus its center

Class embeddings

Each content type becomes a set of learned numerical features, its embedding. The shared table E supplies these features wherever that type occurs.

Masked convolution

Feature values0.20.6−0.40.8?−0.20.40.10.7×Kernel weights0.5−0.20.30.100.4−0.30.20.1Sum−0.17One context featureWeighted sum; center excluded

The masked convolution combines neighbor features using learned weights for each offset. Its output C describes the local pattern while excluding the masked cell.

Context CLocal context
How masked convolution works

A kernel assigns weights to positions around the masked cell. Each weight multiplies the features at the matching position; adding these contributions produces a local description. The center weight is zero, so the cell cannot supply its own answer.

Match the kernel to the neighborhood

100%

NegativePositive

Kernel color shows the mean weight at each offset for this context feature.

Same weights at every positionMasked cell
Multiply matching features and weights
Add the weighted neighbor features

This figure isolates one learned context feature. For each neighbor, the model computes a dot product between its class embedding and the kernel weights at that offset, then adds the shared baseline.

Predict from the surrounding pattern

Fitted DD1 model

Background
Wood
Empty comb
Brood
Pollen
Nectar / honey
Repeat through the volume
100%

The outlined prediction matches the masked input cell. The animation shows predictions accumulating across the patch.

Real DD1 cells and fitted kernel weights are used here. The probabilities include all context features, global position and interactions. The animation visits positions in sequence; the model computes them in parallel.

2Global position

The model applies the same local filter at every cell, so identical neighborhoods produce the same local-context features. To capture the nest’s global layout, we also give the model the masked cell’s coordinates, allowing it to learn nest-wide patterns in cell contents.

Depth · Height · Width

100%

Depth, row, and column locate the cell.

Positional embedding

During training, the model learns a feature vector P for each position along the included spatial axes. The masked cell’s coordinates select this vector, which the model adds to local context before the interaction module. Models that exclude an axis share the same position features along that axis.

Position in the nestLearned features
Global position PGlobal position
A shared baseline everywhere

One learned global bias vector is added at every cell, supplying a shared baseline alongside the position-specific features.

One shared vectorPosition 1Position 2Position 3

3Interactions

Interactions let one feature strengthen or weaken another’s contribution. The model learns combinations within local context and between local context and global position.

Q = C + PAdd matching continuous feature values
Negative
0
Positive
Residual Q

Learned mixture W₁Q

Learned mixture W₂Q

Learned feature interactions

I = (W₁Q) ⊙ (W₂Q)

The model multiplies matching features to represent their joint contribution.

+ Q residual addition
H = Q + IOne combined embedding
A combination within local context

Together, brood and pollen neighbors increase the model’s prediction of pollen at the masked cell.

Local context · brood
Local context · pollen
Raises pollen scoreLowers pollen scoreThicker = larger contribution
Observed Pollen

Probability of pollen

Without term
67.9%
Full model
96.1%

Local context × global position

This neighborhood becomes more predictive of empty comb when its features interact with global position.

Local context
Global position
Raises empty-comb scoreLowers empty-comb scoreThicker = larger contribution
Observed Empty comb

Probability of empty comb

Without term
56.9%
Full model
91.7%

4Class probabilities

The output features H combine local context, global position and learned interactions. The model computes their dot product with each class embedding in the same class table E used at input. Each dot product gives a raw class score, or logit. Softmax turns these scores into conditional class probabilities.

Dot products with class embeddings
Combined features H
Shared class embeddings E
z = E H  ·  zc = E[c] · H
Raw class scores (logits)

One dot product per class.
Scores can be negative and need not sum to one.

Softmax

Softmax converts the class scores into probabilities that sum to one.

p(class | context, position)

Loading fitted probabilities…

p0Background
p1Wood
p2Empty comb
p3Brood
p4Pollen
p5Nectar / honey

The largest probability gives the predicted class. The probability assigned to the recorded class measures how well the model explains that observation.

Training objective and log likelihood

The model learns by assigning more probability to observed contents. Log likelihood measures that probability on a logarithmic scale; its negative is the prediction loss. Confident mistakes receive larger losses.

Likelihood across the nest

100%
Low likelihood · p = 0High likelihood · p = 1

Comb contents only · fitted 3D model · DD1

The masked cell

Observed —

Probability of the observed class
—
Log likelihood · log p
—
Negative log likelihood · −log p
—

The likelihood map and nest maps share the same selected cell.

What training minimizes

Nest contents are unevenly represented, so common classes supplied most of the training signal and dominated learning without weighting. We use class-weighted cross-entropy, increasing the influence of each example from a rarer class through inverse-frequency weights. This helps the model learn to distinguish all types of nest contents, rather than mainly improving predictions for the most common ones.

ℒ =Σi w(yi) [−log p(yi | contexti, positioni)]Σi w(yi)

Here yi is the observed class and w(yi) its weight. Training includes all six classes and treats each observation independently. The map can show the probability assigned to each cell’s observed class, its log likelihood, or its negative log likelihood. Log likelihood and negative log likelihood use natural-log units (nats).

1 of 4

Which spatial relationships make the nest predictable?

We used the same masked-cell prediction task to compare spatial dimensions and measure the effects of comb-frame shuffling.

Comparing spatial dimensions

1D2D3DDepthHeightWidthDepth × heightDepth × widthHeight × widthDepth × height × width
The spatial contexts we compared · current cell neighborhood

We trained seven model configurations: depth, height, width, depth × height, depth × width, height × width, and all three axes. Each configuration used local context and global position only along its included axes. Height and width run within comb sides; depth runs across them.

In control colonies, the full 3D model assigned the highest probability to observed contents across all content classes. The spatial-context selector in step 1 shows the inputs available to each configuration.

Testing comb-frame shuffling

Original arrangementShuffled frames43212413

We randomly rearranged the order and orientation of comb frames every week in six colonies and left six control colonies unshuffled. We also simulated shuffling of control-nest maps by randomizing frame order, keeping the two sides of each frame paired.

We trained the models on unshuffled control colonies, then evaluated them on control colonies, physically shuffled colonies, and simulated-shuffled control maps. Both forms of shuffling reduced predictive likelihood toward 2D levels. Pollen and nectar/honey predictions lost particularly strongly: their 3D likelihoods fell below the 2D average.

What does a good prediction tell us?

These comparisons showed that intact 3D nest organization supplied predictive information beyond individual axes or planes. Shuffling disrupted relationships between frames and their global depth positions while preserving each frame’s contents. The results quantify spatial organization; they do not establish which behavioral mechanisms produce it.

Technical notes on the diagram

For a selected voxel v (a cell-sized grid region), let N(v) contain the offsets included by the axis selection, excluding the center. The class table E is shared between input and output. At that cell the computation is

  1. ContextCv = Σδ ∈ N(v) Wδ E[xv+δ] + b
  2. PositionPv = P[d′, h′, w′]
  3. AddQv = Cv + Pv
  4. InteractIv = (W₁Qv) ⊙ (W₂Qv)
  5. ResidualHv = Qv + Iv
  6. Classifyzv,c = Hv · E[c]; pv = softmax(zv)

The colored feature strips and positional-table values are schematic, not fitted parameter exports. They respond consistently to the selected neighborhood and position; the probabilities and likelihood maps use fitted model outputs.

E includes the implementation’s shared class bias; C includes the convolutional bias. W₁ and W₂ are 1 × 1 × 1 convolutions without bias. They mix features at a cell, not spatial positions. Their product includes context–context, position–position and mixed terms; it is not restricted to context × position.

An excluded coordinate is replaced by a singleton index in the positional table, then broadcast. It cannot distinguish positions along that axis. Outside-grid neighbors receive zero feature padding, which is different from the learned background-class embedding.

This model is described as autoregressive because it predicts a cell from other cells. Its center mask permits neighbors on both sides. It estimates spatial conditionals, without imposing a scan order or a joint probability for the whole nest.

About these maps and illustrations

Colony DD1 is shown across repeated observations. The fitted 3D probabilities come from training on the original, unshuffled colonies, including DD1. Colors are image-segmentation labels from photographs, grouped into the model’s content classes. They may contain classification errors.

Comb sides are aligned and stacked in their original order. Opposite sides stay paired. Adjustable spacing helps you see between combs.

Research in progress. Research team: Peter R. Marting, P. Prathibha, Ben Koger, Stephanie R. Rogers, Jake Graving and Michael L. Smith. Model explanation and interactive visualization by Jake Graving.

Reference

Marting, P.R., P. Prathibha, Koger, B., Rogers, S.R., Graving, J.M., Smith, M.L. (in review). Morphogenesis, differentiation, and robust multi-scale organization of the honeybee nest revealed by a novel 4D atlas. Current Biology. In review.