How to preprocess BigQuery data for TensorFlow?

You are developing a custom TensorFlow classification model based on tabular data. Your raw data is stored in BigQuery. contains hundreds of millions of rows, and includes both categorical and numerical features. You need to use a MaxMin scaler on some numerical features, and apply a one-hot encoding to some categorical features such as SKU names. Your model will be trained over multiple epochs. You want to minimize the effort and cost of your solution. What should you do?

  1. 1. Write a SQL query to create a separate lookup table to scale the numerical features.
  2. 1. Use BigQuery to scale the numerical features.
  3. 1. Use TFX components with Dataflow to encode the text features and scale the numerical features. Source Reference Answer
  4. 1. Write a SQL query to create a separate lookup table to scale the numerical features.

Community Votes

C
47%
D
28%
B
25%

47% of anonymous learners picked answer C. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

This question tests the use of TFX and Dataflow for complex preprocessing, where the trap is underestimating the complexity of implementing full-pass stateful transformations in SQL.

For large-scale tabular data preprocessing requiring stateful transformations like scaling and encoding, using TFX components with Dataflow is the recommended approach. The community consensus supports this method for its ability to efficiently handle distributed processing and pipeline integration, minimizing engineering effort.

Choosing BigQuery (Option B or D) is a common mistake because while it appears cost-effective, implementing stateful transformations like MinMax scaling requires complex auxiliary tables and multiple data passes, increasing effort.

Community Discussion (16 comments)

b2aaace 👍 7 Selected: C
"Full-pass stateful transformations aren't suitable for implementation in BigQuery. If you use BigQuery for full-pass transformations, you need auxiliary tables to store quantities needed by stateful transformations, such as means and variances to scale numerical features. Further, implementation of full-pass transformations using SQL on BigQuery creates increased complexity in the SQL scripts, and creates intricate dependency between training and the scoring SQL scripts." https://www.tensorflow.org/tfx/guide/tft_bestpractices#where_to_do_preprocessing
thescientist 👍 1 Selected: B
With multiple epochs, the data is passed through the model multiple times. If you pre-encoded the categorical features (as in options C and D), you would be storing and repeatedly reading a much larger dataset (due to the one-hot encoding). This significantly increases storage costs and I/O overhead. By performing the one-hot encoding within TensorFlow during training (as in option B), the encoding happens on-the-fly for each batch of data during each epoch.
Ankit267 👍 1 Selected: D
B & D as top 2 choices, C is including Dataflow unnecessarily. D as "minimize the effort and cost of your solution", still some room for B but I selected D
pipefaxaf 👍 3 Selected: D
Option D minimizes effort and cost by using BigQuery to handle both the scaling and one-hot encoding. BigQuery is efficient for these types of preprocessing tasks, especially when dealing with large datasets. By preparing the data in BigQuery, you avoid the need to export data to other services or use additional resources for preprocessing, such as Dataflow. This approach provides a streamlined workflow by creating a preprocessed view in BigQuery, which can then be directly fed into Vertex AI Training without extra transformation steps. This helps optimize cost and simplicity while handling large tabular data effectively.
YangG 👍 2 Selected: C
multiple epochs --> need to persist data after preprocessing
wences 👍 2 Selected: D
Option D since it says minimize effort and cost following that adding something rather than BQ will increase complexity.
AzureDP900 👍 1
Option C uses TFX (TensorFlow Extended) components with Dataflow, which is a great way to perform complex data preprocessing tasks like one-hot encoding and scaling. This approach allows you to process your data in a scalable and efficient manner, using Cloud Storage as the output location. By exporting the results as TFRecords, you can easily feed this preprocessed data into Vertex AI Training for model development.
dija123 👍 1 Selected: C
agree with TFX components with Dataflow
bobjr 👍 4 Selected: D
GPT says D, Gemini says B, Perplexity says C.... I say D : stay in one tool, BQ, which is cheap and natively scalable. B has a risk of out of memory error.
fitri001 👍 1 Selected: B
BigQuery for Preprocessing: BigQuery is a serverless data warehouse optimized for large datasets.expand_more It can handle scaling numerical features using built-in functions like SCALE or QUANTILE_SCALE, reducing the need for complex custom logic or separate lookup tables. TensorFlow for One-Hot Encoding: TensorFlow excels at in-memory processing. One-hot encoding of categorical features, especially text features like SKU names, can be efficiently performed within your TensorFlow model during training. This avoids unnecessary data movement or transformations in BigQuery. Vertex AI Training: By feeding the preprocessed data (scaled numerical features) directly into Vertex AI Training, you leverage its managed infrastructure for training your custom TensorFlow model.
cruise93 👍 1 Selected: C
Agree with b1a8fae
gscharly 👍 2 Selected: C
agree with daidai75
guilhermebutzke 👍 4 Selected: B
My Answer: B 1. Use BigQuery to scale the numerical features.: Simpler and cheaper then use TFX components with Dataflow to scale the numerical features 2. Feed the features into Vertex AI Training. 3. Allow TensorFlow to perform the one-hot text encoding: TensorFlow handles the one-hot text encoding better than BQ.
daidai75 👍 2 Selected: C
key messages: "contains hundreds of millions of rows, and includes both categorical and numerical features. You need to use a MaxMin scaler on some numerical features, and apply a one-hot encoding to some categorical features such as SKU names". Option B is not suitable for the big volume of data processing. Option C is better.
b1a8fae 👍 2 Selected: C
Inclined to choose C over B. By using TFX components with Dataflow, you can perform feature engineering on large-scale tabular data in a distributed and efficient way. You can use the Transform component to apply the MaxMin scaler and the one-hot encoding to the numerical and categorical features, respectively. You can also use the ExampleGen component to read data from BigQuery and the Trainer component to train your TensorFlow model.
pikachu007 👍 3 Selected: B
Option A: Involves creating a separate lookup table and deploying a Hugging Face model in BigQuery, increasing complexity and cost. Option C: While TFX offers robust preprocessing capabilities, it adds overhead for this use case and requires knowledge of Dataflow. Option D: Performing one-hot encoding in BigQuery can be less efficient than TensorFlow's optimized implementation.

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

Expert Analysis

Why the Answer Is Correct

Option C is correct because TFX components, specifically the Transform component with Dataflow, are designed to handle full-pass stateful transformations (like MinMax scaling) and complex encoding on large datasets efficiently. This approach minimizes the engineering effort required to write and maintain complex SQL queries for preprocessing and integrates seamlessly with the TensorFlow training pipeline. As noted in comments, Dataflow provides the distributed processing power necessary for hundreds of millions of rows.

Why the Other Options Are Wrong

Options A, B, and D suggest using BigQuery for scaling, which involves writing manual SQL queries. Implementing a MinMax scaler in SQL requires calculating global min and max values, often necessitating complex joins or separate lookup tables (as hinted in Option A), which increases effort and potential for error. While some comments argue for BigQuery's cost-effectiveness, the question emphasizes minimizing the effort of the solution, and managing complex stateful transformations in SQL is inherently more labor-intensive than using a dedicated preprocessing component like TFX.

Community Comment Notes

There is significant debate in the comments regarding cost versus effort, with some users preferring BigQuery for its simplicity and lower immediate cost (Comments 2, 4). However, top-voted comments highlight that "full-pass stateful transformations aren't suitable for implementation in BigQuery" without auxiliary tables, leading to increased complexity (Comment 1). Others point out that for multiple epochs, a pipeline approach like TFX allows for efficient data handling and persistence (Comment 6, 9).

Official Reference

Exam Strategy

When you encounter questions involving large datasets and specific preprocessing steps like scaling or encoding, prioritize managed MLOps tools like TFX over manual SQL. Remember that while BigQuery is excellent for storage and querying, complex stateful transformations are best handled by Dataflow to reduce engineering effort.

Related Analysis

Practice All PMLE Questions

Access 65 questions with complete answers and detailed explanations.

View Full PMLE Practice Test →

← Back to PMLE Study Guide