<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Batch Serving Design Pattern
This notebook demonstrates the Batch Serving design pattern using BigQuery
Simple text classification model
Let's use the same model that was used in serving_function.ipynb -- a text classification model based on IMDB reviews trained, and exported.
Step1:  Load model into BigQuery for batch serving
Step2:  Now, do it at scale, on consumer complaints about financial products and services
<ASSISTANT_TASK:>
Python Code:
!find export/probs/
%%bash
LOCAL_DIR=$(find export/probs | head -2 | tail -1)
BUCKET=ai-analytics-solutions-kfpdemo
gsutil rm -rf gs://${BUCKET}/mlpatterns/batchserving
gsutil cp -r $LOCAL_DIR gs://${BUCKET}/mlpatterns/batchserving
gsutil ls gs://${BUCKET}/mlpatterns/batchserving
Explanation: Batch Serving Design Pattern
This notebook demonstrates the Batch Serving design pattern using BigQuery
Simple text classification model
Let's use the same model that was used in serving_function.ipynb -- a text classification model based on IMDB reviews trained, and exported.
End of explanation
%%bigquery
CREATE OR REPLACE MODEL mlpatterns.imdb_sentiment
OPTIONS(model_type='tensorflow', model_path='gs://ai-analytics-solutions-kfpdemo/mlpatterns/batchserving/*')
%%bigquery
SELECT * FROM ML.PREDICT(MODEL mlpatterns.imdb_sentiment,
  (SELECT 'This was very well done.' AS reviews)
)
Explanation: Load model into BigQuery for batch serving
End of explanation
%%bigquery preds
SELECT * FROM ML.PREDICT(MODEL mlpatterns.imdb_sentiment,
  (SELECT consumer_complaint_narrative AS reviews 
   FROM `bigquery-public-data`.cfpb_complaints.complaint_database
   WHERE consumer_complaint_narrative IS NOT NULL
   )
)
preds[:3]
# what's does a "positive" complaint look like?
preds.sort_values(by='positive_review_probability', ascending=False).iloc[1]['reviews']
# what's does a "typical" complaint look like?
preds.sort_values(by='positive_review_probability', ascending=False).iloc[len(preds)//2]['reviews']
Explanation: Now, do it at scale, on consumer complaints about financial products and services:
End of explanation
<END_TASK>