Skip to content

Fix activation hook batching, padding trim, and decoding dimensionality#58

Merged
CeliaBenquet merged 1 commit into
celia/test-unified-cebrafrom
ananda/activation-fixes
Jul 24, 2025
Merged

Fix activation hook batching, padding trim, and decoding dimensionality#58
CeliaBenquet merged 1 commit into
celia/test-unified-cebrafrom
ananda/activation-fixes

Conversation

@anandawolz
Copy link
Copy Markdown

@anandawolz anandawolz commented Jul 21, 2025

This PR fixes critical issues in the activation-extraction pipeline and downstream decoding. Previously, activation hooks overwrote outputs per batch, causing loss of data and shape mismatch. Additionally, concatenation and padding removal were not handled for batches >1.

Changes:

  • Hook Accumulation: Changed the activation hook to accumulate outputs per mini-batch in a list.
  • Trimming & Concatenation: Trim padding uniformly across batches. Concatenate along the batch dimension (axis=0) to form (n_windows, channels, time) arrays and then:
  • Reshape: remove the batch dimension to yield (channels, time) arrays to avoid error for kNN decoding, ensuring compatibility with scikit-learn

tests are not passing because _cut_array doesn't handle 2D activation arrays yet. This is handled in PR #59

Copy link
Copy Markdown
Member

@CeliaBenquet CeliaBenquet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! As discussed with @anandawolz, some of the changes are overridden and tests pass in #59. @anandawolz can you update the main comment with what was not functional in this one.

Comment thread cebra_lens/activations.py
sliced_array = array[:, start:end if end != 0 else start:]
return sliced_array

return array
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor and no need to reverse, but in general it is better software engineer practice to create a variable in the if statement and return only once, once you exit the if-else: https://jdriven.com/blog/2021/10/Single-return-vs-Multiple-returns.

@CeliaBenquet CeliaBenquet merged commit 2482830 into celia/test-unified-cebra Jul 24, 2025
@MMathisLab MMathisLab deleted the ananda/activation-fixes branch April 14, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working 🥇 merge first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants