-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
[ML] fix LangIdent model when multiple unicode scripts are present #81876
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,7 +229,7 @@ public InferenceResults infer(Map<String, Object> fields, InferenceConfig config | |
); | ||
} | ||
List<?> embeddedVector = (List<?>) vector; | ||
double[] scores = new double[LANGUAGE_NAMES.size()]; | ||
double[] probabilities = new double[LANGUAGE_NAMES.size()]; | ||
int totalLen = 0; | ||
for (Object vec : embeddedVector) { | ||
if (vec instanceof CustomWordEmbedding.StringLengthAndEmbedding == false) { | ||
|
@@ -240,12 +240,11 @@ public InferenceResults infer(Map<String, Object> fields, InferenceConfig config | |
totalLen += square; | ||
double[] h0 = hiddenLayer.productPlusBias(false, stringLengthAndEmbedding.getEmbedding()); | ||
double[] score = softmaxLayer.productPlusBias(true, h0); | ||
sumDoubleArrays(scores, score, Math.max(square, 1)); | ||
sumDoubleArrays(probabilities, softMax(score), Math.max(square, 1)); | ||
} | ||
if (totalLen != 0) { | ||
divMut(scores, totalLen); | ||
divMut(probabilities, totalLen); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like it is worth noting somewhere (maybe in docs) in multilingual cases the probabilities we report are related to the fraction of the document which is classified with the language type. (We can probably just gloss over the fact we give short fragments less weight though.) |
||
} | ||
double[] probabilities = softMax(scores); | ||
ClassificationConfig classificationConfig = (ClassificationConfig) config; | ||
Tuple<InferenceHelpers.TopClassificationValue, List<TopClassEntry>> topClasses = InferenceHelpers.topClasses( | ||
probabilities, | ||
|
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.
Please add a comment here to say that using the number of UTF-8 bytes:
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 will!