TSV 作为 sagemaker 的输入

TSV as input to sagemaker

有没有办法使用 tsv 而不是 csv 作为 sagemaker 自动驾驶仪的输入?

目前我输入的数据是这样的:

input_data_config = [{
      'DataSource': {
        'S3DataSource': {
          'S3DataType': 'S3Prefix',
          'S3Uri': 's3://{}/{}/train'.format(bucket,prefix)
        }
      },
      'TargetAttributeName': 'sentiment'
    }
  ]

这似乎适用于 .csv 文件,但不适用于我的 .tsv 文件。

我是 AWS SageMaker 的一名开发人员。 Autopilot 目前仅支持 CSV 数据。虽然我们正在努力将支持扩展到更多文件格式:JSON、TSV 等,但您可以尝试将 .tsv 文件转换为 .csv:

import csv

# read tab-delimited file
with open('yourfile.tsv','rb') as fin:
    cr = csv.reader(fin, delimiter='\t')
    filecontents = [line for line in cr]

# write comma-delimited file (comma is the default delimiter)
with open('yourfile.csv','wb') as fou:
    cw = csv.writer(fou, quotechar='', quoting=csv.QUOTE_NONE)
    cw.writerows(filecontents)

希望对您有所帮助。

参考:How to convert a tab separated file to CSV format?