檢查 Azure Machine Learning 結構描述
azure_ai
延伸模組的 azure_ml
結構描述可讓您的資料庫與自訂建置機器學習模型的功能互動。 利用 azure_ml
結構描述,您可以順暢地整合 PostgreSQL 資料庫與 Azure Machine Learning 服務。 這項整合可讓您直接從資料庫部署及提供機器學習模型,讓即時推斷更有效率並可調整。
使用 azure_ml
結構描述的即時推斷
Azure Machine Learning 是一個雲端式平台,可簡化端對端機器學習工作流程。 在 Azure Machine Learning 中,模型是使用 PyTorch 和 TensorFlow 等熱門架構所開發。 定型後,這些模型會部署為端點、可要求預測的穩定 URL。
透過提供即時推斷的線上端點,Azure Machine Learning 與 azure_ai
延伸模組整合,可讓您直接從資料庫進行精確的預測。 此結構描述內的 inference
函式旨在協助使用 Azure Machine Learning 中定型的模型進行預測或產生輸出。 當您部署模型時,推斷函式可讓您叫用模型,並取得新資料的預測。
azure_ml.inference(jsonb,integer,boolean,text)
inference()
函式必須要有下列輸入參數:
參數 | 類型 | 預設 | 描述 |
---|---|---|---|
input_data | jsonb |
JSON 物件,其中包含與 Azure Machine Learning 模型互動所需的 input_data 物件。 |
|
deployment_name | text |
NULL::text |
(選用) 要以指定的 Azure Machine Learning 端點為目標的模型部署名稱。 |
timeout_ms | integer |
NULL::integer |
逾時... |
throw_on_error | boolean |
true |
desc... |
max_attempts | integer |
1 |
在發生失敗時重試對 Azure OpenAI 服務的呼叫次數。 |
retry_delay_ms | integer |
1000 |
嘗試重試呼叫 Azure OpenAI 服務端點之前所要等候的時間量 (以毫秒為單位)。 |
Azure Machine Learning 推斷端點必須要有 JavaScript 物件標記法 (JSON) 物件作為輸入。 不過,此物件的結構相依於基礎模型。 例如,定型的迴歸模型用以預測華盛頓州西雅圖地區短期住房租金的每日租金價格,而如有特定輸入 (例如鄰近區域、郵遞區號、房間數目、浴室數目等等),其具有下列形狀:
{
"input_data": {
"columns": [
"host_is_superhost",
"host_has_profile_pic",
"host_identity_verified",
"neighbourhood_group_cleansed",
"zipcode",
"property_type",
"room_type",
"accommodates",
"bathrooms",
"bedrooms",
"beds"
],
"index": [0],
"data": [["False", "False", "False", "Central Area", "98122", "House", "Entire home/apt", 4, 1.5, 3, 3]]
}
}
檢查與已部署端點相關聯的 Swagger 定義,即可擷取預期的輸入物件結構。 此定義會指定 ServiceInput
和 ServiceOutput
結構,您可使用這個結構來判斷輸入和輸出。
設定 Azure Machine Learning 的連線
使用 azure_ml.inference()
函式執行即時推斷之前,您必須使用 Azure Machine Learning 評分端點和金鑰來設定延伸模組。 azure_ml.scoring_endpoint
的值是已部署模型的 REST 端點。 azure_ml.endpoint_key
的值可以是此端點的主要或次要金鑰。
SELECT azure_ai.set_setting('azure_ml.scoring_endpoint', '{endpoint}');
SELECT azure_ai.set_setting('azure_ml.endpoint_key', '{api-key}');