使用 neptune-export 工具或 Neptune-Export 服务从 Neptune 导出数据用于 Neptune ML - Amazon Neptune
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

使用 neptune-export 工具或 Neptune-Export 服务从 Neptune 导出数据用于 Neptune ML

Neptune ML 要求您为深度图表库 (DGL) 提供训练数据,以创建和评估模型。

您可以使用 Neptune-Export 服务neptune-export 实用程序从 Neptune 导出数据。该服务和命令行工具均以 CSV 格式将数据发布到 Amazon Simple Storage Service (Amazon S3) 的数据,且使用 Amazon S3 服务器端加密 (SSE-S3) 进行加密。请参阅由 Neptune-Export 和 neptune-export 导出的文件

此外,当您为 Neptune ML 配置训练数据的导出时,导出任务会创建并发布加密的模型训练配置文件以及导出的数据。默认情况下,此文件命名为 training-data-configuration.json

使用 Neptune-Export 服务为 Neptune ML 导出训练数据的示例

此请求导出节点分类任务的属性图训练数据:

curl \ (your NeptuneExportApiUri) \ -X POST \ -H 'Content-Type: application/json' \ -d '{ "command": "export-pg", "outputS3Path": "s3://(your Amazon S3 bucket)/neptune-export", "params": { "endpoint": "(your Neptune endpoint DNS name)", "profile": "neptune_ml" }, "additionalParams": { "neptune_ml": { "version": "v2.0", "targets": [ { "node": "Movie", "property": "genre", "type": "classification" } ] } } }'

此请求导出节点分类任务的 RDF 训练数据:

curl \ (your NeptuneExportApiUri) \ -X POST \ -H 'Content-Type: application/json' \ -d '{ "command": "export-rdf", "outputS3Path": "s3://(your Amazon S3 bucket)/neptune-export", "params": { "endpoint": "(your Neptune endpoint DNS name)", "profile": "neptune_ml" }, "additionalParams": { "neptune_ml": { "version": "v2.0", "targets": [ { "node": "http://aws.amazon.com/neptune/csv2rdf/class/Movie", "predicate": "http://aws.amazon.com/neptune/csv2rdf/datatypeProperty/genre", "type": "classification" } ] } } }'

导出训练数据时要在 params 对象中设置的字段

params 文档中所述,导出请求中的 params 对象可以包含各种字段。以下字段与导出机器学习训练数据最为相关:

  • endpoint – 使用 endpoint 指定数据库集群中 Neptune 实例的端点,导出过程可以查询该端点以提取数据。

  • profileparams 对象中的 profile 字段必须设置为 neptune-ml

    这导致导出过程针对 Neptune ML 模型训练适当地格式化导出的数据,针对属性图数据格式化为 CSV 格式,或针对 RDF 数据格式化为 N-Triples。它还会创建 training-data-configuration.json 文件,并将其写入与导出的训练数据相同的 Amazon S3 位置。

  • cloneCluster – 如果设置为 true,则导出过程将克隆您的数据库集群,从克隆中导出,然后在导出完成后将克隆删除。

  • useIamAuth – 如果您的数据库集群启用了 IAM 身份验证,则必须包含此字段(设置为 true)。

导出过程还提供了多种筛选您导出的数据的方法(请参阅这些示例)。

使用 additionalParams 对象调整模型训练信息的导出

additionalParams 对象包含的字段可用于指定用于训练目的的机器学习类别标签和特征,并指导创建训练数据配置文件。

导出过程无法自动推理哪些节点和边缘属性应作为机器学习类别标签以用于训练目的的示例。它也无法自动推理数字、分类和文本属性的最佳特征编码,因此您需要使用 additionalParams 对象中的字段提供提示来指定这些编码,或者覆盖默认编码。

对于属性图数据,导出请求中 additionalParams 的顶级结构可能如下所示:

{ "command": "export-pg", "outputS3Path": "s3://(your Amazon S3 bucket)/neptune-export", "params": { "endpoint": "(your Neptune endpoint DNS name)", "profile": "neptune_ml" }, "additionalParams": { "neptune_ml": { "version": "v2.0", "targets": [ (an array of node and edge class label targets) ], "features": [ (an array of node feature hints) ] } } }

对于 RDF 数据,其顶层结构可能如下所示:

{ "command": "export-rdf", "outputS3Path": "s3://(your Amazon S3 bucket)/neptune-export", "params": { "endpoint": "(your Neptune endpoint DNS name)", "profile": "neptune_ml" }, "additionalParams": { "neptune_ml": { "version": "v2.0", "targets": [ (an array of node and edge class label targets) ] } } }

您还可以使用 jobs 字段提供多种导出配置:

{ "command": "export-pg", "outputS3Path": "s3://(your Amazon S3 bucket)/neptune-export", "params": { "endpoint": "(your Neptune endpoint DNS name)", "profile": "neptune_ml" }, "additionalParams" : { "neptune_ml" : { "version": "v2.0", "jobs": [ { "name" : "(training data configuration name)", "targets": [ (an array of node and edge class label targets) ], "features": [ (an array of node feature hints) ] }, { "name" : "(another training data configuration name)", "targets": [ (an array of node and edge class label targets) ], "features": [ (an array of node feature hints) ] } ] } } }

additionalParamsneptune_ml 字段中的顶级元素

neptune_ml 中的 version 元素

指定要生成的训练数据配置的版本。

可选),类型:字符串,默认值:“v2.0”。

如果确实包含 version,请将其设置为 v2.0

neptune_ml 中的 jobs 字段

包含训练数据配置对象的数组,其中每个对象都定义了一个数据处理任务,并包含:

  • name – 要创建的训练数据配置的名称。

    例如,名为“job-number-1”的训练数据配置会生成名为 job-number-1.json 的训练数据配置文件。

  • targets – 由节点和边缘类别标签目标组成的 JSON 数组,代表用于训练目的的机器学习类别标签。请参阅neptune_ml 对象中的 targets 字段

  • features– 节点属性特征的 JSON 数组。请参阅neptune_ml 中的 features 字段