0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

rubyでVertexAIの テキスト分類(マルチラベル)

Last updated at Posted at 2023-08-24

テキスト分類(マルチラベル)の VertexAI のエンドポイントに対して
オンライン予測のリクエストを投げます。

GEM をインストールして、

gem install google-cloud-ai_platform-v1

以下を実行する。

認証

require "google/cloud/ai_platform/v1"

::Google::Cloud::AIPlatform::V1::PredictionService::Client.configure do |config|
  config.credentials = "path/to/keyfile.json"
end

参考:https://github.com/googleapis/google-cloud-ruby/blob/main/google-cloud-ai_platform-v1/AUTHENTICATION.md

リクエストを投げる

require "google/cloud/ai_platform/v1"

ENDPOINT_ID = "作成したモデルのID"
PROJECT_ID = "GCPのプロジェクトID"
LOCATION = "モデルがあるリージョン"

prediction_client = Google::Cloud::AIPlatform::V1::PredictionService::Client.new do |config|
  config.endpoint = "#{LOCATION}-aiplatform.googleapis.com"
end


instance = Google::Protobuf::Value.new(:struct_value => {:fields => {:content => {:string_value => "送りたいテキスト"}}})
model_full_id = "projects/#{PROJECT_ID}/locations/#{LOCATION}/endpoints/#{ENDPOINT_ID}"
@result = prediction_client.predict Google::Cloud::AIPlatform::V1::PredictRequest.new(endpoint: model_full_id, instances: [instance])

p @result

リクエスト作るところが分からなくて泣きそうでした。

参考
https://cloud.google.com/ruby/docs/reference/google-cloud-ai_platform-v1/latest/Google-Cloud-AIPlatform-V1-PredictionService-Client
https://stackoverflow.com/questions/72827960/how-to-get-image-classification-prediction-from-gcp-aiplatform-in-ruby

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?