inference.asciidoc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 or alias for the trained model.
  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. "inference":{
  71. "model_id":"my_model_id"
  72. "inference_config": {
  73. "regression": {
  74. "results_field": "my_regression"
  75. }
  76. }
  77. }
  78. --------------------------------------------------
  79. // NOTCONSOLE
  80. This configuration specifies a `regression` inference and the results are
  81. written to the `my_regression` field contained in the `target_field` results
  82. object.
  83. [source,js]
  84. --------------------------------------------------
  85. "inference":{
  86. "model_id":"my_model_id"
  87. "inference_config": {
  88. "classification": {
  89. "num_top_classes": 2,
  90. "results_field": "prediction",
  91. "top_classes_results_field": "probabilities"
  92. }
  93. }
  94. }
  95. --------------------------------------------------
  96. // NOTCONSOLE
  97. This configuration specifies a `classification` inference. The number of
  98. categories for which the predicted probabilities are reported is 2
  99. (`num_top_classes`). The result is written to the `prediction` field and the top
  100. classes to the `probabilities` field. Both fields are contained in the
  101. `target_field` results object.
  102. Refer to the
  103. {ml-docs}/ml-lang-ident.html#ml-lang-ident-example[language identification]
  104. trained model documentation for a full example.
  105. [discrete]
  106. [[inference-processor-feature-importance]]
  107. ==== {feat-imp-cap} object mapping
  108. To get the full benefit of aggregating and searching for
  109. {ml-docs}/ml-feature-importance.html[{feat-imp}], update your index mapping of
  110. the {feat-imp} result field as you can see below:
  111. [source,js]
  112. --------------------------------------------------
  113. "ml.inference.feature_importance": {
  114. "type": "nested",
  115. "dynamic": true,
  116. "properties": {
  117. "feature_name": {
  118. "type": "keyword"
  119. },
  120. "importance": {
  121. "type": "double"
  122. }
  123. }
  124. }
  125. --------------------------------------------------
  126. // NOTCONSOLE
  127. The mapping field name for {feat-imp} (in the example above, it is
  128. `ml.inference.feature_importance`) is compounded as follows:
  129. `<ml.inference.target_field>`.`<inference.tag>`.`feature_importance`
  130. * `<ml.inference.target_field>`: defaults to `ml.inference`.
  131. * `<inference.tag>`: if is not provided in the processor definition, then it is
  132. not part of the field path.
  133. For example, if you provide a tag `foo` in the definition as you can see below:
  134. [source,js]
  135. --------------------------------------------------
  136. {
  137. "tag": "foo",
  138. ...
  139. }
  140. --------------------------------------------------
  141. // NOTCONSOLE
  142. Then, the {feat-imp} value is written to the
  143. `ml.inference.foo.feature_importance` field.
  144. You can also specify the target field as follows:
  145. [source,js]
  146. --------------------------------------------------
  147. {
  148. "tag": "foo",
  149. "target_field": "my_field"
  150. }
  151. --------------------------------------------------
  152. // NOTCONSOLE
  153. In this case, {feat-imp} is exposed in the
  154. `my_field.foo.feature_importance` field.