infer-trained-model-deployment.asciidoc 2.8 KB

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