本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Neptune ML 中的 Gremlin 节点分类查询
对于 Neptune ML 中的 Gremlin 节点分类:
模型是在顶点的一个属性上训练的。此属性的唯一值集被称为一组节点类,或简单地称为类。
可以从节点分类模型推断顶点属性的节点类或类别属性值。在此属性尚未附加到顶点的情况下,这很有用。
为了从节点分类模型中获取一个或多个类,你需要使用
with()
跟谓词一步Neptune#ml.classification
要配置properties()
Step。如果这些是顶点属性,输出格式与您期望的格式相似。
节点分类仅适用于字符串属性值。这意味着数字属性值,例如0
要么1
不支持,尽管字符串等效"0"
和"1"
是。同样,布尔值属性值true
和false
不起作用,但"true"
和"false"
执行该操作
以下是一个示例节点分类查询:
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()
步骤包含要从节点分类模型中获取类的顶点集:
.V( "movie_1", "movie_2", "movie_3" )
这些区域有:properties()
step 包含模型训练的关键,并且具有.with("Neptune#ml.classification")
表明这是节点分类 ML 推理查询。
目前不支持多个属性键properties().with("Neptune#ml.classification")
Step。例如,以下查询会导致异常:
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]