Goolge Cloud Skills Boost

최근글


새댓글


Hot Deal


[GSP354] Build and Deploy Machine Learning Solutions with Vertex AI: Challenge Lab

컨텐츠 정보

본문

``` preprocessor = hub.KerasLayer(hparams['tfhub-bert-preprocessor'], name='preprocessing') ``` 이 부분은 TensorFlow Hub에서 제공하는 BERT 사전처리 모델을 불러와 KerasLayer로 만드는 코드입니다. hparams는 하이퍼파라미터를 담은 딕셔너리이며, 여기서는 사전처리 모델의 URL을 가져옵니다. ``` encoder = hub.KerasLayer(hparams['tfhub-bert-encoder'], trainable=True, name='BERT_encoder') ``` 위 코드는 마찬가지로 TensorFlow Hub에서 BERT 인코더 모델을 불러오지만, 이번에는 모델을 학습 가능하게 설정합니다. 이것은 모델을 미세 조정할 때 필요합니다. ``` "model-dir": "./bert-sentiment-classifier-local" ``` 이 코드는 모델 파일들을 저장할 로컬 디렉터리 경로를 설정하는 부분입니다. ``` !gcloud artifacts repositories create {ARTIFACT_REGISTRY} \ --repository-format=docker \ --location={REGION} \ --description="Artifact registry for ML custom training images for sentiment classification" ``` 커맨드라인 명령은 Google Cloud의 gcloud 도구를 사용하여 새로운 Artifact Registry 리포지토리를 생성합니다. 이 리포지토리는 도커 이미지 형식으로, 주로 머신러닝 모델을 학습하기 위한 사용자 정의 이미지를 저장하는 데 사용됩니다. ``` !gcloud builds submit {MODEL_DIR} --timeout=20m --config {MODEL_DIR}/cloudbuild.yaml ``` 여기서는 gcloud builds submit 명령어를 사용하여 구성 파일 cloudbuild.yaml에 따라 Cloud Build 프로세스를 시작합니다. 이 과정에서 모델 디렉토리를 Google Cloud에 제출하고, 이를 통해 모델을 빌드하거나 배포할 수 있습니다. ``` USER = "" ``` 사용자 이름 또는 식별자를 설정하는 변수입니다. ``` display_name=display_name, container_uri=container_uri, model_serving_container_image_uri=model_serving_container_image_uri, base_output_dir=GCS_BASE_OUTPUT_DIR, ``` 사용자 이름 또는 식별자를 설정하는 변수입니다. ``` endpoint = vertexai.Endpoint( endpoint_name=ENDPOINT_NAME, project=PROJECT_ID, location=REGION ) ``` Vertex AI의 Endpoint 객체를 생성하는 코드입니다. 이 엔드포인트는 머신러닝 모델이 호스팅되고 예측을 제공하는데 사용됩니다. ``` test_review = "The Dark Knight is the best Batman movie!" ``` 이 부분은 테스트 예제로, 영화 리뷰 텍스트 문자열을 담고 있습니다. ``` prediction = endpoint.predict([test_review]) ``` 마지막으로, 앞서 생성한 Vertex AI 엔드포인트를 사용하여 test_review 문자열에 대한 예측을 수행합니다. 이 코드 조각들은 모델의 사전 처리, 학습, 빌드, 배포 및 예측에 대한 여러 단계를 나타냅니다.

관련자료

댓글 0
등록된 댓글이 없습니다.
전체 21 / 1 페이지
RSS