12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121 |
- [role="xpack"]
- [[infer-trained-model]]
- = Infer trained model API
- [subs="attributes"]
- ++++
- <titleabbrev>Infer trained model</titleabbrev>
- ++++
- Evaluates a trained model. The model may be any supervised model either trained
- by {dfanalytics} or imported.
- NOTE: For model deployments with caching enabled, results may be returned
- directly from the {infer} cache.
- [[infer-trained-model-request]]
- == {api-request-title}
- `POST _ml/trained_models/<model_id>/_infer`
- `POST _ml/trained_models/<deployment_id>/_infer`
- ////
- [[infer-trained-model-prereq]]
- == {api-prereq-title}
- ////
- ////
- [[infer-trained-model-desc]]
- == {api-description-title}
- ////
- [[infer-trained-model-path-params]]
- == {api-path-parms-title}
- `<model_id>`::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=model-id-or-alias]
- If you specify the `model_id` in the API call, and the model has multiple
- deployments, a random deployment will be used. If the `model_id` matches the ID
- of one of the deployments, that deployment will be used.
- `<deployment_id>`::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=deployment-id]
- [[infer-trained-model-query-params]]
- == {api-query-parms-title}
- `timeout`::
- (Optional, time)
- Controls the amount of time to wait for {infer} results. Defaults to 10 seconds.
- [[infer-trained-model-request-body]]
- == {api-request-body-title}
- `docs`::
- (Required, array)
- An array of objects to pass to the model for inference. The objects should
- contain the fields matching your configured trained model input. Typically for
- NLP models, the field name is `text_field`.
- //Begin inference_config
- `inference_config`::
- (Required, object)
- The default configuration for inference. This can be: `regression`,
- `classification`, `fill_mask`, `ner`, `question_answering`,
- `text_classification`, `text_embedding` or `zero_shot_classification`.
- If `regression` or `classification`, it must match the `target_type` of the
- underlying `definition.trained_model`. If `fill_mask`, `ner`,
- `question_answering`, `text_classification`, or `text_embedding`; the
- `model_type` must be `pytorch`.
- +
- .Properties of `inference_config`
- [%collapsible%open]
- ====
- `classification`:::
- (Optional, object)
- Classification configuration for inference.
- +
- .Properties of classification inference
- [%collapsible%open]
- =====
- `num_top_classes`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-classes]
- `num_top_feature_importance_values`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-num-top-feature-importance-values]
- `prediction_field_type`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-prediction-field-type]
- `results_field`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
- `top_classes_results_field`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-classification-top-classes-results-field]
- =====
- `fill_mask`:::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-fill-mask]
- +
- .Properties of fill_mask inference
- [%collapsible%open]
- =====
- `num_top_classes`::::
- (Optional, integer)
- Number of top predicted tokens to return for replacing the mask token. Defaults
- to `0`.
- `results_field`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
- `tokenization`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
- +
- .Properties of tokenization
- [%collapsible%open]
- ======
- `bert`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
- +
- .Properties of bert
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
- +
- .Properties of roberta
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `mpnet`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
- +
- .Properties of mpnet
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `xlm_roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
- +
- .Properties of xlm_roberta
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `bert_ja`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
- +
- .Properties of bert_ja
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- ======
- =====
- `ner`:::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-ner]
- +
- .Properties of ner inference
- [%collapsible%open]
- =====
- `results_field`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
- `tokenization`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
- +
- .Properties of tokenization
- [%collapsible%open]
- ======
- `bert`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
- +
- .Properties of bert
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
- +
- .Properties of roberta
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `mpnet`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
- +
- .Properties of mpnet
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `xlm_roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
- +
- .Properties of xlm_roberta
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `bert_ja`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
- +
- .Properties of bert_ja
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- ======
- =====
- `pass_through`:::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-pass-through]
- +
- .Properties of pass_through inference
- [%collapsible%open]
- =====
- `results_field`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
- `tokenization`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
- +
- .Properties of tokenization
- [%collapsible%open]
- ======
- `bert`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
- +
- .Properties of bert
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
- +
- .Properties of roberta
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `mpnet`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
- +
- .Properties of mpnet
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `xlm_roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
- +
- .Properties of xlm_roberta
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `bert_ja`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
- +
- .Properties of bert_ja
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- ======
- =====
- `question_answering`:::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-question-answering]
- +
- .Properties of question_answering inference
- [%collapsible%open]
- =====
- `max_answer_length`::::
- (Optional, integer)
- The maximum amount of words in the answer. Defaults to `15`.
- `num_top_classes`::::
- (Optional, integer)
- The number the top found answers to return. Defaults to `0`, meaning only the
- best found answer is returned.
- `question`::::
- (Required, string)
- The question to use when extracting an answer
- `results_field`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
- `tokenization`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
- +
- Recommended to set `max_sequence_length` to `386` with `128` of `span` and set
- `truncate` to `none`.
- +
- .Properties of tokenization
- [%collapsible%open]
- ======
- `bert`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
- +
- .Properties of bert
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
- +
- .Properties of roberta
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `mpnet`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
- +
- .Properties of mpnet
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `xlm_roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
- +
- .Properties of xlm_roberta
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `bert_ja`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
- +
- .Properties of bert_ja
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- ======
- =====
- `regression`:::
- (Optional, object)
- Regression configuration for inference.
- +
- .Properties of regression inference
- [%collapsible%open]
- =====
- `num_top_feature_importance_values`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-regression-num-top-feature-importance-values]
- `results_field`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
- =====
- `text_classification`:::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-classification]
- +
- .Properties of text_classification inference
- [%collapsible%open]
- =====
- `classification_labels`::::
- (Optional, string) An array of classification labels.
- `num_top_classes`::::
- (Optional, integer)
- Specifies the number of top class predictions to return. Defaults to all classes
- (-1).
- `results_field`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
- `tokenization`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
- +
- .Properties of tokenization
- [%collapsible%open]
- ======
- `bert`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
- +
- .Properties of bert
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
- +
- .Properties of roberta
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `mpnet`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
- +
- .Properties of mpnet
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `xlm_roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
- +
- .Properties of xlm_roberta
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `bert_ja`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
- +
- .Properties of bert_ja
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- ======
- =====
- `text_embedding`:::
- (Object, optional)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-embedding]
- +
- .Properties of text_embedding inference
- [%collapsible%open]
- =====
- `results_field`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
- `tokenization`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
- +
- .Properties of tokenization
- [%collapsible%open]
- ======
- `bert`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
- +
- .Properties of bert
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
- +
- .Properties of roberta
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `mpnet`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
- +
- .Properties of mpnet
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `xlm_roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
- +
- .Properties of xlm_roberta
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `bert_ja`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
- +
- .Properties of bert_ja
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- ======
- =====
- `text_similarity`:::
- (Object, optional)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-similarity]
- +
- .Properties of text_similarity inference
- [%collapsible%open]
- =====
- `span_score_combination_function`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-similarity-span-score-func]
- `text`::::
- (Required, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-similarity-text]
- `tokenization`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
- +
- .Properties of tokenization
- [%collapsible%open]
- ======
- `bert`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
- +
- .Properties of bert
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `with_special_tokens`::::
- (Optional, boolean)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-with-special-tokens]
- =======
- `roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
- +
- .Properties of roberta
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `mpnet`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
- +
- .Properties of mpnet
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `xlm_roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
- +
- .Properties of xlm_roberta
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `bert_ja`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
- +
- .Properties of bert_ja
- [%collapsible%open]
- =======
- `span`::::
- (Optional, integer)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-span]
- `with_special_tokens`::::
- (Optional, boolean)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja-with-special-tokens]
- =======
- ======
- =====
- `zero_shot_classification`:::
- (Object, optional)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-zero-shot-classification]
- +
- .Properties of zero_shot_classification inference
- [%collapsible%open]
- =====
- `labels`::::
- (Optional, array)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-zero-shot-classification-labels]
- `multi_label`::::
- (Optional, boolean)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-zero-shot-classification-multi-label]
- `results_field`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
- `tokenization`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
- +
- .Properties of tokenization
- [%collapsible%open]
- ======
- `bert`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert]
- +
- .Properties of bert
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-roberta]
- +
- .Properties of roberta
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `mpnet`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-mpnet]
- +
- .Properties of mpnet
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `xlm_roberta`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-xlm-roberta]
- +
- .Properties of xlm_roberta
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- `bert_ja`::::
- (Optional, object)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-bert-ja]
- +
- .Properties of bert_ja
- [%collapsible%open]
- =======
- `truncate`::::
- (Optional, string)
- include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization-truncate]
- =======
- ======
- =====
- ====
- //End of inference_config
- ////
- [[infer-trained-model-results]]
- == {api-response-body-title}
- ////
- ////
- [[ml-get-trained-models-response-codes]]
- == {api-response-codes-title}
- ////
- [[infer-trained-model-example]]
- == {api-examples-title}
- The response depends on the kind of model.
- For example, for {lang-ident} the response is the predicted language and the
- score:
- [source,console]
- --------------------------------------------------
- POST _ml/trained_models/lang_ident_model_1/_infer
- {
- "docs":[{"text": "The fool doth think he is wise, but the wise man knows himself to be a fool."}]
- }
- --------------------------------------------------
- // TEST[skip:TBD]
- Here are the results predicting english with a high probability.
- [source,console-result]
- ----
- {
- "inference_results": [
- {
- "predicted_value": "en",
- "prediction_probability": 0.9999658805366392,
- "prediction_score": 0.9999658805366392
- }
- ]
- }
- ----
- // NOTCONSOLE
- When it is a text classification model, the response is the score and predicted
- classification.
- For example:
- [source,console]
- --------------------------------------------------
- POST _ml/trained_models/model2/_infer
- {
- "docs": [{"text_field": "The movie was awesome!!"}]
- }
- --------------------------------------------------
- // TEST[skip:TBD]
- The API returns the predicted label and the confidence.
- [source,console-result]
- ----
- {
- "inference_results": [{
- "predicted_value" : "POSITIVE",
- "prediction_probability" : 0.9998667964092964
- }]
- }
- ----
- // NOTCONSOLE
- For named entity recognition (NER) models, the response contains the annotated
- text output and the recognized entities.
- [source,console]
- --------------------------------------------------
- POST _ml/trained_models/model2/_infer
- {
- "docs": [{"text_field": "Hi my name is Josh and I live in Berlin"}]
- }
- --------------------------------------------------
- // TEST[skip:TBD]
- The API returns in this case:
- [source,console-result]
- ----
- {
- "inference_results": [{
- "predicted_value" : "Hi my name is [Josh](PER&Josh) and I live in [Berlin](LOC&Berlin)",
- "entities" : [
- {
- "entity" : "Josh",
- "class_name" : "PER",
- "class_probability" : 0.9977303419824,
- "start_pos" : 14,
- "end_pos" : 18
- },
- {
- "entity" : "Berlin",
- "class_name" : "LOC",
- "class_probability" : 0.9992474323902818,
- "start_pos" : 33,
- "end_pos" : 39
- }
- ]
- }]
- }
- ----
- // NOTCONSOLE
- Zero-shot classification models require extra configuration defining the class
- labels. These labels are passed in the zero-shot inference config.
- [source,console]
- --------------------------------------------------
- POST _ml/trained_models/model2/_infer
- {
- "docs": [
- {
- "text_field": "This is a very happy person"
- }
- ],
- "inference_config": {
- "zero_shot_classification": {
- "labels": [
- "glad",
- "sad",
- "bad",
- "rad"
- ],
- "multi_label": false
- }
- }
- }
- --------------------------------------------------
- // TEST[skip:TBD]
- The API returns the predicted label and the confidence, as well as the top
- classes:
- [source,console-result]
- ----
- {
- "inference_results": [{
- "predicted_value" : "glad",
- "top_classes" : [
- {
- "class_name" : "glad",
- "class_probability" : 0.8061155063386439,
- "class_score" : 0.8061155063386439
- },
- {
- "class_name" : "rad",
- "class_probability" : 0.18218006158387956,
- "class_score" : 0.18218006158387956
- },
- {
- "class_name" : "bad",
- "class_probability" : 0.006325615787634201,
- "class_score" : 0.006325615787634201
- },
- {
- "class_name" : "sad",
- "class_probability" : 0.0053788162898424545,
- "class_score" : 0.0053788162898424545
- }
- ],
- "prediction_probability" : 0.8061155063386439
- }]
- }
- ----
- // NOTCONSOLE
- Question answering models require extra configuration defining the question to
- answer.
- [source,console]
- --------------------------------------------------
- POST _ml/trained_models/model2/_infer
- {
- "docs": [
- {
- "text_field": "<long text to extract answer>"
- }
- ],
- "inference_config": {
- "question_answering": {
- "question": "<question to be answered>"
- }
- }
- }
- --------------------------------------------------
- // TEST[skip:TBD]
- The API returns a response similar to the following:
- [source,console-result]
- ----
- {
- "predicted_value": <string subsection of the text that is the answer>,
- "start_offset": <character offset in document to start>,
- "end_offset": <character offset end of the answer,
- "prediction_probability": <prediction score>
- }
- ----
- // NOTCONSOLE
- Text similarity models require at least two sequences of text to compare. It's
- possible to provide multiple strings of text to compare to another text
- sequence:
- [source,console]
- --------------------------------------------------
- POST _ml/trained_models/cross-encoder__ms-marco-tinybert-l-2-v2/_infer
- {
- "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."}],
- "inference_config": {
- "text_similarity": {
- "text": "How many people live in Berlin?"
- }
- }
- }
- --------------------------------------------------
- // TEST[skip:TBD]
- The response contains the prediction for every string that is compared to the
- text provided in the `text_similarity`.`text` field:
- [source,console-result]
- ----
- {
- "inference_results": [
- {
- "predicted_value": 7.235751628875732
- },
- {
- "predicted_value": -11.562295913696289
- }
- ]
- }
- ----
- // NOTCONSOLE
- The tokenization truncate option can be overridden when calling the API:
- [source,console]
- --------------------------------------------------
- POST _ml/trained_models/model2/_infer
- {
- "docs": [{"text_field": "The Amazon rainforest covers most of the Amazon basin in South America"}],
- "inference_config": {
- "ner": {
- "tokenization": {
- "bert": {
- "truncate": "first"
- }
- }
- }
- }
- }
- --------------------------------------------------
- // TEST[skip:TBD]
- When the input has been truncated due to the limit imposed by the model's
- `max_sequence_length` the `is_truncated` field appears in the response.
- [source,console-result]
- ----
- {
- "inference_results": [{
- "predicted_value" : "The [Amazon](LOC&Amazon) rainforest covers most of the [Amazon](LOC&Amazon) basin in [South America](LOC&South+America)",
- "entities" : [
- {
- "entity" : "Amazon",
- "class_name" : "LOC",
- "class_probability" : 0.9505460915724254,
- "start_pos" : 4,
- "end_pos" : 10
- },
- {
- "entity" : "Amazon",
- "class_name" : "LOC",
- "class_probability" : 0.9969992804311777,
- "start_pos" : 41,
- "end_pos" : 47
- }
- ],
- "is_truncated" : true
- }]
- }
- ----
- // NOTCONSOLE
|