【问题标题】:Predictionio evaluation fails with Text Classification template文本分类模板的 Predictionio 评估失败
【发布时间】:2025-10-03 20:45:01
【问题描述】:

我正在尝试根据 predictionio 上的其他文本字段来预测文本字段。我使用this 指南作为参考。我使用

创建了一个新应用
pio app new MyTextApp

并按照指南使用模板中提供的数据源进行评估。一切都还好,直到评估为止。在评估数据源时,我收到如下粘贴的错误。

[INFO] [CoreWorkflow$] runEvaluation started
[WARN] [Utils] Your hostname, my-ThinkCentre-Edge72 resolves to a  loopback address: 127.0.0.1; using 192.168.65.27 instead (on interface eth0)
[WARN] [Utils] Set SPARK_LOCAL_IP if you need to bind to another address
[INFO] [Remoting] Starting remoting
[INFO] [Remoting] Remoting started; listening on addresses  :[akka.tcp://sparkDriver@192.168.65.27:59649]
[INFO] [CoreWorkflow$] Starting evaluation instance ID: AU29p8j3Fkwdnkfum_ke
[INFO] [Engine$] DataSource: org.template.textclassification.DataSource@faea4da
[INFO] [Engine$] Preparator: org.template.textclassification.Preparator@69f2cb04
[INFO] [Engine$] AlgorithmList: List(org.template.textclassification.NBAlgorithm@45292ec1)
[INFO] [Engine$] Serving: org.template.textclassification.Serving@1ad9b8d3
Exception in thread "main" java.lang.UnsupportedOperationException: empty.maxBy
at scala.collection.TraversableOnce$class.maxBy(TraversableOnce.scala:223)
at scala.collection.AbstractTraversable.maxBy(Traversable.scala:105)
at org.template.textclassification.PreparedData.<init>(Preparator.scala:152)
at org.template.textclassification.Preparator.prepare(Preparator.scala:38)
at org.template.textclassification.Preparator.prepare(Preparator.scala:34)

我是否必须编辑任何配置文件才能使其工作?我已经成功地对movielens 数据进行了测试。

【问题讨论】:

    标签: evaluation text-classification predictionio


    【解决方案1】:

    因此,当您的数据无法通过 DataSource 类正确读取时,就会出现此特定错误消息。如果您使用不同的文本数据集,请确保您正确反映了对 readEventData 方法中的 eventNames、entityType 和相应属性字段名称的任何更改。

    maxBy 方法用于拉取观察次数最多的类。如果要标记 Map 的类别为空,则表示没有记录任何类,这实际上表明您没有输入任何数据。

    例如,我刚刚使用这个引擎做了一个垃圾邮件检测器。我的电子邮件数据格式为:

    {"entityType": "content", "eventTime": "2015-06-04T00:22:39.064+0000", "entityId": 1, "event": "e-mail", "properties": {"label": "spam", "text": "content"}}

    为了使用该数据的引擎,我在 DataSource 类中进行了以下更改:

    entityType = Some("source"), // specify data entity type eventNames = Some(List("documents")) // specify data event name

    改成

    entityType = Some("content"), // specify data entity type eventNames = Some(List("e-mail")) // specify data event name

    )(sc).map(e => Observation(
      e.properties.get[Double]("label"),
      e.properties.get[String]("text"),
      e.properties.get[String]("category")
    )).cache
    

    更改为:

    )(sc).map(e => {
      val label = e.properties.get[String]("label")
    
    
      Observation(
        if (label == "spam") 1.0 else 0.0,
        e.properties.get[String]("text"),
        label
      )
    }).cache
    

    在此之后,我可以进行构建、培训、部署以及评估。

    【讨论】:

    • 感谢您的信息。我对不同的数据集使用相同的应用程序。我删除了现有应用程序及其数据并创建了新应用程序,然后运行 ​​pio 构建、训练和部署。现在它工作正常。 :)
    • 太棒了,我很高兴回复有所帮助!我刚刚发布了一个新版本的引擎,其中包含一个健全性检查,以确保实际输入了训练数据。PreparedClass 也进行了修改,以便更快地完成文本矢量化处理。
    • 我已经下载了最新的文本分类模板(2.0),最近的更新也出现了同样的问题。评估失败并出现错误java.lang.UnsupportedOperationException: empty.maxBy 并且训练失败并出现io.prediction.data.storage.DataMapException: The field label is required. pio 说火花地址绑定到环回。我必须将其更改为公共IP吗?能否请您解释一下文本矢量化?
    • 嘿,我刚刚回复了你的另一个问题:*.com/questions/30771784/…
    最近更新 更多