jiesutd / NCRFpp

NCRF++, a Neural Sequence Labeling Toolkit. Easy use to any sequence labeling tasks (e.g. NER, POS, Segmentation). It includes character LSTM/CNN, word LSTM/CNN and softmax/CRF components.
Apache License 2.0
1.88k stars 447 forks source link

ZeroDivisionError: float division by zero #158

Closed myeghaneh closed 3 years ago

myeghaneh commented 3 years ago

I faced this error!

(base) C:\DOPO\ArgMin\NCRFpp-master>python main.py --config demo.train.config
C:\Users\moha\anaconda3\lib\site-packages\torch\cuda\__init__.py:52: UserWarning: CUDA initialization: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx (Triggered internally at  ..\c10\cuda\CUDAFunctions.cpp:100.)
  return torch._C._cuda_getDeviceCount() > 0
Seed num: 42
MODEL: train
Load pretrained word embedding, norm: False, dir: sample_data/sample.word.emb
Embedding:
     pretrain word:15093, prefect match:2917, case_match:418, oov:3922, oov%:0.5403692477266464
Training model...
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DATA SUMMARY START:
 I/O:
     Start   Sequence   Laebling   task...
     Tag          scheme: BIO
     Split         token:  |||
     MAX SENTENCE LENGTH: 250
     MAX   WORD   LENGTH: -1
     Number   normalized: True
     Word  alphabet size: 7258
     Char  alphabet size: 75
     Label alphabet size: 7
     Word embedding  dir: sample_data/sample.word.emb
     Char embedding  dir: None
     Word embedding size: 50
     Char embedding size: 30
     Norm   word     emb: False
     Norm   char     emb: False
     Train  file directory: sample_data/train03.bmes
     Dev    file directory: sample_data/dev03.bmes
     Test   file directory: sample_data/test03.bmes
     Raw    file directory: None
     Dset   file directory: None
     Model  file directory: sample_data/lstmcrf
     Loadmodel   directory: None
     Decode file directory: None
     Train instance number: 1500
     Dev   instance number: 87
     Test  instance number: 0
     Raw   instance number: 0
     FEATURE num: 0
 ++++++++++++++++++++++++++++++++++++++++
 Model Network:
     Model        use_crf: True
     Model word extractor: LSTM
     Model       use_char: True
     Model char extractor: CNN
     Model char_hidden_dim: 50
 ++++++++++++++++++++++++++++++++++++++++
 Training:
     Optimizer: SGD
     Iteration: 1
     BatchSize: 10
     Average  batch   loss: False
 ++++++++++++++++++++++++++++++++++++++++
 Hyperparameters:
     Hyper              lr: 0.015
     Hyper        lr_decay: 0.05
     Hyper         HP_clip: None
     Hyper        momentum: 0.0
     Hyper              l2: 1e-08
     Hyper      hidden_dim: 200
     Hyper         dropout: 0.5
     Hyper      lstm_layer: 1
     Hyper          bilstm: True
     Hyper             GPU: False
DATA SUMMARY END.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
build sequence labeling network...
use_char:  True
char feature extractor:  CNN
word feature extractor:  LSTM
use crf:  True
build word sequence feature extractor: LSTM...
build word representation...
build char sequence feature extractor: CNN ...
build CRF...
Epoch: 0/1
 Learning rate is set as: 0.015
Shuffle: first input word list: [311, 312, 29, 64, 219, 66, 15, 1251, 50, 141, 1688, 1026, 24]
     Instance: 500; Time: 16.98s; loss: 1044852.7943; acc: 9866/32479=0.3038
     Instance: 1000; Time: 19.71s; loss: 847537.4570; acc: 21936/67374=0.3256
     Instance: 1500; Time: 18.29s; loss: 841230.6245; acc: 32938/100779=0.3268
     Instance: 1500; Time: 0.40s; loss: 0.0000; acc: 32938/100779=0.3268
Epoch: 0 training finished. Time: 55.38s, speed: 27.09st/s,  total loss: 2733620.875793457
totalloss: 2733620.875793457
Right token =  1864  All token =  5209  acc =  0.3578421961988865
Dev: time: 0.74s, speed: 118.85st/s; acc: 0.3578, p: 0.0010, r: 0.0052, f: 0.0016
Exceed previous best f score: -10
Save current best model in file: sample_data/lstmcrf.0.model
Traceback (most recent call last):
  File "main.py", line 554, in <module>
    train(data)
  File "main.py", line 465, in train
    speed, acc, p, r, f, _,_ = evaluate(data, model, "test")
  File "main.py", line 182, in evaluate
    speed = len(instances)/decode_time
ZeroDivisionError: float division by zero

can someone have a clue?

jiesutd commented 3 years ago

Your test dataset size is 0. You need to add the test dataset.

myeghaneh commented 3 years ago

you were right, I made that change! sorry. now it works