--- tags: KHTN khtn recommendation system --- Note === https://stackoverflow.com/questions/47028898/how-tensorflow-handles-categorical-features-with-multiple-inputs-within-one-colu - https://www.tensorflow.org/api_docs/python/tf/feature_column/categorical_column_with_vocabulary_list - generate vocabulary and using it for all video_id/topic_id - set default value - Example pipeline - https://www.tensorflow.org/guide/data - Feture column - https://colab.research.google.com/drive/1xhaCTXu6gSZ723sLBOgRWp161Tl8eFow#scrollTo=DoUEEJ7WSkS5 - https://www.tensorflow.org/tutorials/keras/text_classification#train_the_model - https://colab.research.google.com/drive/1_sAitZMGkBqcDXTMYLs2RIkpo9RRKZdF#scrollTo=5DE8jgeury8i - Batch prediction - https://aihub.cloud.google.com/u/0/p/products%2Ff43ec53c-e534-4fd1-bbf9-5333f01fc7b5 - Cloud ML - https://github.com/GoogleCloudPlatform/cloudml-samples - https://github.com/GoogleCloudPlatform/ai-platform-samples - https://cloud.google.com/ai-platform/training/docs/overview - https://cloud.google.com/ai-platform/training/docs/training-jobs - https://www.tensorflow.org/tfx/tutorials/tfx/cloud-ai-platform-pipelines - Customs routes predict - https://stackoverflow.com/questions/62517564/ai-platform-online-prediction-with-keras-custom-preprocessing ### Deploy model ``` gcloud --quiet beta ai-platform versions create "v25" \ --model "pops_video_recommendation" \ --runtime-version 1.15 \ --python-version 3.7 \ --region us-central1 \ --origin gs://experiment_resources/model_7_using_video_topic/model_20200906_new/experiment_resources/model_7_using_video_topic/model/ \ --package-uris gs://experiment_resources/model_7_using_video_topic/model_20200906_new/experiment_resources/model_7_using_video_topic/model/pops_rec-0.3.tar.gz \ --prediction-class predictor.PopsRecV2Predictor ``` python setup.py sdist --formats=gztar ``` gcloud --quiet beta ai-platform versions create $VERSION_NAME \ --model $MODEL_NAME \ --runtime-version 2.2 \ --python-version 3.7 \ --origin gs://experiment_resources/model_7_using_video_topic/model_20200906_new/experiment_resources/model_7_using_video_topic/model/ \ --package-uris gs://$BUCKET_NAME/custom_prediction_routine_tutorial/my_custom_code-0.1.tar.gz \ --prediction-class predictor.MyPredictor ``` ``` gcloud ai-platform models create pops_video_recommendation --regions asia-northeast1 gcloud --quiet beta ai-platform versions create "v2" \ --model "pops_video_recommendation" \ --runtime-version 2.1 \ --python-version 3.7 \ --framework tensorflow \ --region asia-northeast1 \ --machine-type n1-standard-2 \ --origin gs://experiment_resources/model_7_using_video_topic/model_20200906_new/experiment_resources/model_7_using_video_topic/model/ \ --package-uris gs://$BUCKET_NAME/custom_prediction_routine_tutorial/my_custom_code-0.1.tar.gz \ --prediction-class predictor.PopsRecV2Predictor ``` ``` gcloud ai-platform models create pops_video_recommendation_asia --regions asia-east1 gcloud --quiet beta ai-platform versions create "v2" \ --model "pops_video_recommendation_asia" \ --runtime-version 2.1 \ --python-version 3.7 \ --region asia-east1 \ --origin gs://experiment_resources/model_7_using_video_topic/model_20200906_new/experiment_resources/model_7_using_video_topic/model/ \ --package-uris gs://experiment_resources/model_7_using_video_topic/model_20200906_new/experiment_resources/model_7_using_video_topic/model/pops_rec-0.1.tar.gz \ --prediction-class predictor.PopsRecV2Predictor ``` ``` gcloud ai-platform models create pops_video_recommendation --regions us-central1 gcloud --quiet beta ai-platform versions create "v2" \ --model "pops_video_recommendation" \ --runtime-version 2.1 \ --python-version 3.7 \ --region us-central1 \ --origin gs://experiment_resources/model_7_using_video_topic/model_20200906_new/experiment_resources/model_7_using_video_topic/model/ \ --package-uris gs://experiment_resources/model_7_using_video_topic/model_20200906_new/experiment_resources/model_7_using_video_topic/model/pops_rec-0.1.tar.gz \ --prediction-class predictor.PopsRecV2Predictor ``` ``` {"instances": [ {"input": [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]} ]} ``` ``` export PROJECT_ID='pops-recengine-v2-dev' export ZONE='asia-east1-a' export REGION='asia-east1' export MODEL_NAME='pops_video_recommendation_asia' export MODEL_DIR='gs://pops_raw_data/saved_model/1' export MODEL_VERSION='v2' ``` ## Step 01: Create an AI Model ``` gcloud ai-platform models create ${MODEL_NAME} \ --regions ${REGION} --enable-logging ``` ## Step 02: Deploy model ``` gcloud ai-platform versions create ${MODEL_VERSION} \ --model ${MODEL_NAME} \ --runtime-version 2.1 \ --python-version 3.7 \ --region ${REGION} \ --framework tensorflow \ --machine-type n1-standard-4 \ --origin ${MODEL_DIR} ``` ## GPU support ``` gcloud ai-platform versions create ${MODEL_VERSION} \ --model ${MODEL_NAME} \ --runtime-version 2.1 \ --python-version 3.7 \ --region ${REGION} \ --framework tensorflow \ --machine-type n1-standard-4 \ --accelerator count=1,type=nvidia-tesla-p100 \ --origin ${MODEL_DIR} ``` ``` {"instances": [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ]} ``` ``` {"instances": [{ "video_ids": ["None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None"], "topic_ids": ["None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None"], "keys": [0.1] }]} ```