Skip to content

fix: persist averaged c_tf_idf rows during evolution_tuning (#2370) - #2563

Open
fanjiahe wants to merge 1 commit into
MaartenGr:masterfrom
fanjiahe:fix/evolution-tuning-ctfidf-update
Open

fanjiahe wants to merge 1 commit into
MaartenGr:masterfrom
fanjiahe:fix/evolution-tuning-ctfidf-update

Conversation

@fanjiahe

@fanjiahe fanjiahe commented Dec 3, 2026

Copy link
Copy Markdown

Fixes #2370 (discussed in #2349).

Summary

In BERTopic.topics_over_time(), when evolution_tuning=True (index != 0), row updates were written to a temporary lil_matrix returned by c_tf_idf.tolil() and never assigned back to c_tf_idf:

c_tf_idf.tolil()[current_overlap_idx] = (...)

Because tolil() returns a copy rather than a view, c_tf_idf remained unchanged and evolution_tuning=True had no effect on extracted topic words or subsequent previous_c_tf_idf slices.

Changes

  • Convert c_tf_idf to lil_matrix, update current_overlap_idx rows with the averaged c_tf_idf values (when current_overlap_idx is non-empty), and convert back to csr_matrix (c_tf_idf = c_tf_idf_lil.tocsr()).
  • Add a regression test (test_evolution_tuning_updates_c_tf_idf) in tests/test_variations/test_dynamic.py verifying that evolution_tuning=True propagates previous-timestamp topic terms into overlapping topics at subsequent timestamps.

Copilot AI balanced review requested due to automatic review settings December 3, 2026 11:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
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.

c_tf_idf update in evolution_tuning (in reference to Discussion #2349)

2 participants