iOS 使用 CreateML MLTextClassifier class 的训练模型无法从 JSON 中过滤
iOS Training model with CreateML MLTextClassifier class unable to filter from JSON
我遇到了 MLTextClassifier
class 用于 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
的控制台日志。
尝试了 Whosebug 上发布的所有解决方案,但 none 有效。
注意:我使用的是 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"
}
]
任何修复?
不正确的 textColumn 和 labelColumn 值存在问题。交换了两者的值,它起作用了。
下面是代码片段:
// 3. Create the model
if let objNewsClassifier = try? MLTextClassifier(trainingData: training, textColumn: "category", labelColumn: "title") {
. . .
}
我遇到了 MLTextClassifier
class 用于 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
的控制台日志。
尝试了 Whosebug 上发布的所有解决方案,但 none 有效。
注意:我使用的是 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"
}
]
任何修复?
不正确的 textColumn 和 labelColumn 值存在问题。交换了两者的值,它起作用了。
下面是代码片段:
// 3. Create the model
if let objNewsClassifier = try? MLTextClassifier(trainingData: training, textColumn: "category", labelColumn: "title") {
. . .
}