Google Cloud Vertex AI Feature Store によるエンリッチメント
|
Apache Beam 2.55.0 以降のバージョンでは、エンリッチメント変換には Vertex AI Feature Store の組み込みエンリッチメントハンドラーが含まれています。次の例では、VertexAIFeatureStoreEnrichmentHandler
ハンドラーと VertexAIFeatureStoreLegacyEnrichmentHandler
ハンドラーを使用してエンリッチメント変換を使用するパイプラインを作成する方法を示します。
例 1: Vertex AI Feature Store によるエンリッチメント
Vertex AI Feature Store に保存されている事前計算済みの特徴値は、次の形式を使用します。
user_id | age | gender | state | country |
---|---|---|---|---|
21422 | 12 | 0 | 0 | 0 |
2963 | 12 | 1 | 1 | 1 |
20592 | 12 | 1 | 2 | 2 |
76538 | 12 | 1 | 3 | 0 |
import apache_beam as beam
from apache_beam.transforms.enrichment import Enrichment
from apache_beam.transforms.enrichment_handlers.vertex_ai_feature_store \
import VertexAIFeatureStoreEnrichmentHandler
project_id = 'apache-beam-testing'
location = 'us-central1'
api_endpoint = f"{location}-aiplatform.googleapis.com"
data = [
beam.Row(user_id='2963', product_id=14235, sale_price=15.0),
beam.Row(user_id='21422', product_id=11203, sale_price=12.0),
beam.Row(user_id='20592', product_id=8579, sale_price=9.0),
]
vertex_ai_handler = VertexAIFeatureStoreEnrichmentHandler(
project=project_id,
location=location,
api_endpoint=api_endpoint,
feature_store_name="vertexai_enrichment_example",
feature_view_name="users",
row_key="user_id",
)
with beam.Pipeline() as p:
_ = (
p
| "Create" >> beam.Create(data)
| "Enrich W/ Vertex AI" >> Enrichment(vertex_ai_handler)
| "Print" >> beam.Map(print))
出力
Row(user_id='2963', product_id=14235, sale_price=15.0, age=12.0, state='1', gender='1', country='1')
Row(user_id='21422', product_id=11203, sale_price=12.0, age=12.0, state='0', gender='0', country='0')
Row(user_id='20592', product_id=8579, sale_price=9.0, age=12.0, state='2', gender='1', country='2')
例 2: Vertex AI Feature Store によるエンリッチメント (レガシー)
Vertex AI Feature Store (レガシー) に保存されている事前計算済みの特徴値は、次の形式を使用します。
entity_id | title | genres |
---|---|---|
movie_01 | ショーシャンクの空に | ドラマ |
movie_02 | シャイニング | ホラー |
movie_04 | ダークナイト | アクション |
import apache_beam as beam
from apache_beam.transforms.enrichment import Enrichment
from apache_beam.transforms.enrichment_handlers.vertex_ai_feature_store \
import VertexAIFeatureStoreLegacyEnrichmentHandler
project_id = 'apache-beam-testing'
location = 'us-central1'
api_endpoint = f"{location}-aiplatform.googleapis.com"
data = [
beam.Row(entity_id="movie_01", title='The Shawshank Redemption'),
beam.Row(entity_id="movie_02", title="The Shining"),
beam.Row(entity_id="movie_04", title='The Dark Knight'),
]
vertex_ai_handler = VertexAIFeatureStoreLegacyEnrichmentHandler(
project=project_id,
location=location,
api_endpoint=api_endpoint,
entity_type_id='movies',
feature_store_id="movie_prediction_unique",
feature_ids=["title", "genres"],
row_key="entity_id",
)
with beam.Pipeline() as p:
_ = (
p
| "Create" >> beam.Create(data)
| "Enrich W/ Vertex AI" >> Enrichment(vertex_ai_handler)
| "Print" >> beam.Map(print))
出力
関連する変換
該当なし。
![]() |
最終更新日: 2024/10/31
探していたものはすべて見つかりましたか?
すべて有用で明確でしたか?変更したい点はありますか?ぜひお知らせください!