Hello 文字資料:設定專案和環境

如果您打算使用 Vertex AI SDK for Python,請確認初始化用戶端的服務帳戶具有 Vertex AI 服務代理 (roles/aiplatform.serviceAgent) IAM 角色。

在本教學課程的這一部分,您將設定 Google Cloud 專案,以使用 Vertex AI 和 Cloud Storage bucket,其中包含用於訓練 AutoML 模型的文件。

本教學課程包含多個頁面:

  1. 設定專案和環境。

  2. 建立文字分類資料集。

  3. 訓練 AutoML 文字分類模型。

  4. 將模型部署至端點並傳送預測。

  5. 清除專案所用資源。

各頁面都假設您已按照本教學課程先前頁面的指示操作。

設定專案和環境

使用 Vertex AI 功能前,請先完成下列步驟。

  1. In the Google Cloud console, go to the project selector page.

    Go to project selector

  2. Select or create a Google Cloud project.

  3. Verify that billing is enabled for your Google Cloud project.

  4. 開啟 Cloud Shell。 Cloud Shell 是一種互動式殼層環境,可讓您透過網路瀏覽器管理專案和資源。 Google Cloud
  5. 前往 Cloud Shell
  6. 在 Cloud Shell 中,將目前的專案設為專案 ID,並儲存在 projectid 殼層變數中: Google Cloud
      gcloud config set project PROJECT_ID &&
      projectid=PROJECT_ID &&
      echo $projectid
    PROJECT_ID 替換為專案 ID。您可以在 Google Cloud 控制台中找到專案 ID。詳情請參閱「找出專案 ID」。
  7. Enable the IAM, Compute Engine, Notebooks, Cloud Storage, and Vertex AI APIs.

    Enable the APIs

  8. Make sure that you have the following role or roles on the project: roles/aiplatform.user, roles/storage.admin

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往 IAM
    2. 選取專案。
    3. 按一下「授予存取權」
    4. 在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。

    5. 在「Select a role」(選取角色) 清單中,選取角色。
    6. 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
    7. 按一下 [Save]
    Vertex AI 使用者 (roles/aiplatform.user) IAM 角色可授權存取及使用 Vertex AI 中的所有資源。「儲存空間管理員」(roles/storage.admin) 可讓您將文件訓練資料集儲存在 Cloud Storage 中。

    建立 Cloud Storage bucket 並複製範例資料集

    建立 Cloud Storage 值區,以儲存用於訓練 AutoML 模型的文件。

    1. 開啟 Cloud Shell

    2. PROJECT_ID 變數設為專案 ID。

      export PROJECT_ID=PROJECT_ID
    3. 設定 BUCKET 變數,用於建立 Cloud Storage bucket。

      export BUCKET=${PROJECT_ID}-lcm
    4. us-central1 區域中建立 Cloud Storage 值區,並使用 BUCKET 變數。

      gcloud storage buckets create gs://${BUCKET}/ --project=${PROJECT_ID} --location=us-central1
    5. happiness.csv 訓練資料集樣本複製到值區。

      gcloud storage cp gs://cloud-ml-data/NL-classification/happiness.csv gs://${BUCKET}/text/ --recursive

    後續步驟

    請按照本教學課程的下一頁操作,使用 Vertex AI 控制台建立文字分類資料集,並匯入您複製到 Cloud Storage bucket 的文件。