inference.asciidoc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. [role="xpack"]
  2. [[inference-processor]]
  3. === {infer-cap} processor
  4. ++++
  5. <titleabbrev>{infer-cap}</titleabbrev>
  6. ++++
  7. Uses a pre-trained {dfanalytics} model to infer against the data that is being
  8. ingested in the pipeline.
  9. [[inference-options]]
  10. .{infer-cap} Options
  11. [options="header"]
  12. |======
  13. | Name | Required | Default | Description
  14. | `model_id` | yes | - | (String) The ID or alias for the trained model.
  15. | `target_field` | no | `ml.inference.<processor_tag>` | (String) Field added to incoming documents to contain results objects.
  16. | `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.
  17. | `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`>>.
  18. include::common-options.asciidoc[]
  19. |======
  20. [source,js]
  21. --------------------------------------------------
  22. {
  23. "inference": {
  24. "model_id": "flight_delay_regression-1571767128603",
  25. "target_field": "FlightDelayMin_prediction_infer",
  26. "field_map": {
  27. "your_field": "my_field"
  28. },
  29. "inference_config": { "regression": {} }
  30. }
  31. }
  32. --------------------------------------------------
  33. // NOTCONSOLE
  34. [discrete]
  35. [[inference-processor-regression-opt]]
  36. ==== {regression-cap} configuration options
  37. Regression configuration for inference.
  38. `results_field`::
  39. (Optional, string)
  40. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field-processor]
  41. `num_top_feature_importance_values`::
  42. (Optional, integer)
  43. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-regression-num-top-feature-importance-values]
  44. [discrete]
  45. [[inference-processor-classification-opt]]
  46. ==== {classification-cap} configuration options
  47. Classification configuration for inference.
  48. `num_top_classes`::
  49. (Optional, integer)
  50. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-classes]
  51. `num_top_feature_importance_values`::
  52. (Optional, integer)
  53. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-feature-importance-values]
  54. `results_field`::
  55. (Optional, string)
  56. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field-processor]
  57. `top_classes_results_field`::
  58. (Optional, string)
  59. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-top-classes-results-field]
  60. `prediction_field_type`::
  61. (Optional, string)
  62. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-prediction-field-type]
  63. [discrete]
  64. [[inference-processor-config-example]]
  65. ==== `inference_config` examples
  66. [source,js]
  67. --------------------------------------------------
  68. "inference":{
  69. "model_id":"my_model_id"
  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. "inference":{
  84. "model_id":"my_model_id"
  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. Refer to the
  101. {ml-docs}/ml-dfa-lang-ident.html#ml-lang-ident-example[language identification]
  102. trained model documentation for a full example.
  103. [discrete]
  104. [[inference-processor-feature-importance]]
  105. ==== {feat-imp-cap} object mapping
  106. To get the full benefit of aggregating and searching for
  107. {ml-docs}/ml-feature-importance.html[{feat-imp}], update your index mapping of
  108. the {feat-imp} result field as you can see below:
  109. [source,js]
  110. --------------------------------------------------
  111. "ml.inference.feature_importance": {
  112. "type": "nested",
  113. "dynamic": true,
  114. "properties": {
  115. "feature_name": {
  116. "type": "keyword"
  117. },
  118. "importance": {
  119. "type": "double"
  120. }
  121. }
  122. }
  123. --------------------------------------------------
  124. // NOTCONSOLE
  125. The mapping field name for {feat-imp} (in the example above, it is
  126. `ml.inference.feature_importance`) is compounded as follows:
  127. `<ml.inference.target_field>`.`<inference.tag>`.`feature_importance`
  128. * `<ml.inference.target_field>`: defaults to `ml.inference`.
  129. * `<inference.tag>`: if is not provided in the processor definition, then it is
  130. not part of the field path.
  131. For example, if you provide a tag `foo` in the definition as you can see below:
  132. [source,js]
  133. --------------------------------------------------
  134. {
  135. "tag": "foo",
  136. ...
  137. }
  138. --------------------------------------------------
  139. // NOTCONSOLE
  140. Then, the {feat-imp} value is written to the
  141. `ml.inference.foo.feature_importance` field.
  142. You can also specify the target field as follows:
  143. [source,js]
  144. --------------------------------------------------
  145. {
  146. "tag": "foo",
  147. "target_field": "my_field"
  148. }
  149. --------------------------------------------------
  150. // NOTCONSOLE
  151. In this case, {feat-imp} is exposed in the
  152. `my_field.foo.feature_importance` field.