
Ultimate access to all questions.
You trained a text classification model using TensorFlow and exported it to be served by TensorFlow Serving. You have the following SignatureDefs for the model. You started a TensorFlow-serving component server and configured it to listen for HTTP requests at 'http://localhost:8501/v1/models/text_model:predict'. To get a prediction from the model, you need to send an HTTP POST request. Given the headers = {"content-type": "application/json"}, which of the following is the correct way to write the predict request?_
A
data = json.dumps({"signature_name": "seving_default", "instances": [["ab", "bc", "cd"]]})
B
data = json.dumps({"signature_name": "serving_default", "instances": [["a", "b", "c", "d", "e", "f"]]})
C
data = json.dumps({"signature_name": "serving_default", "instances": [["a", "b", "c"], ["d", "e", "f"]]})
D
data = json.dumps({"signature_name": "serving_default", "instances": [["a", "b"], ["c", "d"], ["e", "f"]]})
Explanation:
The correct answer is D. The SignatureDef expects the input data to have a shape of (-1, 2), which means any number of rows but exactly 2 columns. The instance structure [["a", "b"], ["c", "d"], ["e", "f"]] satisfies this requirement by providing multiple rows each containing 2 elements. Options A, B, and C do not match this required shape: A has 3 elements in one row, B has a single row with 6 elements, and C has 2 rows with 3 elements each. Therefore, only option D matches the expected input shape.