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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduced the Word2VecSynonymFilter #12169
Introduced the Word2VecSynonymFilter #12169
Changes from 1 commit
2abb1ea
8f00abc
bf712b9
fc6489b
1b8c9b3
44c0ed5
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of context, I worked with @dantuzi on deciding if implementing a custom reader(this one) or using dl4j as an imported library.
Multiple attempts were done to include dl4j as a library in Lucene, but the effort and impact was not worth it so we reverted to a simple custom reader class.
There are downsides for this of course, ma it's much more lightweight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to avoid dependencies whenever practical
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why pass in the path when it is only used in
toString()
? Can we choose between accepting ajava.nio.Path
that does its own open/close of the zip file and an (anonymous)InputStream
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything comes from the
Word2VecSynonymFilterFactory
that implementsResourceLoaderAware
. This interface provides us aorg.apache.lucene.util.ResourceLoader
and the possibility to obtain an anonymousInputStream
.I decided to pass also the model file path to enrich the Exception message and make the user's life easier.
BTW I don't have a strong opinion about this. I can easily remove that string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed comment by removing the string
word2vecModelFilePath
and changing the exception messageThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to me this would read much clearer using a traditional
while
loop:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this exception is really intended for use with character set encodings only. Maybe IllegalArgumentException would fit better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we use the library DL4J to train a model and we export it, we obtain a compressed zip file.
This zip contains multiple files but we are only interested in file
syn0
. The exception is thrown if the passed zip does not contain anysyn0
file.I guess
IllegalArgumentException
would fitThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems wasteful to lower case every term here, even when they are not b64-encoded. Also: is this something that dl4j will do consistently throughout the file? If so, we can peek at the first term and then assume the remainder will also be b64-encoded. I also wonder about the
trim()
- why do we need it? DoesBase64.decode
leave garbage at the end of the terms sometimes?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your suggestion to read the first term and assume the remaining terms are encoded in the same way.
I did some checks and the
trim()
was useless. Thank you for noticing itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see that we need this interface if its only use is in this one
Dl4jWord2VecSynonymFilter
. Can't we simply refer directly to the implementing class?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you consider using BytesRefHash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never seen the
ByteRefHash
before, thank you for your suggestionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect - the purpose of this method is to return some bytes representing the vector value. I think instead you ought to simply throw
UnsupportedOperationException
since this implementation will never be used in an indexing context where this method is required.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see, this method is not
@Override
so this is not an implementation ofRandomAccessVectorValues
interface. This is a custom method used in our implementationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this copy is meant to do a deep copy, I suspect we'll need to handle it differently, I am not sure it's copying the internal elements, but reusing them?
So a copy could end up adding elements to data structures used by the original Object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not need to do a deep copy; the purpose of this method is to enable multiple concurrent accesses to the underlying data. Since this implementation doesn't have any temporary variable into which vectors are decoded (which could be overwritten), I think it's safe to simply
return this
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msokolov I tried to implement your suggestion but it looks like the method
HnswGraphBuilder::build
doesn't want the same reference passed to theHnswGraphBuilder.create
. [1]To be honest I still don't understand why this check [2] is required
[1]
[2]
lucene/lucene/core/src/java/org/apache/lucene/util/hnsw/HnswGraphBuilder.java
Lines 155 to 158 in 776149f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have more than one implementation? I don't think this interface is necessary. Later we can always add it if we have multiple implementations and need to abstract. For now it's just extra stuff to maintain