带有CreateML MLTextClassifier类的iOS培训模型无法从JSON过滤

问题描述 投票:0回答:1

我遇到了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的控制台日志。

Screenshot for console log

尝试过所有已发布在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 / ...

ios swift swift-playground createml mltextclassifier
1个回答
1
投票

<。两者的价值互换并且行之有效。 下面是代码段:

// 3. Create the model if let objNewsClassifier = try? MLTextClassifier(trainingData: training, textColumn: "category", labelColumn: "title") { . . . }

© www.soinside.com 2019 - 2024. All rights reserved.