Skip to content

Ignore explicit zeros in sparse embedding counts - #4069

Open
HuaTNA wants to merge 1 commit into
huggingface:mainfrom
HuaTNA:fix/sparse-count-explicit-zeros
Open

HuaTNA wants to merge 1 commit into
huggingface:mainfrom
HuaTNA:fix/sparse-count-explicit-zeros

Conversation

@HuaTNA

@HuaTNA HuaTNA commented Sep 23, 2026

Copy link
Copy Markdown

Fixes #4068.

Filter out explicit zero values after coalescing sparse embeddings in compute_count_vector. Sparse and dense representations of the same embeddings now produce the same nonzero counts, including when duplicate sparse entries cancel to zero.

Regression coverage includes 1D and batched embeddings, coalesced and uncoalesced inputs, and all-zero inputs. The four new cases failed before the fix; pytest -q tests/util/test_tensor.py passes all 23 tests afterward. Ruff lint, formatting, and whitespace checks passed.

AI assistance was used to investigate, implement, and test this patch.

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.

compute_count_vector counts explicit sparse zeros as nonzero values

1 participant