inference.asciidoc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. Regression configuration for inference.
  34. `results_field`::
  35. (Optional, string)
  36. include::{docdir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  37. `num_top_feature_importance_values`::
  38. (Optional, integer)
  39. include::{docdir}/ml/ml-shared.asciidoc[tag=inference-config-regression-num-top-feature-importance-values]
  40. [discrete]
  41. [[inference-processor-classification-opt]]
  42. ==== {classification-cap} configuration options
  43. Classification configuration for inference.
  44. `num_top_classes`::
  45. (Optional, integer)
  46. include::{docdir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-classes]
  47. `num_top_feature_importance_values`::
  48. (Optional, integer)
  49. include::{docdir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-feature-importance-values]
  50. `results_field`::
  51. (Optional, string)
  52. include::{docdir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  53. `top_classes_results_field`::
  54. (Optional, string)
  55. include::{docdir}/ml/ml-shared.asciidoc[tag=inference-config-classification-top-classes-results-field]
  56. `prediction_field_type`::
  57. (Optional, string)
  58. include::{docdir}/ml/ml-shared.asciidoc[tag=inference-config-classification-prediction-field-type]
  59. [discrete]
  60. [[inference-processor-config-example]]
  61. ==== `inference_config` examples
  62. [source,js]
  63. --------------------------------------------------
  64. {
  65. "inference_config": {
  66. "regression": {
  67. "results_field": "my_regression"
  68. }
  69. }
  70. }
  71. --------------------------------------------------
  72. // NOTCONSOLE
  73. This configuration specifies a `regression` inference and the results are
  74. written to the `my_regression` field contained in the `target_field` results
  75. object.
  76. [source,js]
  77. --------------------------------------------------
  78. {
  79. "inference_config": {
  80. "classification": {
  81. "num_top_classes": 2,
  82. "results_field": "prediction",
  83. "top_classes_results_field": "probabilities"
  84. }
  85. }
  86. }
  87. --------------------------------------------------
  88. // NOTCONSOLE
  89. This configuration specifies a `classification` inference. The number of
  90. categories for which the predicted probabilities are reported is 2
  91. (`num_top_classes`). The result is written to the `prediction` field and the top
  92. classes to the `probabilities` field. Both fields are contained in the
  93. `target_field` results object.
  94. [discrete]
  95. [[inference-processor-feature-importance]]
  96. ==== {feat-imp-cap} object mapping
  97. Update your index mapping of the {feat-imp} result field as you can see below to
  98. get the full benefit of aggregating and searching for
  99. {ml-docs}/ml-feature-importance.html[{feat-imp}].
  100. [source,js]
  101. --------------------------------------------------
  102. "ml.inference.feature_importance": {
  103. "type": "nested",
  104. "dynamic": true,
  105. "properties": {
  106. "feature_name": {
  107. "type": "keyword"
  108. },
  109. "importance": {
  110. "type": "double"
  111. }
  112. }
  113. }
  114. --------------------------------------------------
  115. // NOTCONSOLE
  116. The mapping field name for {feat-imp} is compounded as follows:
  117. `<ml.inference.target_field>`.`<inference.tag>`.`feature_importance`
  118. If `inference.tag` is not provided in the processor definition, it is not part
  119. of the field path. The `<ml.inference.target_field>` defaults to `ml.inference`.
  120. For example, you provide a tag `foo` in the definition as you can see below:
  121. [source,js]
  122. --------------------------------------------------
  123. {
  124. "tag": "foo",
  125. ...
  126. }
  127. --------------------------------------------------
  128. // NOTCONSOLE
  129. The {feat-imp} value is written to the `ml.inference.foo.feature_importance`
  130. field.
  131. You can also specify a target field as follows:
  132. [source,js]
  133. --------------------------------------------------
  134. {
  135. "tag": "foo",
  136. "target_field": "my_field"
  137. }
  138. --------------------------------------------------
  139. // NOTCONSOLE
  140. In this case, {feat-imp} is exposed in the
  141. `my_field.foo.feature_importance` field.