Neptune ML 中的 Gremlin 节点分类查询 - Amazon Neptune
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Neptune ML 中的 Gremlin 节点分类查询

对于 Neptune ML 中的 Gremlin 节点分类:

  • 模型是在顶点的一个属性上进行训练的。此属性的唯一值集被称为一组节点类,或简单地称为类。

  • 可以从节点分类模型推断顶点属性的节点类或类别属性值。在此属性尚未附加到顶点的情况下,这很有用。

  • 为了从节点分类模型中获取一个或多个类,你需要使用with()跟谓词一步Neptune#ml.classification要配置properties()步骤。如果这些是顶点属性,输出格式与您期望的格式相似。

以下是一个节点分类查询示例:

g.with( "Neptune#ml.endpoint","node-classification-movie-lens-endpoint" ) .with( "Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role" ) .with( "Neptune#ml.limit", 2 ) .with( "Neptune#ml.threshold", 0.5D ) .V( "movie_1", "movie_2", "movie_3" ) .properties("genre").with("Neptune#ml.classification")

此查询的输出将类似于以下内容:

==>vp[genre->Action]
==>vp[genre->Crime]
==>vp[genre->Comedy]

在上面的查询中,V()properties()步骤的使用方法如下:

这些区域有:V()step 包含要从节点分类模型中获取类的顶点集:

.V( "movie_1", "movie_2", "movie_3" )

这些区域有:properties()step 包含模型训练的关键,并且具有.with("Neptune#ml.classification")表明这是节点分类 ML 推理查询。

目前不支持多个属性键properties().with("Neptune#ml.classification")步骤。例如,以下查询会导致异常:

g.with("Neptune#ml.endpoint", "node-classification-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V( "movie_1", "movie_2", "movie_3" ) .properties("genre", "other_label").with("Neptune#ml.classification")

有关具体错误消息,请参阅Neptune ML 例外列表.

一个properties().with("Neptune#ml.classification")step 可以与以下任何步骤结合使用:

  • value()

  • value().is()

  • hasValue()

  • has(value,"")

  • key()

  • key().is()

  • hasKey()

  • has(key,"")

  • path()

其他节点分类查询

如果推理终端节点和相应的 IAM 角色已保存在数据库集群参数组中,则节点分类查询可以如下所示简单:

g.V("movie_1", "movie_2", "movie_3").properties("genre").with("Neptune#ml.classification")

您可以使用在查询中混合顶点属性和类union()步骤:

g.with("Neptune#ml.endpoint","node-classification-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V( "movie_1", "movie_2", "movie_3" ) .union( properties("genre").with("Neptune#ml.classification"), properties("genre") )

你也可以做一个无界查询,例如这样:

g.with("Neptune#ml.endpoint","node-classification-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V() .properties("genre").with("Neptune#ml.classification")

您可以使用select()as()步骤:

g.with("Neptune#ml.endpoint","node-classification-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V( "movie_1", "movie_2", "movie_3" ).as("vertex") .properties("genre").with("Neptune#ml.classification").as("properties") .select("vertex","properties")

您还可以对节点类进行筛选,如以下示例所示:

g.with("Neptune#ml.endpoint", "node-classification-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V( "movie_1", "movie_2", "movie_3" ) .properties("genre").with("Neptune#ml.classification") .has(value, "Horror") g.with("Neptune#ml.endpoint","node-classification-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V( "movie_1", "movie_2", "movie_3" ) .properties("genre").with("Neptune#ml.classification") .has(value, P.eq("Action")) g.with("Neptune#ml.endpoint","node-classification-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V( "movie_1", "movie_2", "movie_3" ) .properties("genre").with("Neptune#ml.classification") .has(value, P.within("Action", "Horror"))

您可以使用Neptune#ml.score谓词:

g.with("Neptune#ml.endpoint","node-classification-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V( "movie_1", "movie_2", "movie_3" ) .properties("genre", "Neptune#ml.score").with("Neptune#ml.classification")

回应将如下所示:

==>vp[genre->Action]
==>vp[Neptune#ml.score->0.01234567]
==>vp[genre->Crime]
==>vp[Neptune#ml.score->0.543210]
==>vp[genre->Comedy]
==>vp[Neptune#ml.score->0.10101]