infer-trained-model.asciidoc 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  1. [role="xpack"]
  2. [[infer-trained-model]]
  3. = Infer trained model API
  4. [subs="attributes"]
  5. ++++
  6. <titleabbrev>Infer trained model</titleabbrev>
  7. ++++
  8. Evaluates a trained model. The model may be any supervised model either trained
  9. by {dfanalytics} or imported.
  10. NOTE: For model deployments with caching enabled, results may be returned
  11. directly from the {infer} cache.
  12. [[infer-trained-model-request]]
  13. == {api-request-title}
  14. `POST _ml/trained_models/<model_id>/_infer`
  15. `POST _ml/trained_models/<deployment_id>/_infer`
  16. ////
  17. [[infer-trained-model-prereq]]
  18. == {api-prereq-title}
  19. ////
  20. ////
  21. [[infer-trained-model-desc]]
  22. == {api-description-title}
  23. ////
  24. [[infer-trained-model-path-params]]
  25. == {api-path-parms-title}
  26. `<model_id>`::
  27. (Optional, string)
  28. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-id-or-alias]
  29. If you specify the `model_id` in the API call, and the model has multiple
  30. deployments, a random deployment will be used. If the `model_id` matches the ID
  31. of one of the deployments, that deployment will be used.
  32. `<deployment_id>`::
  33. (Optional, string)
  34. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=deployment-id]
  35. [[infer-trained-model-query-params]]
  36. == {api-query-parms-title}
  37. `timeout`::
  38. (Optional, time)
  39. Controls the amount of time to wait for {infer} results. Defaults to 10 seconds.
  40. [[infer-trained-model-request-body]]
  41. == {api-request-body-title}
  42. `docs`::
  43. (Required, array)
  44. An array of objects to pass to the model for inference. The objects should
  45. contain the fields matching your configured trained model input. Typically for
  46. NLP models, the field name is `text_field`.
  47. //Begin inference_config
  48. `inference_config`::
  49. (Required, object)
  50. The default configuration for inference. This can be: `regression`,
  51. `classification`, `fill_mask`, `ner`, `question_answering`,
  52. `text_classification`, `text_embedding` or `zero_shot_classification`.
  53. If `regression` or `classification`, it must match the `target_type` of the
  54. underlying `definition.trained_model`. If `fill_mask`, `ner`,
  55. `question_answering`, `text_classification`, or `text_embedding`; the
  56. `model_type` must be `pytorch`.
  57. +
  58. .Properties of `inference_config`
  59. [%collapsible%open]
  60. ====
  61. `classification`:::
  62. (Optional, object)
  63. Classification configuration for inference.
  64. +
  65. .Properties of classification inference
  66. [%collapsible%open]
  67. =====
  68. `num_top_classes`::::
  69. (Optional, integer)
  70. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-classes]
  71. `num_top_feature_importance_values`::::
  72. (Optional, integer)
  73. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-feature-importance-values]
  74. `prediction_field_type`::::
  75. (Optional, string)
  76. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-prediction-field-type]
  77. `results_field`::::
  78. (Optional, string)
  79. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  80. `top_classes_results_field`::::
  81. (Optional, string)
  82. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-top-classes-results-field]
  83. =====
  84. `fill_mask`:::
  85. (Optional, object)
  86. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-fill-mask]
  87. +
  88. .Properties of fill_mask inference
  89. [%collapsible%open]
  90. =====
  91. `num_top_classes`::::
  92. (Optional, integer)
  93. Number of top predicted tokens to return for replacing the mask token. Defaults
  94. to `0`.
  95. `results_field`::::
  96. (Optional, string)
  97. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  98. `tokenization`::::
  99. (Optional, object)
  100. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  101. +
  102. .Properties of tokenization
  103. [%collapsible%open]
  104. ======
  105. `bert`::::
  106. (Optional, object)
  107. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  108. +
  109. .Properties of bert
  110. [%collapsible%open]
  111. =======
  112. `truncate`::::
  113. (Optional, string)
  114. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  115. =======
  116. `roberta`::::
  117. (Optional, object)
  118. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
  119. +
  120. .Properties of roberta
  121. [%collapsible%open]
  122. =======
  123. `truncate`::::
  124. (Optional, string)
  125. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  126. =======
  127. `mpnet`::::
  128. (Optional, object)
  129. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
  130. +
  131. .Properties of mpnet
  132. [%collapsible%open]
  133. =======
  134. `truncate`::::
  135. (Optional, string)
  136. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  137. =======
  138. `xlm_roberta`::::
  139. (Optional, object)
  140. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
  141. +
  142. .Properties of xlm_roberta
  143. [%collapsible%open]
  144. =======
  145. `truncate`::::
  146. (Optional, string)
  147. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  148. =======
  149. `bert_ja`::::
  150. (Optional, object)
  151. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
  152. +
  153. .Properties of bert_ja
  154. [%collapsible%open]
  155. =======
  156. `truncate`::::
  157. (Optional, string)
  158. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  159. =======
  160. ======
  161. =====
  162. `ner`:::
  163. (Optional, object)
  164. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-ner]
  165. +
  166. .Properties of ner inference
  167. [%collapsible%open]
  168. =====
  169. `results_field`::::
  170. (Optional, string)
  171. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  172. `tokenization`::::
  173. (Optional, object)
  174. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  175. +
  176. .Properties of tokenization
  177. [%collapsible%open]
  178. ======
  179. `bert`::::
  180. (Optional, object)
  181. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  182. +
  183. .Properties of bert
  184. [%collapsible%open]
  185. =======
  186. `truncate`::::
  187. (Optional, string)
  188. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  189. =======
  190. `roberta`::::
  191. (Optional, object)
  192. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
  193. +
  194. .Properties of roberta
  195. [%collapsible%open]
  196. =======
  197. `truncate`::::
  198. (Optional, string)
  199. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  200. =======
  201. `mpnet`::::
  202. (Optional, object)
  203. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
  204. +
  205. .Properties of mpnet
  206. [%collapsible%open]
  207. =======
  208. `truncate`::::
  209. (Optional, string)
  210. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  211. =======
  212. `xlm_roberta`::::
  213. (Optional, object)
  214. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
  215. +
  216. .Properties of xlm_roberta
  217. [%collapsible%open]
  218. =======
  219. `truncate`::::
  220. (Optional, string)
  221. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  222. =======
  223. `bert_ja`::::
  224. (Optional, object)
  225. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
  226. +
  227. .Properties of bert_ja
  228. [%collapsible%open]
  229. =======
  230. `truncate`::::
  231. (Optional, string)
  232. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  233. =======
  234. ======
  235. =====
  236. `pass_through`:::
  237. (Optional, object)
  238. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-pass-through]
  239. +
  240. .Properties of pass_through inference
  241. [%collapsible%open]
  242. =====
  243. `results_field`::::
  244. (Optional, string)
  245. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  246. `tokenization`::::
  247. (Optional, object)
  248. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  249. +
  250. .Properties of tokenization
  251. [%collapsible%open]
  252. ======
  253. `bert`::::
  254. (Optional, object)
  255. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  256. +
  257. .Properties of bert
  258. [%collapsible%open]
  259. =======
  260. `truncate`::::
  261. (Optional, string)
  262. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  263. =======
  264. `roberta`::::
  265. (Optional, object)
  266. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
  267. +
  268. .Properties of roberta
  269. [%collapsible%open]
  270. =======
  271. `truncate`::::
  272. (Optional, string)
  273. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  274. =======
  275. `mpnet`::::
  276. (Optional, object)
  277. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
  278. +
  279. .Properties of mpnet
  280. [%collapsible%open]
  281. =======
  282. `truncate`::::
  283. (Optional, string)
  284. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  285. =======
  286. `xlm_roberta`::::
  287. (Optional, object)
  288. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
  289. +
  290. .Properties of xlm_roberta
  291. [%collapsible%open]
  292. =======
  293. `truncate`::::
  294. (Optional, string)
  295. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  296. =======
  297. `bert_ja`::::
  298. (Optional, object)
  299. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
  300. +
  301. .Properties of bert_ja
  302. [%collapsible%open]
  303. =======
  304. `truncate`::::
  305. (Optional, string)
  306. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  307. =======
  308. ======
  309. =====
  310. `question_answering`:::
  311. (Optional, object)
  312. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-question-answering]
  313. +
  314. .Properties of question_answering inference
  315. [%collapsible%open]
  316. =====
  317. `max_answer_length`::::
  318. (Optional, integer)
  319. The maximum amount of words in the answer. Defaults to `15`.
  320. `num_top_classes`::::
  321. (Optional, integer)
  322. The number the top found answers to return. Defaults to `0`, meaning only the
  323. best found answer is returned.
  324. `question`::::
  325. (Required, string)
  326. The question to use when extracting an answer
  327. `results_field`::::
  328. (Optional, string)
  329. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  330. `tokenization`::::
  331. (Optional, object)
  332. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  333. +
  334. Recommended to set `max_sequence_length` to `386` with `128` of `span` and set
  335. `truncate` to `none`.
  336. +
  337. .Properties of tokenization
  338. [%collapsible%open]
  339. ======
  340. `bert`::::
  341. (Optional, object)
  342. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  343. +
  344. .Properties of bert
  345. [%collapsible%open]
  346. =======
  347. `span`::::
  348. (Optional, integer)
  349. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  350. `truncate`::::
  351. (Optional, string)
  352. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  353. =======
  354. `roberta`::::
  355. (Optional, object)
  356. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
  357. +
  358. .Properties of roberta
  359. [%collapsible%open]
  360. =======
  361. `span`::::
  362. (Optional, integer)
  363. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  364. `truncate`::::
  365. (Optional, string)
  366. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  367. =======
  368. `mpnet`::::
  369. (Optional, object)
  370. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
  371. +
  372. .Properties of mpnet
  373. [%collapsible%open]
  374. =======
  375. `span`::::
  376. (Optional, integer)
  377. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  378. `truncate`::::
  379. (Optional, string)
  380. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  381. =======
  382. `xlm_roberta`::::
  383. (Optional, object)
  384. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
  385. +
  386. .Properties of xlm_roberta
  387. [%collapsible%open]
  388. =======
  389. `span`::::
  390. (Optional, integer)
  391. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  392. `truncate`::::
  393. (Optional, string)
  394. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  395. =======
  396. `bert_ja`::::
  397. (Optional, object)
  398. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
  399. +
  400. .Properties of bert_ja
  401. [%collapsible%open]
  402. =======
  403. `span`::::
  404. (Optional, integer)
  405. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  406. `truncate`::::
  407. (Optional, string)
  408. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  409. =======
  410. ======
  411. =====
  412. `regression`:::
  413. (Optional, object)
  414. Regression configuration for inference.
  415. +
  416. .Properties of regression inference
  417. [%collapsible%open]
  418. =====
  419. `num_top_feature_importance_values`::::
  420. (Optional, integer)
  421. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-regression-num-top-feature-importance-values]
  422. `results_field`::::
  423. (Optional, string)
  424. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  425. =====
  426. `text_classification`:::
  427. (Optional, object)
  428. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-classification]
  429. +
  430. .Properties of text_classification inference
  431. [%collapsible%open]
  432. =====
  433. `classification_labels`::::
  434. (Optional, string) An array of classification labels.
  435. `num_top_classes`::::
  436. (Optional, integer)
  437. Specifies the number of top class predictions to return. Defaults to all classes
  438. (-1).
  439. `results_field`::::
  440. (Optional, string)
  441. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  442. `tokenization`::::
  443. (Optional, object)
  444. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  445. +
  446. .Properties of tokenization
  447. [%collapsible%open]
  448. ======
  449. `bert`::::
  450. (Optional, object)
  451. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  452. +
  453. .Properties of bert
  454. [%collapsible%open]
  455. =======
  456. `span`::::
  457. (Optional, integer)
  458. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  459. `truncate`::::
  460. (Optional, string)
  461. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  462. =======
  463. `roberta`::::
  464. (Optional, object)
  465. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
  466. +
  467. .Properties of roberta
  468. [%collapsible%open]
  469. =======
  470. `span`::::
  471. (Optional, integer)
  472. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  473. `truncate`::::
  474. (Optional, string)
  475. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  476. =======
  477. `mpnet`::::
  478. (Optional, object)
  479. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
  480. +
  481. .Properties of mpnet
  482. [%collapsible%open]
  483. =======
  484. `span`::::
  485. (Optional, integer)
  486. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  487. `truncate`::::
  488. (Optional, string)
  489. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  490. =======
  491. `xlm_roberta`::::
  492. (Optional, object)
  493. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
  494. +
  495. .Properties of xlm_roberta
  496. [%collapsible%open]
  497. =======
  498. `span`::::
  499. (Optional, integer)
  500. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  501. `truncate`::::
  502. (Optional, string)
  503. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  504. =======
  505. `bert_ja`::::
  506. (Optional, object)
  507. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
  508. +
  509. .Properties of bert_ja
  510. [%collapsible%open]
  511. =======
  512. `span`::::
  513. (Optional, integer)
  514. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  515. `truncate`::::
  516. (Optional, string)
  517. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  518. =======
  519. ======
  520. =====
  521. `text_embedding`:::
  522. (Object, optional)
  523. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-embedding]
  524. +
  525. .Properties of text_embedding inference
  526. [%collapsible%open]
  527. =====
  528. `results_field`::::
  529. (Optional, string)
  530. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  531. `tokenization`::::
  532. (Optional, object)
  533. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  534. +
  535. .Properties of tokenization
  536. [%collapsible%open]
  537. ======
  538. `bert`::::
  539. (Optional, object)
  540. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  541. +
  542. .Properties of bert
  543. [%collapsible%open]
  544. =======
  545. `truncate`::::
  546. (Optional, string)
  547. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  548. =======
  549. `roberta`::::
  550. (Optional, object)
  551. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
  552. +
  553. .Properties of roberta
  554. [%collapsible%open]
  555. =======
  556. `truncate`::::
  557. (Optional, string)
  558. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  559. =======
  560. `mpnet`::::
  561. (Optional, object)
  562. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
  563. +
  564. .Properties of mpnet
  565. [%collapsible%open]
  566. =======
  567. `truncate`::::
  568. (Optional, string)
  569. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  570. =======
  571. `xlm_roberta`::::
  572. (Optional, object)
  573. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
  574. +
  575. .Properties of xlm_roberta
  576. [%collapsible%open]
  577. =======
  578. `truncate`::::
  579. (Optional, string)
  580. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  581. =======
  582. `bert_ja`::::
  583. (Optional, object)
  584. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
  585. +
  586. .Properties of bert_ja
  587. [%collapsible%open]
  588. =======
  589. `truncate`::::
  590. (Optional, string)
  591. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  592. =======
  593. ======
  594. =====
  595. `text_similarity`:::
  596. (Object, optional)
  597. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-similarity]
  598. +
  599. .Properties of text_similarity inference
  600. [%collapsible%open]
  601. =====
  602. `span_score_combination_function`::::
  603. (Optional, string)
  604. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-similarity-span-score-func]
  605. `text`::::
  606. (Required, string)
  607. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-similarity-text]
  608. `tokenization`::::
  609. (Optional, object)
  610. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  611. +
  612. .Properties of tokenization
  613. [%collapsible%open]
  614. ======
  615. `bert`::::
  616. (Optional, object)
  617. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  618. +
  619. .Properties of bert
  620. [%collapsible%open]
  621. =======
  622. `span`::::
  623. (Optional, integer)
  624. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  625. `with_special_tokens`::::
  626. (Optional, boolean)
  627. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
  628. =======
  629. `roberta`::::
  630. (Optional, object)
  631. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
  632. +
  633. .Properties of roberta
  634. [%collapsible%open]
  635. =======
  636. `span`::::
  637. (Optional, integer)
  638. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  639. `truncate`::::
  640. (Optional, string)
  641. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  642. =======
  643. `mpnet`::::
  644. (Optional, object)
  645. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
  646. +
  647. .Properties of mpnet
  648. [%collapsible%open]
  649. =======
  650. `span`::::
  651. (Optional, integer)
  652. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  653. `truncate`::::
  654. (Optional, string)
  655. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  656. =======
  657. `xlm_roberta`::::
  658. (Optional, object)
  659. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
  660. +
  661. .Properties of xlm_roberta
  662. [%collapsible%open]
  663. =======
  664. `span`::::
  665. (Optional, integer)
  666. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  667. `truncate`::::
  668. (Optional, string)
  669. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  670. =======
  671. `bert_ja`::::
  672. (Optional, object)
  673. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
  674. +
  675. .Properties of bert_ja
  676. [%collapsible%open]
  677. =======
  678. `span`::::
  679. (Optional, integer)
  680. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
  681. `with_special_tokens`::::
  682. (Optional, boolean)
  683. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja-with-special-tokens]
  684. =======
  685. ======
  686. =====
  687. `zero_shot_classification`:::
  688. (Object, optional)
  689. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-zero-shot-classification]
  690. +
  691. .Properties of zero_shot_classification inference
  692. [%collapsible%open]
  693. =====
  694. `labels`::::
  695. (Optional, array)
  696. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-zero-shot-classification-labels]
  697. `multi_label`::::
  698. (Optional, boolean)
  699. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-zero-shot-classification-multi-label]
  700. `results_field`::::
  701. (Optional, string)
  702. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
  703. `tokenization`::::
  704. (Optional, object)
  705. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
  706. +
  707. .Properties of tokenization
  708. [%collapsible%open]
  709. ======
  710. `bert`::::
  711. (Optional, object)
  712. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
  713. +
  714. .Properties of bert
  715. [%collapsible%open]
  716. =======
  717. `truncate`::::
  718. (Optional, string)
  719. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  720. =======
  721. `roberta`::::
  722. (Optional, object)
  723. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
  724. +
  725. .Properties of roberta
  726. [%collapsible%open]
  727. =======
  728. `truncate`::::
  729. (Optional, string)
  730. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  731. =======
  732. `mpnet`::::
  733. (Optional, object)
  734. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
  735. +
  736. .Properties of mpnet
  737. [%collapsible%open]
  738. =======
  739. `truncate`::::
  740. (Optional, string)
  741. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  742. =======
  743. `xlm_roberta`::::
  744. (Optional, object)
  745. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
  746. +
  747. .Properties of xlm_roberta
  748. [%collapsible%open]
  749. =======
  750. `truncate`::::
  751. (Optional, string)
  752. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  753. =======
  754. `bert_ja`::::
  755. (Optional, object)
  756. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
  757. +
  758. .Properties of bert_ja
  759. [%collapsible%open]
  760. =======
  761. `truncate`::::
  762. (Optional, string)
  763. include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
  764. =======
  765. ======
  766. =====
  767. ====
  768. //End of inference_config
  769. ////
  770. [[infer-trained-model-results]]
  771. == {api-response-body-title}
  772. ////
  773. ////
  774. [[ml-get-trained-models-response-codes]]
  775. == {api-response-codes-title}
  776. ////
  777. [[infer-trained-model-example]]
  778. == {api-examples-title}
  779. The response depends on the kind of model.
  780. For example, for {lang-ident} the response is the predicted language and the
  781. score:
  782. [source,console]
  783. --------------------------------------------------
  784. POST _ml/trained_models/lang_ident_model_1/_infer
  785. {
  786. "docs":[{"text": "The fool doth think he is wise, but the wise man knows himself to be a fool."}]
  787. }
  788. --------------------------------------------------
  789. // TEST[skip:TBD]
  790. Here are the results predicting english with a high probability.
  791. [source,console-result]
  792. ----
  793. {
  794. "inference_results": [
  795. {
  796. "predicted_value": "en",
  797. "prediction_probability": 0.9999658805366392,
  798. "prediction_score": 0.9999658805366392
  799. }
  800. ]
  801. }
  802. ----
  803. // NOTCONSOLE
  804. When it is a text classification model, the response is the score and predicted
  805. classification.
  806. For example:
  807. [source,console]
  808. --------------------------------------------------
  809. POST _ml/trained_models/model2/_infer
  810. {
  811. "docs": [{"text_field": "The movie was awesome!!"}]
  812. }
  813. --------------------------------------------------
  814. // TEST[skip:TBD]
  815. The API returns the predicted label and the confidence.
  816. [source,console-result]
  817. ----
  818. {
  819. "inference_results": [{
  820. "predicted_value" : "POSITIVE",
  821. "prediction_probability" : 0.9998667964092964
  822. }]
  823. }
  824. ----
  825. // NOTCONSOLE
  826. For named entity recognition (NER) models, the response contains the annotated
  827. text output and the recognized entities.
  828. [source,console]
  829. --------------------------------------------------
  830. POST _ml/trained_models/model2/_infer
  831. {
  832. "docs": [{"text_field": "Hi my name is Josh and I live in Berlin"}]
  833. }
  834. --------------------------------------------------
  835. // TEST[skip:TBD]
  836. The API returns in this case:
  837. [source,console-result]
  838. ----
  839. {
  840. "inference_results": [{
  841. "predicted_value" : "Hi my name is [Josh](PER&Josh) and I live in [Berlin](LOC&Berlin)",
  842. "entities" : [
  843. {
  844. "entity" : "Josh",
  845. "class_name" : "PER",
  846. "class_probability" : 0.9977303419824,
  847. "start_pos" : 14,
  848. "end_pos" : 18
  849. },
  850. {
  851. "entity" : "Berlin",
  852. "class_name" : "LOC",
  853. "class_probability" : 0.9992474323902818,
  854. "start_pos" : 33,
  855. "end_pos" : 39
  856. }
  857. ]
  858. }]
  859. }
  860. ----
  861. // NOTCONSOLE
  862. Zero-shot classification models require extra configuration defining the class
  863. labels. These labels are passed in the zero-shot inference config.
  864. [source,console]
  865. --------------------------------------------------
  866. POST _ml/trained_models/model2/_infer
  867. {
  868. "docs": [
  869. {
  870. "text_field": "This is a very happy person"
  871. }
  872. ],
  873. "inference_config": {
  874. "zero_shot_classification": {
  875. "labels": [
  876. "glad",
  877. "sad",
  878. "bad",
  879. "rad"
  880. ],
  881. "multi_label": false
  882. }
  883. }
  884. }
  885. --------------------------------------------------
  886. // TEST[skip:TBD]
  887. The API returns the predicted label and the confidence, as well as the top
  888. classes:
  889. [source,console-result]
  890. ----
  891. {
  892. "inference_results": [{
  893. "predicted_value" : "glad",
  894. "top_classes" : [
  895. {
  896. "class_name" : "glad",
  897. "class_probability" : 0.8061155063386439,
  898. "class_score" : 0.8061155063386439
  899. },
  900. {
  901. "class_name" : "rad",
  902. "class_probability" : 0.18218006158387956,
  903. "class_score" : 0.18218006158387956
  904. },
  905. {
  906. "class_name" : "bad",
  907. "class_probability" : 0.006325615787634201,
  908. "class_score" : 0.006325615787634201
  909. },
  910. {
  911. "class_name" : "sad",
  912. "class_probability" : 0.0053788162898424545,
  913. "class_score" : 0.0053788162898424545
  914. }
  915. ],
  916. "prediction_probability" : 0.8061155063386439
  917. }]
  918. }
  919. ----
  920. // NOTCONSOLE
  921. Question answering models require extra configuration defining the question to
  922. answer.
  923. [source,console]
  924. --------------------------------------------------
  925. POST _ml/trained_models/model2/_infer
  926. {
  927. "docs": [
  928. {
  929. "text_field": "<long text to extract answer>"
  930. }
  931. ],
  932. "inference_config": {
  933. "question_answering": {
  934. "question": "<question to be answered>"
  935. }
  936. }
  937. }
  938. --------------------------------------------------
  939. // TEST[skip:TBD]
  940. The API returns a response similar to the following:
  941. [source,console-result]
  942. ----
  943. {
  944. "predicted_value": <string subsection of the text that is the answer>,
  945. "start_offset": <character offset in document to start>,
  946. "end_offset": <character offset end of the answer,
  947. "prediction_probability": <prediction score>
  948. }
  949. ----
  950. // NOTCONSOLE
  951. Text similarity models require at least two sequences of text to compare. It's
  952. possible to provide multiple strings of text to compare to another text
  953. sequence:
  954. [source,console]
  955. --------------------------------------------------
  956. POST _ml/trained_models/cross-encoder__ms-marco-tinybert-l-2-v2/_infer
  957. {
  958. "docs":[{ "text_field": "Berlin has a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers."}, {"text_field": "New York City is famous for the Metropolitan Museum of Art."}],
  959. "inference_config": {
  960. "text_similarity": {
  961. "text": "How many people live in Berlin?"
  962. }
  963. }
  964. }
  965. --------------------------------------------------
  966. // TEST[skip:TBD]
  967. The response contains the prediction for every string that is compared to the
  968. text provided in the `text_similarity`.`text` field:
  969. [source,console-result]
  970. ----
  971. {
  972. "inference_results": [
  973. {
  974. "predicted_value": 7.235751628875732
  975. },
  976. {
  977. "predicted_value": -11.562295913696289
  978. }
  979. ]
  980. }
  981. ----
  982. // NOTCONSOLE
  983. The tokenization truncate option can be overridden when calling the API:
  984. [source,console]
  985. --------------------------------------------------
  986. POST _ml/trained_models/model2/_infer
  987. {
  988. "docs": [{"text_field": "The Amazon rainforest covers most of the Amazon basin in South America"}],
  989. "inference_config": {
  990. "ner": {
  991. "tokenization": {
  992. "bert": {
  993. "truncate": "first"
  994. }
  995. }
  996. }
  997. }
  998. }
  999. --------------------------------------------------
  1000. // TEST[skip:TBD]
  1001. When the input has been truncated due to the limit imposed by the model's
  1002. `max_sequence_length` the `is_truncated` field appears in the response.
  1003. [source,console-result]
  1004. ----
  1005. {
  1006. "inference_results": [{
  1007. "predicted_value" : "The [Amazon](LOC&Amazon) rainforest covers most of the [Amazon](LOC&Amazon) basin in [South America](LOC&South+America)",
  1008. "entities" : [
  1009. {
  1010. "entity" : "Amazon",
  1011. "class_name" : "LOC",
  1012. "class_probability" : 0.9505460915724254,
  1013. "start_pos" : 4,
  1014. "end_pos" : 10
  1015. },
  1016. {
  1017. "entity" : "Amazon",
  1018. "class_name" : "LOC",
  1019. "class_probability" : 0.9969992804311777,
  1020. "start_pos" : 41,
  1021. "end_pos" : 47
  1022. }
  1023. ],
  1024. "is_truncated" : true
  1025. }]
  1026. }
  1027. ----
  1028. // NOTCONSOLE