inference.asciidoc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[inference-processor]]
  4. === {infer-cap} Processor
  5. Uses a pre-trained {dfanalytics} model to infer against the data that is being
  6. ingested in the pipeline.
  7. [[inference-options]]
  8. .{infer-cap} Options
  9. [options="header"]
  10. |======
  11. | Name | Required | Default | Description
  12. | `model_id` | yes | - | (String) The ID of the model to load and infer against.
  13. | `target_field` | no | `ml.inference.<processor_tag>` | (String) Field added to incoming documents to contain results objects.
  14. | `field_map` | yes | - | (Object) Maps the document field names to the known field names of the model. This mapping takes precedence over any default mappings provided in the model configuration.
  15. | `inference_config` | yes | - | (Object) Contains the inference type and its options. There are two types: <<inference-processor-regression-opt,`regression`>> and <<inference-processor-classification-opt,`classification`>>.
  16. include::common-options.asciidoc[]
  17. |======
  18. [source,js]
  19. --------------------------------------------------
  20. {
  21. "inference": {
  22. "model_id": "flight_delay_regression-1571767128603",
  23. "target_field": "FlightDelayMin_prediction_infer",
  24. "field_map": {},
  25. "inference_config": { "regression": {} }
  26. }
  27. }
  28. --------------------------------------------------
  29. // NOTCONSOLE
  30. [discrete]
  31. [[inference-processor-regression-opt]]
  32. ==== {regression-cap} configuration options
  33. `results_field`::
  34. (Optional, string)
  35. Specifies the field to which the inference prediction is written. Defaults to
  36. `predicted_value`.
  37. `num_top_feature_importance_values`::::
  38. (Optional, integer)
  39. Specifies the maximum number of
  40. {ml-docs}/dfa-regression.html#dfa-regression-feature-importance[feature
  41. importance] values per document. By default, it is zero and no feature importance
  42. calculation occurs.
  43. [discrete]
  44. [[inference-processor-classification-opt]]
  45. ==== {classification-cap} configuration options
  46. `results_field`::
  47. (Optional, string)
  48. The field that is added to incoming documents to contain the inference prediction. Defaults to
  49. `predicted_value`.
  50. `num_top_classes`::
  51. (Optional, integer)
  52. Specifies the number of top class predictions to return. Defaults to 0.
  53. `top_classes_results_field`::
  54. (Optional, string)
  55. Specifies the field to which the top classes are written. Defaults to
  56. `top_classes`.
  57. `num_top_feature_importance_values`::::
  58. (Optional, integer)
  59. Specifies the maximum number of
  60. {ml-docs}/dfa-classification.html#dfa-classification-feature-importance[feature
  61. importance] values per document. By default, it is zero and no feature
  62. importance calculation occurs.
  63. [discrete]
  64. [[inference-processor-config-example]]
  65. ==== `inference_config` examples
  66. [source,js]
  67. --------------------------------------------------
  68. {
  69. "inference_config": {
  70. "regression": {
  71. "results_field": "my_regression"
  72. }
  73. }
  74. }
  75. --------------------------------------------------
  76. // NOTCONSOLE
  77. This configuration specifies a `regression` inference and the results are
  78. written to the `my_regression` field contained in the `target_field` results
  79. object.
  80. [source,js]
  81. --------------------------------------------------
  82. {
  83. "inference_config": {
  84. "classification": {
  85. "num_top_classes": 2,
  86. "results_field": "prediction",
  87. "top_classes_results_field": "probabilities"
  88. }
  89. }
  90. }
  91. --------------------------------------------------
  92. // NOTCONSOLE
  93. This configuration specifies a `classification` inference. The number of
  94. categories for which the predicted probabilities are reported is 2
  95. (`num_top_classes`). The result is written to the `prediction` field and the top
  96. classes to the `probabilities` field. Both fields are contained in the
  97. `target_field` results object.
  98. [discrete]
  99. [[inference-processor-feature-importance]]
  100. ==== {feat-imp-cap} object mapping
  101. Update your index mapping of the {feat-imp} result field as you can see below to
  102. get the full benefit of aggregating and searching for
  103. {ml-docs}/dfa-classification.html#dfa-classification-feature-importance[{feat-imp}].
  104. [source,js]
  105. --------------------------------------------------
  106. "ml.inference.feature_importance": {
  107. "type": "nested",
  108. "dynamic": true,
  109. "properties": {
  110. "feature_name": {
  111. "type": "keyword"
  112. },
  113. "importance": {
  114. "type": "double"
  115. }
  116. }
  117. }
  118. --------------------------------------------------
  119. // NOTCONSOLE
  120. The mapping field name for {feat-imp} is compounded as follows:
  121. `<ml.inference.target_field>`.`<inference.tag>`.`feature_importance`
  122. If `inference.tag` is not provided in the processor definition, it is not part
  123. of the field path. The `<ml.inference.target_field>` defaults to `ml.inference`.
  124. For example, you provide a tag `foo` in the definition as you can see below:
  125. [source,js]
  126. --------------------------------------------------
  127. {
  128. "tag": "foo",
  129. ...
  130. }
  131. --------------------------------------------------
  132. // NOTCONSOLE
  133. The `{feat-imp}` value is written to the `ml.inference.foo.feature_importance`
  134. field.
  135. You can also specify a target field as follows:
  136. [source,js]
  137. --------------------------------------------------
  138. {
  139. "tag": "foo",
  140. "target_field": "my_field"
  141. }
  142. --------------------------------------------------
  143. // NOTCONSOLE
  144. In this case, `{feat-imp}` is exposed in the
  145. `my_field.foo.feature_importance` field.