適用於 Object2Vec 的編碼器內嵌 - Amazon SageMaker

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

適用於 Object2Vec 的編碼器內嵌

下頁列出從 Amazon SageMaker Object2Vec 模型取得編碼器內嵌推論的輸入請求和輸出回應格式。

GPU 最佳化:編碼器內嵌

內嵌是指從離散物件 (例如單字) 對應至實數向量。

由於GPU記憶體不足,可以指定INFERENCE_PREFERRED_MODE環境變數,以最佳化 適用於 Object2Vec 推論的資料格式或編碼器內嵌推論網路是否載入 GPU。如果大部分的推論是用於編碼器內嵌,請指定 INFERENCE_PREFERRED_MODE=embedding。以下是使用 4 個 p3.2xlarge 執行個體,最佳化編碼器內嵌推論的批次轉換範例:

transformer = o2v.transformer(instance_count=4, instance_type="ml.p2.xlarge", max_concurrent_transforms=2, max_payload=1, # 1MB strategy='MultiRecord', env={'INFERENCE_PREFERRED_MODE': 'embedding'}, # only useful with GPU output_path=output_s3_path)

輸入:編碼器內嵌

Content-type:Application/json;infer_max_seqlens=<FWD-LENGTH>、<BCK-LENGTH>

其中 <FWD-LENGTH> 和 <BCK-LENGTH> 是 【1,5000】 範圍內的整數,並定義向前和向後編碼器的最大序列長度。

{ "instances" : [ {"in0": [6, 17, 606, 19, 53, 67, 52, 12, 5, 10, 15, 10178, 7, 33, 652, 80, 15, 69, 821, 4]}, {"in0": [22, 1016, 32, 13, 25, 11, 5, 64, 573, 45, 5, 80, 15, 67, 21, 7, 9, 107, 4]}, {"in0": [774, 14, 21, 206]} ] }

Content-type:Application/jsonlines;infer_max_seqlens=<FWD-LENGTH>、<BCK-LENGTH>

其中 <FWD-LENGTH> 和 <BCK-LENGTH> 是 【1,5000】 範圍內的整數,並定義向前和向後編碼器的最大序列長度。

{"in0": [6, 17, 606, 19, 53, 67, 52, 12, 5, 10, 15, 10178, 7, 33, 652, 80, 15, 69, 821, 4]} {"in0": [22, 1016, 32, 13, 25, 11, 5, 64, 573, 45, 5, 80, 15, 67, 21, 7, 9, 107, 4]} {"in0": [774, 14, 21, 206]}

在這兩種格式中,您只要指定 “in0”“in1.” 其中一個輸入類型。推論服務即會為每個執行個體調用對應的編碼器,並輸出內嵌。

輸出:編碼器內嵌

Content-type: application/json

{ "predictions": [ {"embeddings":[0.057368703186511,0.030703511089086,0.099890425801277,0.063688032329082,0.026327300816774,0.003637571120634,0.021305780857801,0.004316598642617,0.0,0.003397724591195,0.0,0.000378780066967,0.0,0.0,0.0,0.007419463712722]}, {"embeddings":[0.150190666317939,0.05145975202322,0.098204270005226,0.064249359071254,0.056249320507049,0.01513972133398,0.047553978860378,0.0,0.0,0.011533712036907,0.011472506448626,0.010696629062294,0.0,0.0,0.0,0.008508535102009]} ] }

Content-type: application/jsonlines

{"embeddings":[0.057368703186511,0.030703511089086,0.099890425801277,0.063688032329082,0.026327300816774,0.003637571120634,0.021305780857801,0.004316598642617,0.0,0.003397724591195,0.0,0.000378780066967,0.0,0.0,0.0,0.007419463712722]} {"embeddings":[0.150190666317939,0.05145975202322,0.098204270005226,0.064249359071254,0.056249320507049,0.01513972133398,0.047553978860378,0.0,0.0,0.011533712036907,0.011472506448626,0.010696629062294,0.0,0.0,0.0,0.008508535102009]}

推論服務輸出的內嵌向量長度等於您在訓練時指定的下列其中一個超參數值:enc0_token_embedding_dimenc1_token_embedding_dimenc_dim