こんにちは、PS課の峯です。
Amazon Sagemakerではユーザーがモデルをトレーニングしてデプロイするだけでなく、AWS Marketplaceでトレーニング済みモデルを購入しデプロイすることもできます。
SageMakerの左下からAWS Marketplaceへ。
すでにAmazon Sagemakerにチェックが入っています。
今回はこちらの無料のトレーニング済みモデルを使用します。
歌詞を生成するモデルのようです。
「Continue to Subscribe」をクリックして進みます。
説明を読んで「Accept Offer」をクリックします。このモデルはml.c5.xlargeしか使えないようです。他のモデルでも利用できるインスタンスタイプが限られているものがあります。モデル自体は無料でもエンドポイントを作成するとそのインスタンスタイプ分の料金はかかるので注意しましょう。
バーションやらリージョンを選択し、「View in SageMakher」をクリック。
するとSageMakerのコンソールの推論 > モデルパッケージ > AWS Marketplaceのサブスクリプションに追加されていればOKです。
あとはモデルパッケージを選択し、アクションからモデル/エンドポイントを作成すれば予測が行えます。
ちなみに
ここではエンドポイント作成手順は省略しますが、「lyric-generater」という名でエンドポイント作成後、以下のように雑な感じで予測を行ってみました
import ast import sagemaker endpoint_name = "lyric-generater" payload = bytes('''{"instances":[{"artist":"taylor swift","seed":"sagemaker"}]}''',encoding="utf-8") predicter = sagemaker.predictor.RealTimePredictor(endpoint_name) result_str = predicter.predict(payload).decode() result = ast.literal_eval(result_str) lyric = result['predictions'][0]['lyrics'] print(lyric)
ちなみに歌詞はこんな感じ…(成形してあります。)
Sagemaker she walk around she wanna be said she can't have to say her life is a city and she want the world in the morning its just she was a fool she said she was crazy she'll say how many times she will never do the shadow she said she says but she was proud nand she was shirting come on and be something she could she like it but she loves me i got some shake and she don't but she don't know about me I can do it for you she wants to be mad can't you see that she can survive i don't wanna know i don't know if the same {以下略}