Skip to content

Conversation

@davidkyle
Copy link
Member

This changes makes MachineLearning an IngestPlugin, adds an Inference processor and the factory to create it.

This PR is based on the enrich feature branch

@davidkyle davidkyle added the :ml Machine learning label Aug 29, 2019
@davidkyle davidkyle requested a review from benwtrent August 29, 2019 15:48
@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core

@davidkyle davidkyle force-pushed the inference-processor-simple branch from bf33974 to a3350b8 Compare August 29, 2019 17:19
Copy link
Contributor

@przemekwitek przemekwitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design looks good, minor code comments inline.

return Collections.singletonMap(InferenceProcessor.TYPE, new InferenceProcessor.Factory(getModelLoaders(parameters.client)));
}

private Map<String, ModelLoader> getModelLoaders(Client client) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be static?

* be called either with the updated (or new) document or an {@code Exception}.
*
* @param document Document to infer on
* @param handler The handler must be called
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param handler The handler must be called
* @param handler Handler that must be called

public interface Model {

/**
* Perform inference on the input {@code document}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Perform inference on the input {@code document}.
* Performs inference on the input {@code document}.

* Inference processors must remove their configuration from the {@code config} map.
* For the case when a model has already been loaded
*
* This method should be used when {@link #load(String, String, boolean, Map)} isn't.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I cannot parse this sentence: This method should be used when "load" isn't.. What does "isn't" refer to?


private static final String TARGET_FIELD = "hotdog_or_not";

private Random random;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be final.

}


public void load(String id, String index, ActionListener<Model> listener) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be private?

private Map<String, ModelLoader> modelLoaders;

public Factory(Map<String, ModelLoader> modelLoaders) {
loadedModels = new ConcurrentHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
loadedModels = new ConcurrentHashMap<>();
this.loadedModels = new ConcurrentHashMap<>();


public static final class Factory implements Processor.Factory {

private Map<String, Model> loadedModels;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final here and in the next line?


@Override
public IngestDocument execute(IngestDocument ingestDocument) {
assert false : "The async override of execute() must be used";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education: Why did you choose to assert rather than, say throw UnsupportedOperationException?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it should be UnsupportedOperationException thanks


InferenceProcessor.Factory factory = new InferenceProcessor.Factory(Map.of("test", mockLoader));

Map<String, Object> config = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are using Map.of anyway in line 31, you could also use it here to make declaration of config more concise. The same in line 45.

public static final String TYPE = "inference";
private static final String MODEL_ID = "model_id";
private static final String MODEL_TYPE = "model_type";
private static final String IGNORE_MISSING = "ignore_missing";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be good to have a feature_map so that the same model can be used to process different docs.

@droberts195
Copy link

Superseded by #47859.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:ml Machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants