Gremlin 推論查詢中使用的 Neptune ML 述詞 - Amazon Neptune

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

Gremlin 推論查詢中使用的 Neptune ML 述詞

Neptune#ml.deterministic

這個述詞是針對歸納推論查詢的選項,也就是,針對包含 Neptune#ml.inductiveInference 述詞的查詢。

使用歸納推斷時,Neptune 引擎會建立適當的子圖來評估訓練後的 GNN 模型,而這個子圖的需求取決於最終模型的參數。尤其,num-layer 參數會決定來自目標節點或邊緣的周遊躍點數目,而 fanouts 參數則會指定要在每個躍點上取樣的鄰近項目數 (請參閱 HPO 參數)。

根據預設,歸納推論查詢會在非確定性模式下執行,其中 Neptune 會隨機建置鄰域。在進行預測時,這種正常的隨機鄰近項目抽樣有時會導致不同的預測。

當您在歸納推論查詢中包含 Neptune#ml.deterministic 時,Neptune 引擎會嘗試以確定性的方式對鄰近項目進行取樣,以便相同查詢的多次調用,每次都會傳回相同的結果。不過,不能保證結果是完全確定的,因為對分散式系統的基礎圖形和成品的變更仍然可能會引起波動。

您可以在查詢中包含 Neptune#ml.deterministic 述詞,如下所示:

.with("Neptune#ml.deterministic")

如果包含 Neptune#ml.deterministic 述詞的查詢中未同時包含 Neptune#ml.inductiveInference,則只需將其忽略即可。

Neptune#ml.disableInductiveInferenceMetadataCache

這個述詞是針對歸納推論查詢的選項,也就是,針對包含 Neptune#ml.inductiveInference 述詞的查詢。

對於歸納推論查詢,Neptune 會使用儲存在 Amazon S3 中的中繼資料檔案,以在建立鄰域時決定躍點數和扇出數。Neptune 通常會快取此模型中繼資料,以避免重複從 Amazon S3 擷取檔案。可在查詢中包含 Neptune#ml.disableInductiveInferenceMetadataCache 述詞來停用快取。雖然 Neptune 直接從 Amazon S3 擷取中繼資料可能會比較慢,但是當 SageMaker 端點在重新訓練或轉換之後更新了且快取過時時,這會很有用。

您可以在查詢中包含 Neptune#ml.disableInductiveInferenceMetadataCache 述詞,如下所示:

.with("Neptune#ml.disableInductiveInferenceMetadataCache")

以下是查詢範例在 Jupyter 筆記本中的可能樣子:

%%gremlin g.with("Neptune#ml.endpoint", "ep1") .with("Neptune#ml.iamRoleArn", "arn:aws:iam::123456789012:role/NeptuneMLRole") .with("Neptune#ml.disableInductiveInferenceMetadataCache") .V('101').properties("rating") .with("Neptune#ml.regression") .with("Neptune#ml.inductiveInference")

Neptune#ml.endpoint

Neptune#ml.endpoint 述詞會在 with() 步驟中用來指定推論端點 (如有必要):

.with("Neptune#ml.endpoint", "the model's SageMaker inference endpoint")

您可以透過端點 id 或其 URL 來識別端點。例如:

.with( "Neptune#ml.endpoint", "node-classification-movie-lens-endpoint" )

或者:

.with( "Neptune#ml.endpoint", "https://runtime.sagemaker.us-east-1.amazonaws.com/endpoints/node-classification-movie-lens-endpoint/invocations" )
注意

如果您將 Neptune 資料庫叢集參數群組中的 neptune_ml_endpoint 參數設定為端點 id 或 URL,則不需要在每個查詢中包含 Neptune#ml.endpoint 述詞。

Neptune#ml.iamRoleArn

Neptune#ml.iamRoleArn 會在 with() 步驟中用來指定 SageMaker 執行 IAM 角色的 ARN (如有必要):

.with("Neptune#ml.iamRoleArn", "the ARN for the SageMaker execution IAM role")

如需如何建立 SageMaker 執行 IAM 角色的相關資訊,請參閱 建立自訂 NeptuneSageMakerIAMRole 角色

注意

如果您將 Neptune 資料庫叢集參數群組中的 neptune_ml_iam_role 參數設定為 SageMaker 執行 IAM 角色的 ARN,則不需要在每個查詢中包含 Neptune#ml.iamRoleArn 述詞。

Neptune#ml.inductiveInference

預設會在 Gremlin 中啟用直推式推論。若要進行即時直推式推論查詢,請包含如下 Neptune#ml.inductiveInference 述詞:

.with("Neptune#ml.inductiveInference")

如果您的圖形是動態的,歸納推論通常是最佳選擇,但是如果您的圖形是靜態的,則直推式推論更快、更有效率。

Neptune#ml.limit

Neptune#ml.limit 述詞可以選擇性地限制每個實體傳回的結果數量:

.with( "Neptune#ml.limit", 2 )

根據預設,限制為 1,但可以設定的數量上限為 100。

Neptune#ml.threshold

Neptune#ml.threshold 述詞可以選擇性地建立結果分數的截止閾值:

.with( "Neptune#ml.threshold", 0.5D )

這可讓您捨棄分數低於指定閾值的所有結果。

Neptune#ml.classification

Neptune#ml.classification 述詞會附加至 properties() 步驟,以確定需要從節點分類模型的 SageMaker 端點擷取屬性:

.properties( "property key of the node classification model" ).with( "Neptune#ml.classification" )

Neptune#ml.regression

Neptune#ml.regression 述詞會附加至 properties() 步驟,以確定需要從節點迴歸模型的 SageMaker 端點擷取屬性:

.properties( "property key of the node regression model" ).with( "Neptune#ml.regression" )

Neptune#ml.prediction

Neptune#ml.prediction 述詞會附加到 in()out() 步驟,以確定這是連結預測查詢:

.in("edge label of the link prediction model").with("Neptune#ml.prediction").hasLabel("target node label")

Neptune#ml.score

Neptune#ml.score 述詞用於 Gemlin 節點或邊緣分類查詢中,以擷取機器學習可信度分數。Neptune#ml.score 述詞應該與 properties() 步驟中的查詢述詞一起傳遞,以取得節點或邊緣分類查詢的 ML 可信度分數。

您可以在邊緣分類區段中找到具有其他節點分類範例的節點分類範例,以及邊緣分類範例。