cnn text classification pytorch
1.0.0
這是Kim在Pytorch中用於句子分類論文的捲積神經網絡的實施。
我只是嘗試了兩個數據集,MR和SST。
| 數據集 | 班級大小 | 最好的結果 | 金的論文結果 |
|---|---|---|---|
| 先生 | 2 | 77.5%(CNN-Rand靜態) | 76.1%(CNN-Rand-Nostatic) |
| SST | 5 | 37.2%(CNN-Rand靜態) | 45.0%(CNN-Rand-Nostatic) |
我沒有認真對待SST的超參數。
./main.py -h
或者
python3 main.py -h
您會得到:
CNN text classificer
optional arguments:
-h, --help show this help message and exit
-batch-size N batch size for training [default: 50]
-lr LR initial learning rate [default: 0.01]
-epochs N number of epochs for train [default: 10]
-dropout the probability for dropout [default: 0.5]
-max_norm MAX_NORM l2 constraint of parameters
-cpu disable the gpu
-device DEVICE device to use for iterate data
-embed-dim EMBED_DIM
-static fix the embedding
-kernel-sizes KERNEL_SIZES
Comma-separated kernel size to use for convolution
-kernel-num KERNEL_NUM
number of each kind of kernel
-class-num CLASS_NUM number of class
-shuffle shuffle the data every epoch
-num-workers NUM_WORKERS
how many subprocesses to use for data loading
[default: 0]
-log-interval LOG_INTERVAL
how many batches to wait before logging training
status
-test-interval TEST_INTERVAL
how many epochs to wait before testing
-save-interval SAVE_INTERVAL
how many epochs to wait before saving
-predict PREDICT predict the sentence given
-snapshot SNAPSHOT filename of model snapshot [default: None]
-save-dir SAVE_DIR where to save the checkpoint
./main.py
您會得到:
Batch[100] - loss: 0.655424 acc: 59.3750%
Evaluation - loss: 0.672396 acc: 57.6923%(615/1066)
如果您的測試集構造了,則進行測試:
/main.py -test -snapshot="./snapshot/2017-02-11_15-50-53/snapshot_steps1500.pt
快照選項表示您的模型加載位置。如果您不分配它,則該模型將從從頭開始。
示例1
./main.py -predict="Hello my dear , I love you so much ."
-snapshot="./snapshot/2017-02-11_15-50-53/snapshot_steps1500.pt"
您會得到:
Loading model from [./snapshot/2017-02-11_15-50-53/snapshot_steps1500.pt]...
[Text] Hello my dear , I love you so much .
[Label] positive
示例2
./main.py -predict="You just make me so sad and I have to leave you ."
-snapshot="./snapshot/2017-02-11_15-50-53/snapshot_steps1500.pt"
您會得到:
Loading model from [./snapshot/2017-02-11_15-50-53/snapshot_steps1500.pt]...
[Text] You just make me so sad and I have to leave you .
[Label] negative
您的文本必須用空間,甚至標點符號分隔。並且,您的文本應更長的時間更長的最大內核大小。