Swift NaturalLanguage 框架错误“Token SequenceType 长度为 0”

Swift NaturalLanguage framework error “Token SequenceType length is 0"

我目前正在使用 Apple 的 CreateML 从我拥有的 JSON 文件生成 NLP 模型。这是我的代码:

import Foundation
import CreateML
import NaturalLanguage

let trainingData = try MLDataTable(contentsOf: Bundle.main.url(forResource: "Fel", withExtension: "json")!)
let model = try MLWordTagger(trainingData: trainingData, tokenColumn: "tokens", labelColumn: "labels")
let metadata = MLModelMetadata(author: "Sai Kambampati", shortDescription: "The Felicity Named Entity Recognizer", license: "MIT", version: "1.0")
try model.write(to: URL(fileURLWithPath: "/Users/SaiKambampati/Desktop/Felicity.mlmodel"), metadata: metadata)

JSON 文件有 116,096 行,Xcode 能够正确解析它。它从 5% 的数据中生成了一个验证集。然而,当它开始标记数据和提取特征时,我收到一条错误消息:

▿ MLCreateError ▿ generic : 1 element - reason : "Token SequenceType length is 0”

我不知道这是什么意思,在网上也找不到任何东西!有人可以帮忙吗?

您的 JSON 文件必须采用此格式才能使用 MLWordTagger 的 tokenColumn 参数。标记作为字符串列表,标签作为字符串列表。

[
    {
      "tokens": [
        "Aprender",
        "a",
        "realizar",
        "Aquisição",
        "de",
        "usuários"
      ],
      "labels": [
        "GENERIC_ACTION",
        "NONE",
        "ACTION",
        "TOPIC",
        "NONE",
        "NONE"
      ]
    }, ...