infer-trained-model-deployment.asciidoc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. [role="xpack"]
  2. [[infer-trained-model-deployment]]
  3. = Infer trained model deployment API
  4. [subs="attributes"]
  5. ++++
  6. <titleabbrev>Infer trained model deployment</titleabbrev>
  7. ++++
  8. Evaluates a trained model.
  9. [[infer-trained-model-deployment-request]]
  10. == {api-request-title}
  11. `POST _ml/trained_models/<model_id>/deployment/_infer`
  12. ////
  13. [[infer-trained-model-deployment-prereq]]
  14. == {api-prereq-title}
  15. ////
  16. ////
  17. [[infer-trained-model-deployment-desc]]
  18. == {api-description-title}
  19. ////
  20. [[infer-trained-model-deployment-path-params]]
  21. == {api-path-parms-title}
  22. `<model_id>`::
  23. (Required, string)
  24. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-id]
  25. [[infer-trained-model-deployment-query-params]]
  26. == {api-query-parms-title}
  27. `timeout`::
  28. (Optional, time)
  29. Controls the amount of time to wait for {infer} results. Defaults to 10 seconds.
  30. [[infer-trained-model-request-body]]
  31. == {api-request-body-title}
  32. `docs`::
  33. (Required, array)
  34. An array of objects to pass to the model for inference. The objects should
  35. contain a field matching your configured trained model input. Typically, the field
  36. name is `text_field`. Currently, only a single value is allowed.
  37. ////
  38. [[infer-trained-model-deployment-results]]
  39. == {api-response-body-title}
  40. ////
  41. ////
  42. [[ml-get-trained-models-response-codes]]
  43. == {api-response-codes-title}
  44. ////
  45. [[infer-trained-model-deployment-example]]
  46. == {api-examples-title}
  47. The response depends on the task the model is trained for. If it is a
  48. text classification task, the response is the score. For example:
  49. [source,console]
  50. --------------------------------------------------
  51. POST _ml/trained_models/model2/deployment/_infer
  52. {
  53. "docs": [{"text_field": "The movie was awesome!!"}]
  54. }
  55. --------------------------------------------------
  56. // TEST[skip:TBD]
  57. The API returns the predicted label and the confidence.
  58. [source,console-result]
  59. ----
  60. {
  61. "predicted_value" : "POSITIVE",
  62. "prediction_probability" : 0.9998667964092964
  63. }
  64. ----
  65. // NOTCONSOLE
  66. For named entity recognition (NER) tasks, the response contains the annotated
  67. text output and the recognized entities.
  68. [source,console]
  69. --------------------------------------------------
  70. POST _ml/trained_models/model2/deployment/_infer
  71. {
  72. "input": "Hi my name is Josh and I live in Berlin"
  73. }
  74. --------------------------------------------------
  75. // TEST[skip:TBD]
  76. The API returns in this case:
  77. [source,console-result]
  78. ----
  79. {
  80. "predicted_value" : "Hi my name is [Josh](PER&Josh) and I live in [Berlin](LOC&Berlin)",
  81. "entities" : [
  82. {
  83. "entity" : "Josh",
  84. "class_name" : "PER",
  85. "class_probability" : 0.9977303419824,
  86. "start_pos" : 14,
  87. "end_pos" : 18
  88. },
  89. {
  90. "entity" : "Berlin",
  91. "class_name" : "LOC",
  92. "class_probability" : 0.9992474323902818,
  93. "start_pos" : 33,
  94. "end_pos" : 39
  95. }
  96. ]
  97. }
  98. ----
  99. // NOTCONSOLE