@@ -90,7 +90,7 @@ text output and the recognized entities.
9090--------------------------------------------------
9191POST _ml/trained_models/model2/deployment/_infer
9292{
93- "input ": " Hi my name is Josh and I live in Berlin"
93+ "docs ": [{"text_field": " Hi my name is Josh and I live in Berlin"}]
9494}
9595--------------------------------------------------
9696// TEST[skip:TBD]
@@ -120,3 +120,112 @@ The API returns in this case:
120120}
121121----
122122// NOTCONSOLE
123+
124+ Zero-shot classification tasks require extra configuration defining the class labels.
125+ These labels are passed in the zero-shot inference config.
126+
127+ [source,console]
128+ --------------------------------------------------
129+ POST _ml/trained_models/model2/deployment/_infer
130+ {
131+ "docs": [
132+ {
133+ "text_field": "This is a very happy person"
134+ }
135+ ],
136+ "inference_config": {
137+ "zero_shot_classification": {
138+ "labels": [
139+ "glad",
140+ "sad",
141+ "bad",
142+ "rad"
143+ ],
144+ "multi_label": false
145+ }
146+ }
147+ }
148+ --------------------------------------------------
149+ // TEST[skip:TBD]
150+
151+ The API returns the predicted label and the confidence, as well as the top classes:
152+
153+ [source,console-result]
154+ ----
155+ {
156+ "predicted_value" : "glad",
157+ "top_classes" : [
158+ {
159+ "class_name" : "glad",
160+ "class_probability" : 0.8061155063386439,
161+ "class_score" : 0.8061155063386439
162+ },
163+ {
164+ "class_name" : "rad",
165+ "class_probability" : 0.18218006158387956,
166+ "class_score" : 0.18218006158387956
167+ },
168+ {
169+ "class_name" : "bad",
170+ "class_probability" : 0.006325615787634201,
171+ "class_score" : 0.006325615787634201
172+ },
173+ {
174+ "class_name" : "sad",
175+ "class_probability" : 0.0053788162898424545,
176+ "class_score" : 0.0053788162898424545
177+ }
178+ ],
179+ "prediction_probability" : 0.8061155063386439
180+ }
181+ ----
182+ // NOTCONSOLE
183+
184+
185+ The tokenization truncate option can be overridden when calling the API:
186+
187+ [source,console]
188+ --------------------------------------------------
189+ POST _ml/trained_models/model2/deployment/_infer
190+ {
191+ "docs": [{"text_field": "The Amazon rainforest covers most of the Amazon basin in South America"}],
192+ "inference_config": {
193+ "ner": {
194+ "tokenization": {
195+ "bert": {
196+ "truncate": "first"
197+ }
198+ }
199+ }
200+ }
201+ }
202+ --------------------------------------------------
203+ // TEST[skip:TBD]
204+
205+ When the input has been truncated due to the limit imposed by the model's `max_sequence_length`
206+ the `is_truncated` field appears in the response.
207+
208+ [source,console-result]
209+ ----
210+ {
211+ "predicted_value" : "The [Amazon](LOC&Amazon) rainforest covers most of the [Amazon](LOC&Amazon) basin in [South America](LOC&South+America)",
212+ "entities" : [
213+ {
214+ "entity" : "Amazon",
215+ "class_name" : "LOC",
216+ "class_probability" : 0.9505460915724254,
217+ "start_pos" : 4,
218+ "end_pos" : 10
219+ },
220+ {
221+ "entity" : "Amazon",
222+ "class_name" : "LOC",
223+ "class_probability" : 0.9969992804311777,
224+ "start_pos" : 41,
225+ "end_pos" : 47
226+ }
227+ ],
228+ "is_truncated" : true
229+ }
230+ ----
231+ // NOTCONSOLE
0 commit comments