-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[ML][Inference] adding more options to inference processor #48545
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
Merged
benwtrent
merged 2 commits into
elastic:feature/ml-inference
from
benwtrent:feature/ml-inference-adding-processor-options
Oct 28, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -43,7 +43,8 @@ public void testMutateDocumentWithClassification() { | |||||
"classification_model", | ||||||
new ClassificationConfig(0), | ||||||
Collections.emptyMap(), | ||||||
"_ml_model.my_processor"); | ||||||
"ml.my_processor", | ||||||
true); | ||||||
|
||||||
Map<String, Object> source = new HashMap<>(); | ||||||
Map<String, Object> ingestMetadata = new HashMap<>(); | ||||||
|
@@ -54,7 +55,7 @@ public void testMutateDocumentWithClassification() { | |||||
inferenceProcessor.mutateDocument(response, document); | ||||||
|
||||||
assertThat(document.getFieldValue(targetField, String.class), equalTo("foo")); | ||||||
assertThat(document.getFieldValue("_ml_model", Map.class), | ||||||
assertThat(document.getFieldValue("ml", Map.class), | ||||||
equalTo(Collections.singletonMap("my_processor", Collections.singletonMap("model_id", "classification_model")))); | ||||||
} | ||||||
|
||||||
|
@@ -67,7 +68,8 @@ public void testMutateDocumentClassificationTopNClasses() { | |||||
"classification_model", | ||||||
new ClassificationConfig(2), | ||||||
Collections.emptyMap(), | ||||||
"_ml_model.my_processor"); | ||||||
"ml.my_processor", | ||||||
true); | ||||||
|
||||||
Map<String, Object> source = new HashMap<>(); | ||||||
Map<String, Object> ingestMetadata = new HashMap<>(); | ||||||
|
@@ -83,7 +85,7 @@ public void testMutateDocumentClassificationTopNClasses() { | |||||
|
||||||
assertThat((List<Map<?,?>>)document.getFieldValue(targetField, List.class), | ||||||
contains(classes.stream().map(ClassificationInferenceResults.TopClassEntry::asValueMap).toArray(Map[]::new))); | ||||||
assertThat(document.getFieldValue("_ml_model", Map.class), | ||||||
assertThat(document.getFieldValue("ml", Map.class), | ||||||
equalTo(Collections.singletonMap("my_processor", Collections.singletonMap("model_id", "classification_model")))); | ||||||
} | ||||||
|
||||||
|
@@ -95,7 +97,8 @@ public void testMutateDocumentRegression() { | |||||
"regression_model", | ||||||
new RegressionConfig(), | ||||||
Collections.emptyMap(), | ||||||
"_ml_model.my_processor"); | ||||||
"ml.my_processor", | ||||||
true); | ||||||
|
||||||
Map<String, Object> source = new HashMap<>(); | ||||||
Map<String, Object> ingestMetadata = new HashMap<>(); | ||||||
|
@@ -106,7 +109,7 @@ public void testMutateDocumentRegression() { | |||||
inferenceProcessor.mutateDocument(response, document); | ||||||
|
||||||
assertThat(document.getFieldValue(targetField, Double.class), equalTo(0.7)); | ||||||
assertThat(document.getFieldValue("_ml_model", Map.class), | ||||||
assertThat(document.getFieldValue("ml", Map.class), | ||||||
equalTo(Collections.singletonMap("my_processor", Collections.singletonMap("model_id", "regression_model")))); | ||||||
} | ||||||
|
||||||
|
@@ -118,7 +121,8 @@ public void testMutateDocumentNoModelMetaData() { | |||||
"regression_model", | ||||||
new RegressionConfig(), | ||||||
Collections.emptyMap(), | ||||||
null); | ||||||
"ml.my_processor", | ||||||
false); | ||||||
|
||||||
Map<String, Object> source = new HashMap<>(); | ||||||
Map<String, Object> ingestMetadata = new HashMap<>(); | ||||||
|
@@ -129,20 +133,54 @@ public void testMutateDocumentNoModelMetaData() { | |||||
inferenceProcessor.mutateDocument(response, document); | ||||||
|
||||||
assertThat(document.getFieldValue(targetField, Double.class), equalTo(0.7)); | ||||||
assertThat(document.hasField("_ml_model"), is(false)); | ||||||
assertThat(document.hasField("ml"), is(false)); | ||||||
} | ||||||
|
||||||
public void testMutateDocumentModelMetaDataExistingField() { | ||||||
String targetField = "regression_value"; | ||||||
InferenceProcessor inferenceProcessor = new InferenceProcessor(client, | ||||||
"my_processor", | ||||||
targetField, | ||||||
"regression_model", | ||||||
new RegressionConfig(), | ||||||
Collections.emptyMap(), | ||||||
"ml.my_processor", | ||||||
true); | ||||||
|
||||||
//cannot use singleton map as attempting to mutate later | ||||||
Map<String, Object> ml = new HashMap<>(){{ | ||||||
put("regression_prediction", 0.55); | ||||||
}}; | ||||||
Map<String, Object> source = new HashMap<>(){{ | ||||||
put("ml", ml); | ||||||
}}; | ||||||
Map<String, Object> ingestMetadata = new HashMap<>(); | ||||||
IngestDocument document = new IngestDocument(source, ingestMetadata); | ||||||
|
||||||
InferModelAction.Response response = new InferModelAction.Response( | ||||||
Collections.singletonList(new RegressionInferenceResults(0.7))); | ||||||
inferenceProcessor.mutateDocument(response, document); | ||||||
|
||||||
assertThat(document.getFieldValue(targetField, Double.class), equalTo(0.7)); | ||||||
assertThat(document.getFieldValue("ml", Map.class), | ||||||
equalTo(new HashMap<>(){{ | ||||||
put("my_processor", Collections.singletonMap("model_id", "regression_model")); | ||||||
put("regression_prediction", 0.55); | ||||||
}})); | ||||||
} | ||||||
|
||||||
public void testGenerateRequestWithEmptyMapping() { | ||||||
String modelId = "model"; | ||||||
Integer topNClasses = randomBoolean() ? null : randomIntBetween(1, 10); | ||||||
|
||||||
InferenceProcessor processor = new InferenceProcessor(client, | ||||||
"my_processor", | ||||||
"my_field", | ||||||
modelId, | ||||||
new ClassificationConfig(topNClasses), | ||||||
Collections.emptyMap(), | ||||||
null); | ||||||
"my_processor", | ||||||
"my_field", | ||||||
modelId, | ||||||
new ClassificationConfig(topNClasses), | ||||||
Collections.emptyMap(), | ||||||
"ml.my_processor", | ||||||
false); | ||||||
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.
Suggested change
|
||||||
|
||||||
Map<String, Object> source = new HashMap<>(){{ | ||||||
put("value1", 1); | ||||||
|
@@ -171,7 +209,8 @@ public void testGenerateWithMapping() { | |||||
modelId, | ||||||
new ClassificationConfig(topNClasses), | ||||||
fieldMapping, | ||||||
null); | ||||||
"ml.my_processor", | ||||||
false); | ||||||
|
||||||
Map<String, Object> source = new HashMap<>(3){{ | ||||||
put("value1", 1); | ||||||
|
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.
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 seems that
modelInfoField
should never benull
?Does it make sense to add
requireNonNull
in the constructor?