Fix LSI dimension mismatch with native Ruby SVD#78
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a dimension mismatch error (ExceptionForMatrix::ErrDimensionMismatch) that occurs when classifying documents using native Ruby SVD with 10+ similar documents. The root cause is that Ruby's native SVD implementation returns transposed dimensions when there are fewer unique terms than documents, causing query vectors to have incompatible dimensions with document vectors during comparison.
Key Changes:
- Fixed iteration to use
column_sizeinstead ofrow_sizewhen building the document index - Added dimension validation and transposition logic to handle native Ruby SVD's behavior
- Ensured consistent matrix dimensions between GSL and native Ruby implementations
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Native Ruby SVD returns transposed matrix dimensions when row_size < column_size (common case: few terms, many documents). This caused ExceptionForMatrix::ErrDimensionMismatch during classification with 10+ similar documents. Two changes: - Transpose reduced matrix when dimensions don't match input - Iterate over column_size (documents) not row_size (terms) Fixes #72
37ae2e3 to
4b67850
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ExceptionForMatrix::ErrDimensionMismatchwhen classifying with 10+ similar documents using native Ruby SVDRoot Cause
Native Ruby SVD returns transposed dimensions when
row_size < column_size(common case: few unique terms, many documents). This caused query vectors (5 elements) to be compared against document vectors (20 elements).Test Plan
NATIVE_VECTOR=trueFixes #72