Let's use the same model that was used in serving_function.ipynb -- a text classification model based on IMDB reviews trained, and exported.
In [3]:
!find export/probs/
In [8]:
%%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
In [12]:
%%bigquery
CREATE OR REPLACE MODEL mlpatterns.imdb_sentiment
OPTIONS(model_type='tensorflow', model_path='gs://ai-analytics-solutions-kfpdemo/mlpatterns/batchserving/*')
Out[12]:
In [13]:
%%bigquery
SELECT * FROM ML.PREDICT(MODEL mlpatterns.imdb_sentiment,
(SELECT 'This was very well done.' AS reviews)
)
Out[13]:
Now, do it at scale, on consumer complaints about financial products and services:
In [42]:
%%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
)
)
In [44]:
preds[:3]
Out[44]:
In [48]:
# what's does a "positive" complaint look like?
preds.sort_values(by='positive_review_probability', ascending=False).iloc[1]['reviews']
Out[48]:
In [49]:
# what's does a "typical" complaint look like?
preds.sort_values(by='positive_review_probability', ascending=False).iloc[len(preds)//2]['reviews']
Out[49]:
Copyright 2020 Google Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License