【问题标题】:Convolutional neural network for multi-classes text classification用于多类文本分类的卷积神经网络
【发布时间】:2017-04-12 04:43:40
【问题描述】:

我有一个包含两列的 CSV 文件,'sentence' 是句子的字符串,emoID 是 1-7 整数,如下所示:

sentence           emoID
During the period of falling in love.       1
When I was involved in a traffic accident.  2
 .....                                      ...

我需要将每个句子分类到其对应的 emoID。我看到了一个分类两个类的例子,如下所示:

# Generate labels
positive_labels = [[0, 1] for _ in positive_examples]
negative_labels = [[1, 0] for _ in negative_examples]

现在我有 7 个类而不是两个,如何为每个类生成 7 个标签?我是python的初学者,非常感谢您的帮助!

【问题讨论】:

    标签: python python-3.x conv-neural-network text-classification


    【解决方案1】:

    您可以使用一个包含 7 个条目的数组,对于类 n,条目 1 在数组中的位置 n 处,其余为 0。例如第 3 类:[0,0,1,0,0,0,0] 并且:

    c3_labels = [[0,0,1,0,0,0,0] for _ in c3_examples]
    

    【讨论】:

    • 是的,这就是我的想法。'for _ in c3_examples'是指将 [0,0,1,0,0,0,0] 附加到 c3_examples 中吗?
    • 对不起,我误解了你的问题。 c3_labels = [[0,0,1,0,0,0,0] for _ in c3_examples] 将创建一个包含标签数组 len(c3_labels) 次的数组。因此,如果您有三个 3 类样本,则变量 c3_labels 将包含[[0, 0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0]]。然后,您可以使用此数组并将其作为新的“列”附加到您的示例数据中。
    猜你喜欢
    • 2019-01-30
    • 1970-01-01
    • 2016-10-03
    • 2017-08-11
    • 2020-10-19
    • 2016-10-23
    • 1970-01-01
    • 2021-12-16
    • 2017-03-21
    相关资源
    最近更新 更多