我在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"
}
]有什么解决办法吗?
发布于 2020-05-07 07:00:48
不正确的textColumn和labelColumn值有一个问题。交换了两者的值,它起作用了。
下面是代码片段:
// 3. Create the model
if let objNewsClassifier = try? MLTextClassifier(trainingData: training, textColumn: "category", labelColumn: "title") {
. . .
}https://stackoverflow.com/questions/61634978
复制相似问题