我遇到了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" } ]
是否解决?
我遇到了用于创建文本的MLTextClassifier类的问题。下面是代码段:import CreateML import Foundation let objURL = URL(fileURLWithPath:“ / Users / ...
<。两者的价值互换并且行之有效。 下面是代码段:
// 3. Create the model
if let objNewsClassifier = try? MLTextClassifier(trainingData: training, textColumn: "category", labelColumn: "title") {
. . .
}