inference.asciidoc 5.4 KB

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