我遇到了用于文本的MLTextClassifier
类的问题。CreateML
下面是代码片段:
import CreateML
import Foundation
let objURL = URL(fileURLWithPath: "/Users/jayprakashdubey/Desktop/headlines.json")
// 1. Load data from a JSON file
guard let newsJsonFileContent = try? MLDataTable(contentsOf: objURL) else {
exit(0)
}
// 2. Make a train-test split
let (training, testing) = newsJsonFileContent.randomSplit(by: 0.8, seed: 5)
print("training: \(training.description)")
// 3. Create the model
if let objNewsClassifier = try? MLTextClassifier(trainingData: training, textColumn: "title", labelColumn: "category") {
. . .
} else {
print("Failed while classifying News - MLTextClassifier")
}
如果条件在上面的代码片段中总是失败。
下面是控制台日志playground
。
尝试了在 Stackoverflow 上发布的所有解决方案,但没有一个有效。
注意:我使用的是 Xcode v11.3.1。
下面是 JSON 文件结构:
[
{
"text":"New 13-inch MacBook Pro comes with 6K monitor support, Dolby Atmos playback",
"category":"Technology"
},
. . .
{
"text":"Apple Watch ECG detects signs of coronary ischemia missed by hospital ECG",
"category":"Technology"
}
]
有什么修复吗?