get-trained-models.asciidoc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[get-trained-models]]
  4. = Get trained models API
  5. [subs="attributes"]
  6. ++++
  7. <titleabbrev>Get trained models</titleabbrev>
  8. ++++
  9. Retrieves configuration information for a trained model.
  10. [[ml-get-trained-models-request]]
  11. == {api-request-title}
  12. `GET _ml/trained_models/` +
  13. `GET _ml/trained_models/<model_id>` +
  14. `GET _ml/trained_models/_all` +
  15. `GET _ml/trained_models/<model_id1>,<model_id2>` +
  16. `GET _ml/trained_models/<model_id_pattern*>`
  17. [[ml-get-trained-models-prereq]]
  18. == {api-prereq-title}
  19. Requires the `monitor_ml` cluster privilege. This privilege is included in the
  20. `machine_learning_user` built-in role.
  21. //[[ml-get-trained-models-desc]]
  22. //== {api-description-title}
  23. [[ml-get-trained-models-path-params]]
  24. == {api-path-parms-title}
  25. `<model_id>`::
  26. (Optional, string)
  27. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-id-or-alias]
  28. +
  29. You can get information for multiple trained models in a single API request by
  30. using a comma-separated list of model IDs or a wildcard expression.
  31. [[ml-get-trained-models-query-params]]
  32. == {api-query-parms-title}
  33. `allow_no_match`::
  34. (Optional, Boolean)
  35. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=allow-no-match-models]
  36. `decompress_definition`::
  37. (Optional, Boolean)
  38. Specifies whether the included model definition should be returned as a JSON map
  39. (`true`) or in a custom compressed format (`false`). Defaults to `true`.
  40. `exclude_generated`::
  41. (Optional, Boolean)
  42. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=exclude-generated]
  43. `from`::
  44. (Optional, integer)
  45. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=from-models]
  46. `include`::
  47. (Optional, string)
  48. A comma delimited string of optional fields to include in the response body. The
  49. default value is empty, indicating no optional fields are included. Valid
  50. options are:
  51. - `definition`: Includes the model definition.
  52. - `feature_importance_baseline`: Includes the baseline for {feat-imp} values.
  53. - `hyperparameters`: Includes the information about hyperparameters used to
  54. train the model. This information consists of the value, the absolute and
  55. relative importance of the hyperparameter as well as an indicator of whether
  56. it was specified by the user or tuned during hyperparameter optimization.
  57. - `total_feature_importance`: Includes the total {feat-imp} for the training
  58. data set.
  59. The baseline and total {feat-imp} values are returned in the `metadata` field
  60. in the response body.
  61. `size`::
  62. (Optional, integer)
  63. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=size-models]
  64. `tags`::
  65. (Optional, string)
  66. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=tags]
  67. [role="child_attributes"]
  68. [[ml-get-trained-models-results]]
  69. == {api-response-body-title}
  70. `trained_model_configs`::
  71. (array)
  72. An array of trained model resources, which are sorted by the `model_id` value in
  73. ascending order.
  74. +
  75. .Properties of trained model resources
  76. [%collapsible%open]
  77. ====
  78. `created_by`:::
  79. (string)
  80. Information on the creator of the trained model.
  81. `create_time`:::
  82. (<<time-units,time units>>)
  83. The time when the trained model was created.
  84. `default_field_map` :::
  85. (object)
  86. A string to string object that contains the default field map to use
  87. when inferring against the model. For example, data frame analytics
  88. may train the model on a specific multi-field `foo.keyword`.
  89. The analytics job would then supply a default field map entry for
  90. `"foo" : "foo.keyword"`.
  91. +
  92. Any field map described in the inference configuration takes precedence.
  93. `description`:::
  94. (string)
  95. The free-text description of the trained model.
  96. `estimated_heap_memory_usage_bytes`:::
  97. (integer)
  98. The estimated heap usage in bytes to keep the trained model in memory.
  99. `estimated_operations`:::
  100. (integer)
  101. The estimated number of operations to use the trained model.
  102. `inference_config`:::
  103. (object)
  104. The default configuration for inference. This can be either a `regression`
  105. or `classification` configuration. It must match the underlying
  106. `definition.trained_model`'s `target_type`.
  107. +
  108. .Properties of `inference_config`
  109. [%collapsible%open]
  110. =====
  111. `classification`::::
  112. (object)
  113. Classification configuration for inference.
  114. +
  115. .Properties of classification inference
  116. [%collapsible%open]
  117. ======
  118. `num_top_classes`:::
  119. (integer)
  120. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-classes]
  121. `num_top_feature_importance_values`:::
  122. (integer)
  123. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-feature-importance-values]
  124. `prediction_field_type`:::
  125. (string)
  126. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-prediction-field-type]
  127. `results_field`:::
  128. (string)
  129. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  130. `top_classes_results_field`:::
  131. (string)
  132. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-top-classes-results-field]
  133. ======
  134. `fill_mask`::::
  135. (Optional, object)
  136. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-fill-mask]
  137. +
  138. .Properties of fill_mask inference
  139. [%collapsible%open]
  140. ======
  141. `tokenization`::::
  142. (Optional, object)
  143. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  144. +
  145. .Properties of tokenization
  146. [%collapsible%open]
  147. =======
  148. `bert`::::
  149. (Optional, object)
  150. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  151. +
  152. .Properties of bert
  153. [%collapsible%open]
  154. ========
  155. `do_lower_case`::::
  156. (Optional, boolean)
  157. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-do-lower-case]
  158. `max_sequence_length`::::
  159. (Optional, integer)
  160. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-max-sequence-length]
  161. `with_special_tokens`::::
  162. (Optional, boolean)
  163. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  164. ========
  165. =======
  166. `vocabulary`::::
  167. (Optional, object)
  168. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-vocabulary]
  169. +
  170. .Properties of vocabulary
  171. [%collapsible%open]
  172. =======
  173. `index`::::
  174. (Required, string)
  175. The index where the vocabulary is stored.
  176. =======
  177. ======
  178. `ner`::::
  179. (Optional, object)
  180. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-ner]
  181. +
  182. .Properties of ner inference
  183. [%collapsible%open]
  184. ======
  185. `classification_labels`::::
  186. (Optional, string)
  187. An array of classification labels. NER supports only
  188. Inside-Outside-Beginning labels (IOB) and only persons, organizations, locations,
  189. and miscellaneous. For example:
  190. `["O", "B-PER", "I-PER", "B-ORG", "I-ORG", "B-LOC", "I-LOC", "B-MISC", "I-MISC"]`.
  191. `tokenization`::::
  192. (Optional, object)
  193. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  194. +
  195. .Properties of tokenization
  196. [%collapsible%open]
  197. =======
  198. `bert`::::
  199. (Optional, object)
  200. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  201. +
  202. .Properties of bert
  203. [%collapsible%open]
  204. ========
  205. `do_lower_case`::::
  206. (Optional, boolean)
  207. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-do-lower-case]
  208. `max_sequence_length`::::
  209. (Optional, integer)
  210. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-max-sequence-length]
  211. `with_special_tokens`::::
  212. (Optional, boolean)
  213. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  214. ========
  215. =======
  216. `vocabulary`::::
  217. (Optional, object)
  218. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-vocabulary]
  219. +
  220. .Properties of vocabulary
  221. [%collapsible%open]
  222. =======
  223. `index`::::
  224. (Required, string)
  225. The index where the vocabulary is stored
  226. =======
  227. ======
  228. `pass_through`::::
  229. (Optional, object)
  230. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-pass-through]
  231. +
  232. .Properties of pass_through inference
  233. [%collapsible%open]
  234. ======
  235. `tokenization`::::
  236. (Optional, object)
  237. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  238. +
  239. .Properties of tokenization
  240. [%collapsible%open]
  241. =======
  242. `bert`::::
  243. (Optional, object)
  244. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  245. +
  246. .Properties of bert
  247. [%collapsible%open]
  248. ========
  249. `do_lower_case`::::
  250. (Optional, boolean)
  251. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-do-lower-case]
  252. `max_sequence_length`::::
  253. (Optional, integer)
  254. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-max-sequence-length]
  255. `with_special_tokens`::::
  256. (Optional, boolean)
  257. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  258. ========
  259. =======
  260. `vocabulary`::::
  261. (Optional, object)
  262. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-vocabulary]
  263. +
  264. .Properties of vocabulary
  265. [%collapsible%open]
  266. =======
  267. `index`::::
  268. (Required, string)
  269. The index where the vocabulary is stored.
  270. =======
  271. ======
  272. `regression`::::
  273. (object)
  274. Regression configuration for inference.
  275. +
  276. .Properties of regression inference
  277. [%collapsible%open]
  278. ======
  279. `num_top_feature_importance_values`:::
  280. (integer)
  281. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-regression-num-top-feature-importance-values]
  282. `results_field`:::
  283. (string)
  284. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  285. ======
  286. `text_classification`::::
  287. (Optional, object)
  288. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-classification]
  289. +
  290. .Properties of text_classification inference
  291. [%collapsible%open]
  292. ======
  293. `classification_labels`::::
  294. (Optional, string)
  295. An array of classification labels.
  296. `num_top_classes`::::
  297. (Optional, integer)
  298. Specifies the number of top class predictions to return. Defaults to all classes (-1).
  299. `tokenization`::::
  300. (Optional, object)
  301. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  302. +
  303. .Properties of tokenization
  304. [%collapsible%open]
  305. =======
  306. `bert`::::
  307. (Optional, object)
  308. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  309. +
  310. .Properties of bert
  311. [%collapsible%open]
  312. ========
  313. `do_lower_case`::::
  314. (Optional, boolean)
  315. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-do-lower-case]
  316. `max_sequence_length`::::
  317. (Optional, integer)
  318. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-max-sequence-length]
  319. `with_special_tokens`::::
  320. (Optional, boolean)
  321. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  322. ========
  323. =======
  324. `vocabulary`::::
  325. (Optional, object)
  326. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-vocabulary]
  327. +
  328. .Properties of vocabulary
  329. [%collapsible%open]
  330. =======
  331. `index`::::
  332. (Required, string)
  333. The index where the vocabulary is stored.
  334. =======
  335. ======
  336. `text_embedding`::::
  337. (Object, optional)
  338. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-embedding]
  339. +
  340. .Properties of text_embedding inference
  341. [%collapsible%open]
  342. ======
  343. `tokenization`::::
  344. (Optional, object)
  345. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  346. +
  347. .Properties of tokenization
  348. [%collapsible%open]
  349. =======
  350. `bert`::::
  351. (Optional, object)
  352. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  353. +
  354. .Properties of bert
  355. [%collapsible%open]
  356. ========
  357. `do_lower_case`::::
  358. (Optional, boolean)
  359. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-do-lower-case]
  360. `max_sequence_length`::::
  361. (Optional, integer)
  362. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-max-sequence-length]
  363. `with_special_tokens`::::
  364. (Optional, boolean)
  365. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  366. ========
  367. =======
  368. `vocabulary`::::
  369. (Optional, object)
  370. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-vocabulary]
  371. +
  372. .Properties of vocabulary
  373. [%collapsible%open]
  374. =======
  375. `index`::::
  376. (Required, string)
  377. The index where the vocabulary is stored.
  378. =======
  379. ======
  380. =====
  381. `input`:::
  382. (object)
  383. The input field names for the model definition.
  384. +
  385. .Properties of `input`
  386. [%collapsible%open]
  387. =====
  388. `field_names`::::
  389. (string)
  390. An array of input field names for the model.
  391. =====
  392. // Begin location
  393. `location`::
  394. (Optional, object)
  395. The model definition location. Must be provided if the `definition` or `compressed_definition` are not
  396. provided.
  397. +
  398. .Properties of `location`
  399. [%collapsible%open]
  400. =====
  401. `index`:::
  402. (Required, object)
  403. Indicates that the model definition is stored in an index. It is required to be empty as
  404. the index for storing model definitions is configured automatically.
  405. =====
  406. // End location
  407. `license_level`::
  408. (string)
  409. The license level of the trained model.
  410. `metadata`::
  411. (object)
  412. An object containing metadata about the trained model. For example, models
  413. created by {dfanalytics} contain `analysis_config` and `input` objects.
  414. +
  415. .Properties of metadata
  416. [%collapsible%open]
  417. =====
  418. `feature_importance_baseline`:::
  419. (object)
  420. An object that contains the baseline for {feat-imp} values. For {reganalysis},
  421. it is a single value. For {classanalysis}, there is a value for each class.
  422. `hyperparameters`:::
  423. (array)
  424. List of the available hyperparameters optimized during the
  425. `fine_parameter_tuning` phase as well as specified by the user.
  426. +
  427. .Properties of hyperparameters
  428. [%collapsible%open]
  429. ======
  430. `absolute_importance`::::
  431. (double)
  432. A positive number showing how much the parameter influences the variation of the
  433. {ml-docs}/dfa-regression-lossfunction.html[loss function]. For
  434. hyperparameters with values that are not specified by the user but tuned during
  435. hyperparameter optimization.
  436. `max_trees`::::
  437. (integer)
  438. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=max-trees-trained-models]
  439. `name`::::
  440. (string)
  441. Name of the hyperparameter.
  442. `relative_importance`::::
  443. (double)
  444. A number between 0 and 1 showing the proportion of influence on the variation of
  445. the loss function among all tuned hyperparameters. For hyperparameters with
  446. values that are not specified by the user but tuned during hyperparameter
  447. optimization.
  448. `supplied`::::
  449. (Boolean)
  450. Indicates if the hyperparameter is specified by the user (`true`) or optimized
  451. (`false`).
  452. `value`::::
  453. (double)
  454. The value of the hyperparameter, either optimized or specified by the user.
  455. ======
  456. `total_feature_importance`:::
  457. (array)
  458. An array of the total {feat-imp} for each feature used from
  459. the training data set. This array of objects is returned if {dfanalytics} trained
  460. the model and the request includes `total_feature_importance` in the `include`
  461. request parameter.
  462. +
  463. .Properties of total {feat-imp}
  464. [%collapsible%open]
  465. ======
  466. `feature_name`:::
  467. (string)
  468. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-feature-name]
  469. `importance`:::
  470. (object)
  471. A collection of {feat-imp} statistics related to the training data set for this particular feature.
  472. +
  473. .Properties of {feat-imp}
  474. [%collapsible%open]
  475. =======
  476. `mean_magnitude`:::
  477. (double)
  478. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-magnitude]
  479. `max`:::
  480. (integer)
  481. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-max]
  482. `min`:::
  483. (integer)
  484. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-min]
  485. =======
  486. `classes`:::
  487. (array)
  488. If the trained model is a classification model, {feat-imp} statistics are gathered
  489. per target class value.
  490. +
  491. .Properties of class {feat-imp}
  492. [%collapsible%open]
  493. =======
  494. `class_name`:::
  495. (string)
  496. The target class value. Could be a string, boolean, or number.
  497. `importance`:::
  498. (object)
  499. A collection of {feat-imp} statistics related to the training data set for this particular feature.
  500. +
  501. .Properties of {feat-imp}
  502. [%collapsible%open]
  503. ========
  504. `mean_magnitude`:::
  505. (double)
  506. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-magnitude]
  507. `max`:::
  508. (int)
  509. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-max]
  510. `min`:::
  511. (int)
  512. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-metadata-feature-importance-min]
  513. ========
  514. =======
  515. ======
  516. =====
  517. `model_id`::
  518. (string)
  519. Identifier for the trained model.
  520. `model_type`::
  521. (Optional, string)
  522. The created model type. By default the model type is `tree_ensemble`.
  523. Appropriate types are:
  524. +
  525. --
  526. * `tree_ensemble`: The model definition is an ensemble model of decision trees.
  527. * `lang_ident`: A special type reserved for language identification models.
  528. * `pytorch`: The stored definition is a PyTorch (specifically a TorchScript) model. Currently only
  529. NLP models are supported.
  530. --
  531. `tags`::
  532. (string)
  533. A comma delimited string of tags. A trained model can have many tags, or none.
  534. `version`::
  535. (string)
  536. The {es} version number in which the trained model was created.
  537. ====
  538. [[ml-get-trained-models-response-codes]]
  539. == {api-response-codes-title}
  540. `400`::
  541. If `include_model_definition` is `true`, this code indicates that more than
  542. one models match the ID pattern.
  543. `404` (Missing resources)::
  544. If `allow_no_match` is `false`, this code indicates that there are no
  545. resources that match the request or only partial matches for the request.
  546. [[ml-get-trained-models-example]]
  547. == {api-examples-title}
  548. The following example gets configuration information for all the trained models:
  549. [source,console]
  550. --------------------------------------------------
  551. GET _ml/trained_models/
  552. --------------------------------------------------
  553. // TEST[skip:TBD]