Professional Machine Learning Engineer free question 8 / 10 · Domain 5: Automating and orchestrating ML pipelines
You call tfdv.infer_schema(stats) without changing any arguments. In the statistics, the required feature amount has a minimum of 1 and a maximum of 1 values per example, and the required feature tags has a minimum of 1 and a maximum of 5. What happens to the shape in the inferred schema?
- A shape is inferred for amount but not for tags
- A shape is inferred for tags but not for amount
- No shape is inferred by default, and one is inferred with infer_feature_shape=True
- A shape is inferred for amount and for tags
Show the answer and explanation
Answer: A
Why this is correct
The Get started page says that by default tfdv.infer_schema infers the shape of a required feature if its value_count.min equals its value_count.max, and that to turn shape inference off you set infer_feature_shape to False. amount has a minimum and maximum of 1, so its shape is inferred, and tags has a minimum of 1 and a maximum of 5, so it is not.
Why the other options are wrong
"A shape is inferred for amount and for tags" … By default infer_schema infers a shape only for a required feature whose value_count min and max are equal. tags has a minimum of 1 and a maximum of 5, which are not equal, so no shape is inferred.
"A shape is inferred for tags but not for amount" … The condition is that value_count min and max are equal, and amount, with a fixed number of values, meets it. tags, whose number of values varies from example to example, does not.
"No shape is inferred by default, and one is inferred with infer_feature_shape=True" … Shape inference is done by default, and you set infer_feature_shape to False to stop it. It is not the case that it infers only when True is passed.
Key point
infer_schema is a way to create a first version of the schema from statistics, and TFDV makes conservative inferences so as not to overfit the data. You are strongly encouraged to review the inferred schema and revise it with your domain knowledge.