本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
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
必要时,在 with()
步骤中使用 Neptune#ml.endpoint
谓词来指定推理端点:
.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
在 with()
步骤中使用 Neptune#ml.iamRoleArn
来指定 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
在 Gremlin 节点或边缘分类查询中使用 Neptune#ml.score
谓词来获取机器学习置信度分数。在 properties()
步骤中应将 Neptune#ml.score
谓词与查询谓词一起传递,以获得节点或边缘分类查询的 ML 置信度分数。
您可以找到一个包含其它节点分类示例的节点分类示例,以及边缘分类部分中的一个边缘分类示例。