Skip to content

fix: correctly set weights when w is initialized#322

Merged
stephantul merged 2 commits intomainfrom
set-weights-on-init
Apr 17, 2026
Merged

fix: correctly set weights when w is initialized#322
stephantul merged 2 commits intomainfrom
set-weights-on-init

Conversation

@stephantul
Copy link
Copy Markdown
Contributor

When initializing a trainable model with weights, we correctly set the weights in the initializer. However, when calling _initialize, we would call construct_weights, which would ignore the original weights. Because _initialize was always called before fitting (it is called on every fit call), this made us effectively ignore weights.

The fix is straightforward: we save the weights as _weights and initialize w to _weights if it is not None. One interesting thing is that we have to project _weights to the inverse of the sigmoid before doing so.

@stephantul stephantul requested a review from Pringled April 16, 2026 16:06
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
model2vec/train/base.py 98.06% <100.00%> (+0.03%) ⬆️
model2vec/train/utils.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@Pringled Pringled left a comment

Choose a reason for hiding this comment

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

Nice catch!

@stephantul stephantul merged commit fa30df9 into main Apr 17, 2026
9 checks passed
@stephantul stephantul deleted the set-weights-on-init branch April 17, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants