inference.asciidoc 5.2 KB

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