put-trained-models.asciidoc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. [role="xpack"]
  2. [[put-trained-models]]
  3. = Create trained models API
  4. [subs="attributes"]
  5. ++++
  6. <titleabbrev>Create trained models</titleabbrev>
  7. ++++
  8. Creates a trained model.
  9. WARNING: Models created in version 7.8.0 are not backwards compatible
  10. with older node versions. If in a mixed cluster environment,
  11. all nodes must be at least 7.8.0 to use a model stored by
  12. a 7.8.0 node.
  13. [[ml-put-trained-models-request]]
  14. == {api-request-title}
  15. `PUT _ml/trained_models/<model_id>`
  16. [[ml-put-trained-models-prereq]]
  17. == {api-prereq-title}
  18. Requires the `manage_ml` cluster privilege. This privilege is included in the
  19. `machine_learning_admin` built-in role.
  20. [[ml-put-trained-models-desc]]
  21. == {api-description-title}
  22. The create trained model API enables you to supply a trained model that is not
  23. created by {dfanalytics}.
  24. [[ml-put-trained-models-path-params]]
  25. == {api-path-parms-title}
  26. `<model_id>`::
  27. (Required, string)
  28. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-id]
  29. [[ml-put-trained-models-query-params]]
  30. == {api-query-parms-title}
  31. `defer_definition_decompression`::
  32. (Optional, boolean)
  33. If set to `true` and a `compressed_definition` is provided, the request defers
  34. definition decompression and skips relevant validations.
  35. This deferral is useful for systems or users that know a good byte size estimate for their
  36. model and know that their model is valid and likely won't fail during inference.
  37. [role="child_attributes"]
  38. [[ml-put-trained-models-request-body]]
  39. == {api-request-body-title}
  40. `compressed_definition`::
  41. (Required, string)
  42. The compressed (GZipped and Base64 encoded) {infer} definition of the model.
  43. If `compressed_definition` is specified, then `definition` cannot be specified.
  44. //Begin definition
  45. `definition`::
  46. (Required, object)
  47. The {infer} definition for the model. If `definition` is specified, then
  48. `compressed_definition` cannot be specified.
  49. +
  50. .Properties of `definition`
  51. [%collapsible%open]
  52. ====
  53. //Begin preprocessors
  54. `preprocessors`::
  55. (Optional, object)
  56. Collection of preprocessors. See <<ml-put-trained-models-preprocessor-example>>.
  57. +
  58. .Properties of `preprocessors`
  59. [%collapsible%open]
  60. =====
  61. //Begin frequency encoding
  62. `frequency_encoding`::
  63. (Required, object)
  64. Defines a frequency encoding for a field.
  65. +
  66. .Properties of `frequency_encoding`
  67. [%collapsible%open]
  68. ======
  69. `feature_name`::
  70. (Required, string)
  71. The name of the resulting feature.
  72. `field`::
  73. (Required, string)
  74. The field name to encode.
  75. `frequency_map`::
  76. (Required, object map of string:double)
  77. Object that maps the field value to the frequency encoded value.
  78. `custom`::
  79. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=custom-preprocessor]
  80. ======
  81. //End frequency encoding
  82. //Begin one hot encoding
  83. `one_hot_encoding`::
  84. (Required, object)
  85. Defines a one hot encoding map for a field.
  86. +
  87. .Properties of `one_hot_encoding`
  88. [%collapsible%open]
  89. ======
  90. `field`::
  91. (Required, string)
  92. The field name to encode.
  93. `hot_map`::
  94. (Required, object map of strings)
  95. String map of "field_value: one_hot_column_name".
  96. `custom`::
  97. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=custom-preprocessor]
  98. ======
  99. //End one hot encoding
  100. //Begin target mean encoding
  101. `target_mean_encoding`::
  102. (Required, object)
  103. Defines a target mean encoding for a field.
  104. +
  105. .Properties of `target_mean_encoding`
  106. [%collapsible%open]
  107. ======
  108. `default_value`:::
  109. (Required, double)
  110. The feature value if the field value is not in the `target_map`.
  111. `feature_name`:::
  112. (Required, string)
  113. The name of the resulting feature.
  114. `field`:::
  115. (Required, string)
  116. The field name to encode.
  117. `target_map`:::
  118. (Required, object map of string:double)
  119. Object that maps the field value to the target mean value.
  120. `custom`::
  121. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=custom-preprocessor]
  122. ======
  123. //End target mean encoding
  124. =====
  125. //End preprocessors
  126. //Begin trained model
  127. `trained_model`::
  128. (Required, object)
  129. The definition of the trained model.
  130. +
  131. .Properties of `trained_model`
  132. [%collapsible%open]
  133. =====
  134. //Begin tree
  135. `tree`::
  136. (Required, object)
  137. The definition for a binary decision tree.
  138. +
  139. .Properties of `tree`
  140. [%collapsible%open]
  141. ======
  142. `classification_labels`:::
  143. (Optional, string) An array of classification labels (used for
  144. `classification`).
  145. `feature_names`:::
  146. (Required, string)
  147. Features expected by the tree, in their expected order.
  148. `target_type`:::
  149. (Required, string)
  150. String indicating the model target type; `regression` or `classification`.
  151. `tree_structure`:::
  152. (Required, object)
  153. An array of `tree_node` objects. The nodes must be in ordinal order by their
  154. `tree_node.node_index` value.
  155. ======
  156. //End tree
  157. //Begin tree node
  158. `tree_node`::
  159. (Required, object)
  160. The definition of a node in a tree.
  161. +
  162. --
  163. There are two major types of nodes: leaf nodes and not-leaf nodes.
  164. * Leaf nodes only need `node_index` and `leaf_value` defined.
  165. * All other nodes need `split_feature`, `left_child`, `right_child`,
  166. `threshold`, `decision_type`, and `default_left` defined.
  167. --
  168. +
  169. .Properties of `tree_node`
  170. [%collapsible%open]
  171. ======
  172. `decision_type`::
  173. (Optional, string)
  174. Indicates the positive value (in other words, when to choose the left node)
  175. decision type. Supported `lt`, `lte`, `gt`, `gte`. Defaults to `lte`.
  176. `default_left`::
  177. (Optional, Boolean)
  178. Indicates whether to default to the left when the feature is missing. Defaults
  179. to `true`.
  180. `leaf_value`::
  181. (Optional, double)
  182. The leaf value of the of the node, if the value is a leaf (in other words, no
  183. children).
  184. `left_child`::
  185. (Optional, integer)
  186. The index of the left child.
  187. `node_index`::
  188. (Integer)
  189. The index of the current node.
  190. `right_child`::
  191. (Optional, integer)
  192. The index of the right child.
  193. `split_feature`::
  194. (Optional, integer)
  195. The index of the feature value in the feature array.
  196. `split_gain`::
  197. (Optional, double) The information gain from the split.
  198. `threshold`::
  199. (Optional, double)
  200. The decision threshold with which to compare the feature value.
  201. ======
  202. //End tree node
  203. //Begin ensemble
  204. `ensemble`::
  205. (Optional, object)
  206. The definition for an ensemble model. See <<ml-put-trained-models-model-example>>.
  207. +
  208. .Properties of `ensemble`
  209. [%collapsible%open]
  210. ======
  211. //Begin aggregate output
  212. `aggregate_output`::
  213. (Required, object)
  214. An aggregated output object that defines how to aggregate the outputs of the
  215. `trained_models`. Supported objects are `weighted_mode`, `weighted_sum`, and
  216. `logistic_regression`. See <<ml-put-trained-models-aggregated-output-example>>.
  217. +
  218. .Properties of `aggregate_output`
  219. [%collapsible%open]
  220. =======
  221. //Begin logistic regression
  222. `logistic_regression`::
  223. (Optional, object)
  224. This `aggregated_output` type works with binary classification (classification
  225. for values [0, 1]). It multiplies the outputs (in the case of the `ensemble`
  226. model, the inference model values) by the supplied `weights`. The resulting
  227. vector is summed and passed to a
  228. {wikipedia}/Sigmoid_function[`sigmoid` function]. The result
  229. of the `sigmoid` function is considered the probability of class 1 (`P_1`),
  230. consequently, the probability of class 0 is `1 - P_1`. The class with the
  231. highest probability (either 0 or 1) is then returned. For more information about
  232. logistic regression, see
  233. {wikipedia}/Logistic_regression[this wiki article].
  234. +
  235. .Properties of `logistic_regression`
  236. [%collapsible%open]
  237. ========
  238. `weights`:::
  239. (Required, double)
  240. The weights to multiply by the input values (the inference values of the trained
  241. models).
  242. ========
  243. //End logistic regression
  244. //Begin weighted sum
  245. `weighted_sum`::
  246. (Optional, object)
  247. This `aggregated_output` type works with regression. The weighted sum of the
  248. input values.
  249. +
  250. .Properties of `weighted_sum`
  251. [%collapsible%open]
  252. ========
  253. `weights`:::
  254. (Required, double)
  255. The weights to multiply by the input values (the inference values of the trained
  256. models).
  257. ========
  258. //End weighted sum
  259. //Begin weighted mode
  260. `weighted_mode`::
  261. (Optional, object)
  262. This `aggregated_output` type works with regression or classification. It takes
  263. a weighted vote of the input values. The most common input value (taking the
  264. weights into account) is returned.
  265. +
  266. .Properties of `weighted_mode`
  267. [%collapsible%open]
  268. ========
  269. `weights`:::
  270. (Required, double)
  271. The weights to multiply by the input values (the inference values of the trained
  272. models).
  273. ========
  274. //End weighted mode
  275. //Begin exponent
  276. `exponent`::
  277. (Optional, object)
  278. This `aggregated_output` type works with regression. It takes a weighted sum of
  279. the input values and passes the result to an exponent function
  280. (`e^x` where `x` is the sum of the weighted values).
  281. +
  282. .Properties of `exponent`
  283. [%collapsible%open]
  284. ========
  285. `weights`:::
  286. (Required, double)
  287. The weights to multiply by the input values (the inference values of the trained
  288. models).
  289. ========
  290. //End exponent
  291. =======
  292. //End aggregate output
  293. `classification_labels`::
  294. (Optional, string)
  295. An array of classification labels.
  296. `feature_names`::
  297. (Optional, string)
  298. Features expected by the ensemble, in their expected order.
  299. `target_type`::
  300. (Required, string)
  301. String indicating the model target type; `regression` or `classification.`
  302. `trained_models`::
  303. (Required, object)
  304. An array of `trained_model` objects. Supported trained models are `tree` and
  305. `ensemble`.
  306. ======
  307. //End ensemble
  308. =====
  309. //End trained model
  310. ====
  311. //End definition
  312. `description`::
  313. (Optional, string)
  314. A human-readable description of the {infer} trained model.
  315. `estimated_heap_memory_usage_bytes`::
  316. (Optional, integer) deprecated:[7.16.0,Replaced by `model_size_bytes`]
  317. `estimated_operations`::
  318. (Optional, integer)
  319. The estimated number of operations to use the trained model during inference.
  320. This property is supported only if `defer_definition_decompression` is `true` or
  321. the model definition is not supplied.
  322. //Begin inference_config
  323. `inference_config`::
  324. (Required, object)
  325. The default configuration for inference. This can be: `regression`,
  326. `classification`, `fill_mask`, `ner`, `text_classification`, `text_embedding` or `zero_shot_classification`.
  327. If `regression` or `classification`, it must match the `target_type` of the
  328. underlying `definition.trained_model`. If `fill_mask`, `ner`,
  329. `text_classification`, or `text_embedding`; the `model_type` must be `pytorch`.
  330. +
  331. .Properties of `inference_config`
  332. [%collapsible%open]
  333. ====
  334. `classification`:::
  335. (Optional, object)
  336. Classification configuration for inference.
  337. +
  338. .Properties of classification inference
  339. [%collapsible%open]
  340. =====
  341. `num_top_classes`::::
  342. (Optional, integer)
  343. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-classes]
  344. `num_top_feature_importance_values`::::
  345. (Optional, integer)
  346. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-feature-importance-values]
  347. `prediction_field_type`::::
  348. (Optional, string)
  349. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-prediction-field-type]
  350. `results_field`::::
  351. (Optional, string)
  352. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  353. `top_classes_results_field`::::
  354. (Optional, string)
  355. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-top-classes-results-field]
  356. =====
  357. `fill_mask`:::
  358. (Optional, object)
  359. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-fill-mask]
  360. +
  361. .Properties of fill_mask inference
  362. [%collapsible%open]
  363. =====
  364. `tokenization`::::
  365. (Optional, object)
  366. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  367. +
  368. .Properties of tokenization
  369. [%collapsible%open]
  370. ======
  371. `bert`::::
  372. (Optional, object)
  373. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  374. +
  375. .Properties of bert
  376. [%collapsible%open]
  377. =======
  378. `do_lower_case`::::
  379. (Optional, boolean)
  380. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-do-lower-case]
  381. `max_sequence_length`::::
  382. (Optional, integer)
  383. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-max-sequence-length]
  384. `truncate`::::
  385. (Optional, string)
  386. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-truncate]
  387. `with_special_tokens`::::
  388. (Optional, boolean)
  389. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  390. =======
  391. ======
  392. =====
  393. `ner`:::
  394. (Optional, object)
  395. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-ner]
  396. +
  397. .Properties of ner inference
  398. [%collapsible%open]
  399. =====
  400. `classification_labels`::::
  401. (Optional, string)
  402. An array of classification labels. NER only supports Inside-Outside-Beginning labels (IOB)
  403. and only persons, organizations, locations, and miscellaneous.
  404. Example: ["O", "B-PER", "I-PER", "B-ORG", "I-ORG", "B-LOC", "I-LOC", "B-MISC", "I-MISC"]
  405. `tokenization`::::
  406. (Optional, object)
  407. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  408. +
  409. .Properties of tokenization
  410. [%collapsible%open]
  411. ======
  412. `bert`::::
  413. (Optional, object)
  414. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  415. +
  416. .Properties of bert
  417. [%collapsible%open]
  418. =======
  419. `do_lower_case`::::
  420. (Optional, boolean)
  421. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-do-lower-case]
  422. `max_sequence_length`::::
  423. (Optional, integer)
  424. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-max-sequence-length]
  425. `truncate`::::
  426. (Optional, string)
  427. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-truncate]
  428. `with_special_tokens`::::
  429. (Optional, boolean)
  430. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  431. =======
  432. ======
  433. =====
  434. `pass_through`:::
  435. (Optional, object)
  436. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-pass-through]
  437. +
  438. .Properties of pass_through inference
  439. [%collapsible%open]
  440. =====
  441. `tokenization`::::
  442. (Optional, object)
  443. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  444. +
  445. .Properties of tokenization
  446. [%collapsible%open]
  447. ======
  448. `bert`::::
  449. (Optional, object)
  450. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  451. +
  452. .Properties of bert
  453. [%collapsible%open]
  454. =======
  455. `do_lower_case`::::
  456. (Optional, boolean)
  457. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-do-lower-case]
  458. `max_sequence_length`::::
  459. (Optional, integer)
  460. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-max-sequence-length]
  461. `truncate`::::
  462. (Optional, string)
  463. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-truncate]
  464. `with_special_tokens`::::
  465. (Optional, boolean)
  466. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  467. =======
  468. ======
  469. =====
  470. `regression`:::
  471. (Optional, object)
  472. Regression configuration for inference.
  473. +
  474. .Properties of regression inference
  475. [%collapsible%open]
  476. =====
  477. `num_top_feature_importance_values`::::
  478. (Optional, integer)
  479. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-regression-num-top-feature-importance-values]
  480. `results_field`::::
  481. (Optional, string)
  482. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  483. =====
  484. `text_classification`:::
  485. (Optional, object)
  486. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-classification]
  487. +
  488. .Properties of text_classification inference
  489. [%collapsible%open]
  490. =====
  491. `classification_labels`::::
  492. (Optional, string) An array of classification labels.
  493. `num_top_classes`::::
  494. (Optional, integer)
  495. Specifies the number of top class predictions to return. Defaults to all classes (-1).
  496. `tokenization`::::
  497. (Optional, object)
  498. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  499. +
  500. .Properties of tokenization
  501. [%collapsible%open]
  502. ======
  503. `bert`::::
  504. (Optional, object)
  505. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  506. +
  507. .Properties of bert
  508. [%collapsible%open]
  509. =======
  510. `do_lower_case`::::
  511. (Optional, boolean)
  512. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-do-lower-case]
  513. `max_sequence_length`::::
  514. (Optional, integer)
  515. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-max-sequence-length]
  516. `truncate`::::
  517. (Optional, string)
  518. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-truncate]
  519. `with_special_tokens`::::
  520. (Optional, boolean)
  521. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  522. =======
  523. ======
  524. =====
  525. `text_embedding`:::
  526. (Object, optional)
  527. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-embedding]
  528. +
  529. .Properties of text_embedding inference
  530. [%collapsible%open]
  531. =====
  532. `tokenization`::::
  533. (Optional, object)
  534. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  535. +
  536. .Properties of tokenization
  537. [%collapsible%open]
  538. ======
  539. `bert`::::
  540. (Optional, object)
  541. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  542. +
  543. .Properties of bert
  544. [%collapsible%open]
  545. =======
  546. `do_lower_case`::::
  547. (Optional, boolean)
  548. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-do-lower-case]
  549. `max_sequence_length`::::
  550. (Optional, integer)
  551. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-max-sequence-length]
  552. `truncate`::::
  553. (Optional, string)
  554. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-truncate]
  555. `with_special_tokens`::::
  556. (Optional, boolean)
  557. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  558. =======
  559. ======
  560. =====
  561. `zero_shot_classification`:::
  562. (Object, optional)
  563. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-zero-shot-classification]
  564. +
  565. .Properties of zero_shot_classification inference
  566. [%collapsible%open]
  567. =====
  568. `classification_labels`::::
  569. (Required, array)
  570. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-zero-shot-classification-classification-labels]
  571. `hypothesis_template`::::
  572. (Optional, string)
  573. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-zero-shot-classification-hypothesis-template]
  574. `labels`::::
  575. (Optional, array)
  576. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-zero-shot-classification-labels]
  577. `multi_label`::::
  578. (Optional, boolean)
  579. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-zero-shot-classification-multi-label]
  580. `tokenization`::::
  581. (Optional, object)
  582. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  583. +
  584. .Properties of tokenization
  585. [%collapsible%open]
  586. ======
  587. `bert`::::
  588. (Optional, object)
  589. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  590. +
  591. .Properties of bert
  592. [%collapsible%open]
  593. =======
  594. `do_lower_case`::::
  595. (Optional, boolean)
  596. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-do-lower-case]
  597. `max_sequence_length`::::
  598. (Optional, integer)
  599. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-max-sequence-length]
  600. `truncate`::::
  601. (Optional, string)
  602. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-truncate]
  603. `with_special_tokens`::::
  604. (Optional, boolean)
  605. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  606. =======
  607. ======
  608. =====
  609. ====
  610. //End of inference_config
  611. //Begin input
  612. `input`::
  613. (Required, object)
  614. The input field names for the model definition.
  615. +
  616. .Properties of `input`
  617. [%collapsible%open]
  618. ====
  619. `field_names`:::
  620. (Required, string)
  621. An array of input field names for the model.
  622. ====
  623. //End input
  624. // Begin location
  625. `location`::
  626. (Optional, object)
  627. The model definition location. If the `definition` or `compressed_definition`
  628. are not specified, the `location` is required.
  629. +
  630. .Properties of `location`
  631. [%collapsible%open]
  632. ====
  633. `index`:::
  634. (Required, object)
  635. Indicates that the model definition is stored in an index. This object must be
  636. empty as the index for storing model definitions is configured automatically.
  637. ====
  638. // End location
  639. `metadata`::
  640. (Optional, object)
  641. An object map that contains metadata about the model.
  642. `model_size_bytes`::
  643. (Optional, integer)
  644. The estimated memory usage in bytes to keep the trained model in memory. This
  645. property is supported only if `defer_definition_decompression` is `true` or the
  646. model definition is not supplied.
  647. `model_type`::
  648. (Optional, string)
  649. The created model type. By default the model type is `tree_ensemble`.
  650. Appropriate types are:
  651. +
  652. --
  653. * `tree_ensemble`: The model definition is an ensemble model of decision trees.
  654. * `lang_ident`: A special type reserved for language identification models.
  655. * `pytorch`: The stored definition is a PyTorch (specifically a TorchScript) model. Currently only
  656. NLP models are supported.
  657. --
  658. `tags`::
  659. (Optional, string)
  660. An array of tags to organize the model.
  661. [[ml-put-trained-models-example]]
  662. == {api-examples-title}
  663. [[ml-put-trained-models-preprocessor-example]]
  664. === Preprocessor examples
  665. The example below shows a `frequency_encoding` preprocessor object:
  666. [source,js]
  667. ----------------------------------
  668. {
  669. "frequency_encoding":{
  670. "field":"FlightDelayType",
  671. "feature_name":"FlightDelayType_frequency",
  672. "frequency_map":{
  673. "Carrier Delay":0.6007414737092798,
  674. "NAS Delay":0.6007414737092798,
  675. "Weather Delay":0.024573576178086153,
  676. "Security Delay":0.02476631010889467,
  677. "No Delay":0.6007414737092798,
  678. "Late Aircraft Delay":0.6007414737092798
  679. }
  680. }
  681. }
  682. ----------------------------------
  683. //NOTCONSOLE
  684. The next example shows a `one_hot_encoding` preprocessor object:
  685. [source,js]
  686. ----------------------------------
  687. {
  688. "one_hot_encoding":{
  689. "field":"FlightDelayType",
  690. "hot_map":{
  691. "Carrier Delay":"FlightDelayType_Carrier Delay",
  692. "NAS Delay":"FlightDelayType_NAS Delay",
  693. "No Delay":"FlightDelayType_No Delay",
  694. "Late Aircraft Delay":"FlightDelayType_Late Aircraft Delay"
  695. }
  696. }
  697. }
  698. ----------------------------------
  699. //NOTCONSOLE
  700. This example shows a `target_mean_encoding` preprocessor object:
  701. [source,js]
  702. ----------------------------------
  703. {
  704. "target_mean_encoding":{
  705. "field":"FlightDelayType",
  706. "feature_name":"FlightDelayType_targetmean",
  707. "target_map":{
  708. "Carrier Delay":39.97465788139886,
  709. "NAS Delay":39.97465788139886,
  710. "Security Delay":203.171206225681,
  711. "Weather Delay":187.64705882352948,
  712. "No Delay":39.97465788139886,
  713. "Late Aircraft Delay":39.97465788139886
  714. },
  715. "default_value":158.17995752420433
  716. }
  717. }
  718. ----------------------------------
  719. //NOTCONSOLE
  720. [[ml-put-trained-models-model-example]]
  721. === Model examples
  722. The first example shows a `trained_model` object:
  723. [source,js]
  724. ----------------------------------
  725. {
  726. "tree":{
  727. "feature_names":[
  728. "DistanceKilometers",
  729. "FlightTimeMin",
  730. "FlightDelayType_NAS Delay",
  731. "Origin_targetmean",
  732. "DestRegion_targetmean",
  733. "DestCityName_targetmean",
  734. "OriginAirportID_targetmean",
  735. "OriginCityName_frequency",
  736. "DistanceMiles",
  737. "FlightDelayType_Late Aircraft Delay"
  738. ],
  739. "tree_structure":[
  740. {
  741. "decision_type":"lt",
  742. "threshold":9069.33437193022,
  743. "split_feature":0,
  744. "split_gain":4112.094574306927,
  745. "node_index":0,
  746. "default_left":true,
  747. "left_child":1,
  748. "right_child":2
  749. },
  750. ...
  751. {
  752. "node_index":9,
  753. "leaf_value":-27.68987349695448
  754. },
  755. ...
  756. ],
  757. "target_type":"regression"
  758. }
  759. }
  760. ----------------------------------
  761. //NOTCONSOLE
  762. The following example shows an `ensemble` model object:
  763. [source,js]
  764. ----------------------------------
  765. "ensemble":{
  766. "feature_names":[
  767. ...
  768. ],
  769. "trained_models":[
  770. {
  771. "tree":{
  772. "feature_names":[],
  773. "tree_structure":[
  774. {
  775. "decision_type":"lte",
  776. "node_index":0,
  777. "leaf_value":47.64069875778043,
  778. "default_left":false
  779. }
  780. ],
  781. "target_type":"regression"
  782. }
  783. },
  784. ...
  785. ],
  786. "aggregate_output":{
  787. "weighted_sum":{
  788. "weights":[
  789. ...
  790. ]
  791. }
  792. },
  793. "target_type":"regression"
  794. }
  795. ----------------------------------
  796. //NOTCONSOLE
  797. [[ml-put-trained-models-aggregated-output-example]]
  798. === Aggregated output example
  799. Example of a `logistic_regression` object:
  800. [source,js]
  801. ----------------------------------
  802. "aggregate_output" : {
  803. "logistic_regression" : {
  804. "weights" : [2.0, 1.0, .5, -1.0, 5.0, 1.0, 1.0]
  805. }
  806. }
  807. ----------------------------------
  808. //NOTCONSOLE
  809. Example of a `weighted_sum` object:
  810. [source,js]
  811. ----------------------------------
  812. "aggregate_output" : {
  813. "weighted_sum" : {
  814. "weights" : [1.0, -1.0, .5, 1.0, 5.0]
  815. }
  816. }
  817. ----------------------------------
  818. //NOTCONSOLE
  819. Example of a `weighted_mode` object:
  820. [source,js]
  821. ----------------------------------
  822. "aggregate_output" : {
  823. "weighted_mode" : {
  824. "weights" : [1.0, 1.0, 1.0, 1.0, 1.0]
  825. }
  826. }
  827. ----------------------------------
  828. //NOTCONSOLE
  829. Example of an `exponent` object:
  830. [source,js]
  831. ----------------------------------
  832. "aggregate_output" : {
  833. "exponent" : {
  834. "weights" : [1.0, 1.0, 1.0, 1.0, 1.0]
  835. }
  836. }
  837. ----------------------------------
  838. //NOTCONSOLE
  839. [[ml-put-trained-models-json-schema]]
  840. === Trained models JSON schema
  841. For the full JSON schema of trained models,
  842. https://github.com/elastic/ml-json-schemas[click here].