Python 用于为 AutoML 自然语言创建 JSONL 训练文件的脚本

Python script for creating JSONL training files for AutoML Natural Language

我正在尝试为 AutoML Natural Language 创建 JSONL 训练文件,它在 docs

To help you create JSONL training files, AutoML Natural Language offers a Python script that converts plain text files into appropriately formatted JSONL files. See the comments in the script for details.

我试图关注这些评论,但我没有得到它们 我试过运行用这个

python jason.py C:\..dic.csv C:\..text.txt gs://mybucket

但它给了我:

(with 5 blank lines skipped)
Traceback (most recent call last):
  File "jason.py", line 688, in <module>
    main()
  File "jason.py", line 680, in main
    UploadFiles(annotated_files, FLAGS.target_gcs_directory)
  File "jason.py", line 636, in UploadFiles
    f.write(csv_line)
TypeError: write() argument must be str, not bytes

谁能帮我举例说明如何 运行 script

提供的tool是使用python2创建的。您可以 运行 python2 jsonl_converter.py -s sample_1.txt gs://your-bucket 这样您就不会编辑提供的代码。或者,如果您需要 运行 python3,您可以遵循@Justin Ezequiel 的建议。我只是使用了 -s 选项来自动分割长文件。

使用 python 2 进行测试:

指定 GCS 存储桶中的 JSONL: