fix: convert Dataset Column to list before SentenceTransformer.encode#116
Open
octo-patch wants to merge 1 commit into
Open
fix: convert Dataset Column to list before SentenceTransformer.encode#116octo-patch wants to merge 1 commit into
octo-patch wants to merge 1 commit into
Conversation
…fixes HandsOnLLM#79) SentenceTransformer.encode() sorts sentences by length internally using numpy.int64 indices, which HuggingFace Dataset Column objects do not support. This causes a TypeError at encode-time. Wrapping the column with list() converts it to a plain Python list before the call, eliminating the incompatibility.
|
IMO this problem is fixed by pinning sentence transformers as mentioned in this issue (no issue when running colab, pinning transformers, sentence transformers and peft to versions in requirements.txt) |
Author
|
Thanks — pinning works as a workaround, but this 2-line defensive change keeps the notebook running on whatever sentence-transformers / datasets versions a reader happens to install (e.g. fresh Colab runtimes with newer pins). It costs almost nothing and avoids users hitting the same |
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.
Fixes #79
Problem
SentenceTransformer.encode()sorts input sentences by length internally usingnumpy.int64indices. HuggingFaceDatasetcolumn objects (e.g.data["train"]["text"]) do not support indexing withnumpy.int64, which raises aTypeErrorduring encode.Solution
Wrap the column with
list()before passing it tomodel.encode(), converting it to a plain Python list that supports standard numpy indexing:Testing
The fix matches the workaround confirmed in the issue thread. The
list()conversion has zero impact on encode results — it only changes the container type before sort-by-length occurs.