linyuefeng123 / semi-supervised-1

使用keras框架Embedding+LSTM对短文本分类-半监督

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

第一步: 重要文件位置结构 ./data/20_newsgroupsori/...(20类文本语料数据) /glove.6B.50d.txt /newsblogbbs.vec ./main.py # 主函数 ./config.py # 参数配置文件 ./utils.py # 常用函数文件 ./modules.py # 模型存放文件

第二步: 设置配置文件中的各项参数,GPU显存小可以修改config.batch_size 修改main.py中的CUDA_VISIBLE_DEVICES值为服务器GPU的id值,一块GPU时该值设置为“0”

第三步: 执行 main.py

注意事项: 1、 样本集分为: 训练集和验证集 将训练集中的数据按unSupervisedSize的比率划分出一部分给半监督自学习使用。 半监督比例在config.py文件中设置

2、 文件modules.py文件中的RcnnModel1训练速度很慢 约1000s一个epoch 而RcnnModel2的速度较快约30s一个epoch 所以测试阶段是在RcnnModel2进行,若要测试RcnnModel1,可想而知时间会很久

3、 使用RcnnModel1时修改文件config.py中的 config.input_length = 800 使用RcnnModel2时修改文件config.py中的 config.input_length = 1000

4、semi_batch 这个参数是自学习的阈值 整个unlabel集合为U

第k轮自学习后剩余unlabel集合Size为: U_k = { size(U) - (k-1)*(1.0/semi_batch)*size(U) } 第k轮后将从 U_k 集合中添加置信度最高的 (1.0/ semi_batch) * size(U) 个unlabel样本加入到训练集作为第k+1轮自学习的训练集。

结论: 有监督学习 训练集15991个样本,验证集3997个样本

accuracy score: 0.754065549162 classification report: precision recall f1-score support

      0       0.66      0.57      0.61       185
      1       0.63      0.78      0.70       176
      2       0.73      0.75      0.74       189
      3       0.57      0.64      0.60       202
      4       0.73      0.74      0.73       207
      5       0.85      0.71      0.77       197
      6       0.69      0.75      0.72       224
      7       0.80      0.82      0.81       209
      8       0.81      0.84      0.82       209
      9       0.82      0.92      0.87       210
     10       0.96      0.94      0.95       187
     11       0.90      0.85      0.87       220
     12       0.79      0.58      0.67       208
     13       0.94      0.86      0.90       197
     14       0.87      0.83      0.85       201
     15       0.91      0.86      0.88       180
     16       0.80      0.63      0.71       206
     17       0.92      0.85      0.88       213
     18       0.56      0.65      0.60       208
     19       0.36      0.49      0.41       169

avg / total 0.77 0.75 0.76 3997

半监督学习 config.VALIDATION_SPLIT = 0.2 # 整个 样本集 划分给验证集的大小 config.unSupervisedRatio = 0.4 # 整个从样本集划分出来的 训练集 划分给半监督集的比率 config.semi_batch = 6 # 将所有半监督中使用的unlabel样本分semi_batch个批依次加入模型训练,值越大越慢

Train on 9605 samples, validate on 3997 samples #################### vali data set report #################### accuracy score: 0.713284963723 classification report: precision recall f1-score support

      0       0.67      0.44      0.53       204
      1       0.65      0.57      0.61       213
      2       0.81      0.55      0.66       228
      3       0.56      0.58      0.57       179
      4       0.62      0.58      0.60       195
      5       0.77      0.75      0.76       193
      6       0.72      0.74      0.73       195
      7       0.79      0.76      0.78       219
      8       0.83      0.80      0.81       203
      9       0.85      0.87      0.86       216
     10       0.88      0.91      0.89       209
     11       0.74      0.78      0.76       193
     12       0.63      0.71      0.67       206
     13       0.84      0.89      0.86       202
     14       0.74      0.89      0.81       182
     15       0.83      0.79      0.81       202
     16       0.77      0.71      0.74       207
     17       0.81      0.85      0.83       190
     18       0.47      0.65      0.55       178
     19       0.35      0.42      0.38       183

avg / total 0.72 0.71 0.71 3997 #################### semiSupervised data set 0 report #################### accuracy score: 0.719386157219 classification report: precision recall f1-score support

      0       0.66      0.42      0.52       318
      1       0.70      0.68      0.69       314
      2       0.79      0.61      0.68       308
      3       0.63      0.58      0.60       328
      4       0.66      0.61      0.63       321
      5       0.82      0.75      0.78       322
      6       0.75      0.74      0.75       321
      7       0.76      0.81      0.79       312
      8       0.90      0.81      0.85       318
      9       0.85      0.86      0.85       313
     10       0.85      0.90      0.87       314
     11       0.79      0.77      0.78       322
     12       0.61      0.68      0.64       317
     13       0.81      0.88      0.85       319
     14       0.77      0.83      0.80       326
     15       0.82      0.82      0.82       318
     16       0.70      0.65      0.67       317
     17       0.83      0.84      0.83       324
     18       0.49      0.66      0.56       328
     19       0.39      0.48      0.43       326

avg / total 0.73 0.72 0.72 6386 unlabel samples remains 5109.

Train on 10882 samples, validate on 3997 samples #################### vali data set report #################### accuracy score: 0.733550162622 classification report: precision recall f1-score support

      0       0.67      0.58      0.62       204
      1       0.59      0.62      0.60       213
      2       0.76      0.61      0.67       228
      3       0.60      0.68      0.64       179
      4       0.57      0.73      0.64       195
      5       0.84      0.69      0.76       193
      6       0.77      0.73      0.75       195
      7       0.74      0.81      0.77       219
      8       0.80      0.78      0.79       203
      9       0.92      0.81      0.86       216
     10       0.87      0.93      0.90       209
     11       0.93      0.78      0.85       193
     12       0.67      0.73      0.70       206
     13       0.86      0.85      0.86       202
     14       0.79      0.88      0.83       182
     15       0.87      0.77      0.82       202
     16       0.73      0.81      0.77       207
     17       0.84      0.89      0.86       190
     18       0.66      0.52      0.58       178
     19       0.35      0.43      0.39       183

avg / total 0.74 0.73 0.74 3997 #################### semiSupervised data set 1 report #################### accuracy score: 0.664905069485 classification report: precision recall f1-score support

      0       0.61      0.55      0.58       317
      1       0.63      0.73      0.68       293
      2       0.76      0.59      0.67       282
      3       0.60      0.64      0.62       320
      4       0.57      0.70      0.62       299
      5       0.81      0.67      0.73       271
      6       0.71      0.64      0.68       249
      7       0.67      0.78      0.72       224
      8       0.76      0.74      0.75       226
      9       0.84      0.72      0.77       195
     10       0.73      0.82      0.77       162
     11       0.89      0.72      0.80       233
     12       0.62      0.61      0.61       280
     13       0.76      0.79      0.77       195
     14       0.70      0.71      0.71       182
     15       0.76      0.71      0.73       202
     16       0.62      0.75      0.68       308
     17       0.79      0.80      0.79       237
     18       0.56      0.40      0.47       309
     19       0.41      0.50      0.45       325

avg / total 0.67 0.66 0.67 5109 unlabel samples remains 3832.

Train on 12159 samples, validate on 3997 samples #################### vali data set report #################### accuracy score: 0.733049787341 classification report: precision recall f1-score support

      0       0.67      0.59      0.63       204
      1       0.68      0.59      0.63       213
      2       0.80      0.57      0.67       228
      3       0.53      0.63      0.58       179
      4       0.65      0.66      0.65       195
      5       0.75      0.78      0.76       193
      6       0.71      0.73      0.72       195
      7       0.79      0.77      0.78       219
      8       0.80      0.80      0.80       203
      9       0.95      0.86      0.91       216
     10       0.95      0.89      0.92       209
     11       0.87      0.84      0.85       193
     12       0.65      0.78      0.71       206
     13       0.91      0.87      0.89       202
     14       0.67      0.90      0.77       182
     15       0.85      0.72      0.78       202
     16       0.77      0.78      0.78       207
     17       0.86      0.84      0.85       190
     18       0.60      0.60      0.60       178
     19       0.33      0.43      0.38       183

avg / total 0.75 0.73 0.74 3997 #################### semiSupervised data set 2 report #################### accuracy score: 0.553235908142 classification report: precision recall f1-score support

      0       0.53      0.45      0.49       261
      1       0.56      0.52      0.54       217
      2       0.66      0.50      0.57       225
      3       0.52      0.57      0.54       251
      4       0.61      0.59      0.60       247
      5       0.69      0.69      0.69       225
      6       0.46      0.43      0.45       168
      7       0.53      0.57      0.55       141
      8       0.67      0.60      0.63       147
      9       0.81      0.68      0.74       130
     10       0.75      0.58      0.65        83
     11       0.65      0.64      0.64       165
     12       0.45      0.56      0.49       216
     13       0.72      0.65      0.68       124
     14       0.41      0.62      0.49       124
     15       0.58      0.55      0.57       146
     16       0.52      0.58      0.55       212
     17       0.67      0.58      0.62       139
     18       0.51      0.48      0.50       297
     19       0.38      0.46      0.42       314

avg / total 0.57 0.55 0.56 3832 unlabel samples remains 2555.

#################### vali data set report #################### accuracy score: 0.716287215412 classification report: precision recall f1-score support

      0       0.69      0.48      0.56       204
      1       0.72      0.46      0.56       213
      2       0.71      0.53      0.61       228
      3       0.58      0.58      0.58       179
      4       0.50      0.81      0.61       195
      5       0.68      0.77      0.72       193
      6       0.76      0.78      0.77       195
      7       0.79      0.79      0.79       219
      8       0.79      0.80      0.79       203
      9       0.95      0.75      0.84       216
     10       0.86      0.93      0.89       209
     11       0.92      0.77      0.84       193
     12       0.67      0.73      0.70       206
     13       0.75      0.90      0.82       202
     14       0.85      0.86      0.86       182
     15       0.77      0.82      0.80       202
     16       0.76      0.78      0.77       207
     17       0.81      0.88      0.84       190
     18       0.62      0.48      0.54       178
     19       0.34      0.44      0.38       183

avg / total 0.73 0.72 0.72 3997 #################### semiSupervised data set 3 report #################### accuracy score: 0.368688845401 classification report: precision recall f1-score support

      0       0.41      0.24      0.30       203
      1       0.45      0.34      0.39       156
      2       0.44      0.27      0.34       161
      3       0.29      0.24      0.26       163
      4       0.33      0.59      0.42       167
      5       0.45      0.55      0.50       119
      6       0.37      0.33      0.35       120
      7       0.34      0.37      0.35        84
      8       0.45      0.44      0.44        84
      9       0.64      0.30      0.41        70
     10       0.55      0.60      0.57        57
     11       0.49      0.23      0.31        87
     12       0.30      0.32      0.31       136
     13       0.29      0.60      0.39        75
     14       0.33      0.30      0.31        71
     15       0.40      0.56      0.47        97
     16       0.35      0.40      0.38       144
     17       0.39      0.46      0.42        84
     18       0.38      0.25      0.30       221
     19       0.30      0.37      0.33       256

avg / total 0.38 0.37 0.36 2555 unlabel samples remains 1278.

Train on 14713 samples, validate on 3997 samples #################### vali data set report #################### accuracy score: 0.746810107581 classification report: precision recall f1-score support

      0       0.63      0.63      0.63       204
      1       0.60      0.66      0.63       213
      2       0.73      0.68      0.70       228
      3       0.62      0.60      0.61       179
      4       0.58      0.71      0.64       195
      5       0.72      0.76      0.74       193
      6       0.71      0.79      0.75       195
      7       0.86      0.70      0.77       219
      8       0.88      0.81      0.84       203
      9       0.92      0.89      0.90       216
     10       0.98      0.90      0.94       209
     11       0.85      0.87      0.86       193
     12       0.71      0.71      0.71       206
     13       0.93      0.90      0.91       202
     14       0.81      0.90      0.85       182
     15       0.80      0.84      0.82       202
     16       0.75      0.80      0.78       207
     17       0.86      0.87      0.87       190
     18       0.60      0.56      0.58       178
     19       0.37      0.32      0.34       183

avg / total 0.75 0.75 0.75 3997 #################### semiSupervised data set 4 report #################### accuracy score: 0.191705790297 classification report: precision recall f1-score support

      0       0.27      0.24      0.25       122
      1       0.29      0.37      0.32        86
      2       0.33      0.25      0.29        95
      3       0.26      0.18      0.21       102
      4       0.04      0.11      0.06        46
      5       0.17      0.28      0.21        40
      6       0.19      0.19      0.19        68
      7       0.14      0.10      0.12        40
      8       0.26      0.26      0.26        34
      9       0.58      0.49      0.53        43
     10       0.14      0.05      0.07        21
     11       0.45      0.43      0.44        54
     12       0.15      0.11      0.12        75
     13       0.03      0.05      0.04        19
     14       0.17      0.19      0.18        42
     15       0.13      0.22      0.16        32
     16       0.16      0.19      0.18        68
     17       0.09      0.09      0.09        35
     18       0.11      0.08      0.09       129
     19       0.04      0.04      0.04       127

avg / total 0.20 0.19 0.19 1278 unlabel samples remains 1.

About

使用keras框架Embedding+LSTM对短文本分类-半监督


Languages

Language:Python 100.0%