IBM Cloud Docs
对文本进行分类

对文本进行分类

定义可对文档中的文本进行分类的类别。

本主题描述如何对文本进行分类。 如果要对文档进行分类,请使用“内容挖掘”应用程序。 更多信息,请参阅 分类器类型

添加文本分类器以将集合中的文档中的文本分配到类别中。Discovery 使用您提供的标签和文本示例来预测集合中文本的类别。

要创建文本分类器,请完成以下步骤:

  1. 创建包含示例文本的 CSV 文件,后跟每行的类别标签。

    CSV 文件必须采用 UTF-8 编码格式,并且必须满足以下要求:

    • 格式必须是 text,labeltext 是示例文本,label 是类别名称。

      添加完整的句子作为文本条目。 请勿在 CSV 文件中包含任何空白行。

      如果您需要在 text 列中的句子应用多个标签,可以添加更多 label 列。 例如,text,label,label

    • 文件必须至少有两列,且没有标题。

    • 为要定义的每个类别添加 10 个或多个条目。 每个类别所需的最小条目数为 3。 为每个类别提供的示例越多,分类器越能预测集合中其他内容的类别。

    以下示例是一个 CSV 文件,用于定义名为 facility_temperaturecatering 的两个类别。 示例文本由来自会议出席者的反馈组成。

    The rooms were too cold.,facility_temperature
    Breakfast did not include gluten-free options.,catering
    The rooms were too warm.,facility_temperature
    I was very comfortable in the session rooms.,facility_temperature
    The awards dinner was delicious.,catering
    Coffee ran out during one of the breaks.,catering
    The temperature was not comfortable.,facility_temperature
    I was very happy with the selection at lunch.,catering
    It was nice that you provided tea and coffee. Tea drinkers are often ignored.,catering
    Can you turn up the air conditioning? I was very warm.,facility_temperature
    My teeth were chattering because I was so cold.,facility_temperature
    The speaker left the room to find someone to adjust the temperature.,facility_temperature
    Would you consider an all-vegan menu next year?,catering
    I would like lemonade and iced tea to be served during the breaks.,catering
    The lunch staff was excellent.,catering
    Appreciated the fresh blueberry muffins at breakfast.,catering
    The hotel staff adjusted the temperature in my session room as soon as I asked. Excellent service!,facility_temperature
    Every meal was delicious and there was something for everyone.,catering
    The seats under the skylights were not comfortable. Too hot.,facility_temperature
    I was comfortable everywhere in the conference center. I never needed my emergency sweater.,facility_temperature
    
  2. 从“改进工具”面板的 Teach 域概念 部分,然后单击 文本分类器

  3. 单击上传

  4. 指定分类器的名称,然后选择 CSV 文件中使用的语言。

  5. 单击 上载 以浏览先前创建的 CSV 文件。

  6. 单击创建

    将根据您提供的训练数据创建分类器扩充项。

  7. 选择要在其中应用文本分类器扩充项的集合和字段,然后单击 应用

以下示例显示了使用样本 CSV 文件作为其训练数据创建的扩充项如何对文档中的文本进行分类。 在输出中,分类器扩充项将 facility_temperature 标签应用于文档文本。 label 存储在 enriched_{field_name} 数组中的 classes 数组内。

{
  "enriched_text": [
    {
      "classes": [
        {
          "confidence": 0.999692440032959,
          "label": "facility_temperature"
        }
      ]
    }
  ],
  "text": [
    "I think more attendees would stay awake in the sessions if the rooms were colder."
  ]
}

分类器类型

从 Discovery 用户界面添加的分类器是 文本分类器。 文本分类器可以根据从正文文本中抽取的词和短语及其考虑的部分语音信息对文档进行分类。

只能从已部署的“内容挖掘”应用程序创建另一个分类器类型 文档分类器。 文档分类器可以根据从正文文本字段中抽取的词和短语对文档进行分类,这些词和短语包含来自其词性的信息以及应用于所考虑的正文文本的其他扩充项。 还会使用来自其他非主体字段的信息。

您可以将文档分类器应用于非内容挖掘项目的项目类型中的集合。 要执行此操作,必须在已部署的“内容挖掘”应用程序中创建分类器并将其导出。 然后,您可以导入分类器,并将其作为扩充项应用于集合。 有关更多信息,请参阅 创建和应用文档分类器

文本分类器使用“部分语音”信息,而不考虑是否将“部分语音”扩充项应用于项目。

添加到一个项目的文本分类器可以由其他项目 (包括内容挖掘项目) 使用。

文本分类器不会对置信度分数低于 0.5的目标文本字段进行分类。 无法更改文本分类器所使用的置信度阈值。 如果您希望将某些类型的段落分类为未分类的段落,那么可以将具有类似特征的段落添加到训练数据中,并训练另一个分类器。

文本分类器限制

每个服务实例可以创建的文本分类器和标签数取决于 Discovery 套餐类型。

文本分类器计划限制
限制 企业 Premium Cloud Pak for Data
每个服务实例的文本分类器数 5 20 20 无限制
标记的数据行数 2,000 20,000 20,000 20,000
扩充后训练数据的最大大小 (MB) 16 1,024 1,024 1,024
标签数 100 1,000 小时 1,000 小时 1,000 小时