inference.asciidoc 5.7 KB

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