inference.asciidoc 5.4 KB

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