Errors when running the default model
philfuchs opened this issue · 7 comments
I ran the model with Glove embeddings without any modifications (python trainer)
and I got this error
Traceback (most recent call last):
File "trainer.py", line 237, in <module>
main()
File "trainer.py", line 191, in main
conf = Config(opt)
File "/home/user/pytorch_lstmcrf/src/config/config.py", line 75, in __init__
self.print_detail_f1 = args.print_detail_f1
AttributeError: 'Namespace' object has no attribute 'print_detail_f1'
If I set both lines 75 and 76 to True
then I get this error. Is this behaviour intended with the default dataset included in the repo?
(pt_lstmcrf) ➜ pytorch_lstmcrf git:(master) ✗ python trainer.py
device: cpu
seed: 42
dataset: conll2003_sample
embedding_file: data/glove.6B.100d.txt
embedding_dim: 100
optimizer: sgd
learning_rate: 0.01
l2: 1e-08
lr_decay: 0
batch_size: 10
num_epochs: 100
train_num: -1
dev_num: -1
test_num: -1
max_no_incre: 100
model_folder: english_model
hidden_dim: 200
dropout: 0.5
use_char_rnn: 1
static_context_emb: none
add_iobes_constraint: 0
reading the pretraing embedding: data/glove.6B.100d.txt
[Warning] pretrain embedding file not exists, using random embedding
[Data Info] Reading dataset from:
data/conll2003_sample/train.txt
data/conll2003_sample/dev.txt
data/conll2003_sample/test.txt
[Data Info] Reading file: data/conll2003_sample/train.txt, labels will be converted to IOBES encoding
[Data Info] Modify src/data/ner_dataset.read_txt function if you have other requirements
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 470667.64it/s]
number of sentences: 5
[Data Info] Using the training set to build label index
#labels: 11
label 2idx: {'<PAD>': 0, 'S-ORG': 1, 'O': 2, 'S-MISC': 3, 'B-PER': 4, 'E-PER': 5, 'S-LOC': 6, 'B-ORG': 7, 'E-ORG': 8, '<START>': 9, '<STOP>': 10}
[Data Info] Reading file: data/conll2003_sample/dev.txt, labels will be converted to IOBES encoding
[Data Info] Modify src/data/ner_dataset.read_txt function if you have other requirements
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 51/51 [00:00<00:00, 446575.16it/s]
number of sentences: 3
Traceback (most recent call last):
File "trainer.py", line 237, in <module>
main()
File "trainer.py", line 200, in main
label2idx=train_dataset.label2idx, is_train=False)
File "/home/Projekte/pytorch_lstmcrf/src/data/ner_dataset.py", line 43, in __init__
check_all_labels_in_dict(insts=insts, label2idx=self.label2idx)
File "/home/Projekte/pytorch_lstmcrf/src/data/data_utils.py", line 68, in check_all_labels_in_dict
raise ValueError(f"The label {label} does not exist in label2idx dict. The label might not appear in the training set.")
ValueError: The label B-MISC does not exist in label2idx dict. The label might not appear in the training set.
Ubuntu 20.04
For that error, I think your test dataset contain tags that do not exist in the training set, am I right?
It looks like the supplied dev set contains "B-MISC", so that should probably be fixed for the default model to run. I haven't looked at the entire code yet, do you know if there's a way to specify the label set to avoid this?
Usually, I will try to incorporate every tag in the training set. One simple fix is to copy the instances in the dev set to the training set.
Or you can specify the label list yourself, instead of reading the label list from the training set. Let me know if you need more help on this.
Instead of using the provided sample data set I used my own in which all labels do occur in all data sets and now I get a completely different error during training. I formatted the data exactly like the provided data and made nro further changes to the code. Surely I can't be the only one running into these errors. Do you have an idea how to proceed? Thanks for your help.
(pt_lstmcrf) ➜ pytorch_lstmcrf git:(master) ✗ python trainer.py
device: cpu
seed: 42
dataset: conll2003_sample
embedding_file: data/glove.6B.100d.txt
embedding_dim: 100
optimizer: sgd
learning_rate: 0.01
l2: 1e-08
lr_decay: 0
batch_size: 10
num_epochs: 100
train_num: -1
dev_num: -1
test_num: -1
max_no_incre: 100
model_folder: english_model
hidden_dim: 200
dropout: 0.5
use_char_rnn: 1
static_context_emb: none
add_iobes_constraint: 0
reading the pretraing embedding: data/glove.6B.100d.txt
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 400000/400000 [00:13<00:00, 28808.30it/s]
[Data Info] Reading dataset from:
data/conll2003_sample/train.txt
data/conll2003_sample/dev.txt
data/conll2003_sample/test.txt
[Data Info] Reading file: data/conll2003_sample/train.txt, labels will be converted to IOBES encoding
[Data Info] Modify src/data/ner_dataset.read_txt function if you have other requirements
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 119576/119576 [00:00<00:00, 658853.98it/s]
number of sentences: 280
[Data Info] Using the training set to build label index
#labels: 23
label 2idx: {'<PAD>': 0, 'O': 1, 'B-PER': 2, 'E-PER': 3, 'S-LOC': 4, 'S-TITLE': 5, 'S-SKILL': 6, 'B-SKILL': 7, 'E-SKILL': 8, 'B-ORG': 9, 'E-ORG': 10, 'B-LOC': 11, 'I-LOC': 12, 'E-LOC': 13, 'B-TITLE': 14, 'E-TITLE': 15, 'I-TITLE': 16, 'I-ORG': 17, 'S-PER': 18, 'S-ORG': 19, 'I-SKILL': 20, '<START>': 21, '<STOP>': 22}
[Data Info] Reading file: data/conll2003_sample/dev.txt, labels will be converted to IOBES encoding
[Data Info] Modify src/data/ner_dataset.read_txt function if you have other requirements
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 34121/34121 [00:00<00:00, 813470.40it/s]
number of sentences: 80
[Data Info] Reading file: data/conll2003_sample/test.txt, labels will be converted to IOBES encoding
[Data Info] Modify src/data/ner_dataset.read_txt function if you have other requirements
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 18712/18712 [00:00<00:00, 805482.69it/s]
number of sentences: 40
Building the embedding table for vocabulary...
[Info] Use the pretrained word embedding to initialize: 29739 x 100
[Data Info] num words: 29739
number of instances: 280
[Model Info] Input size to LSTM: 150
[Model Info] LSTM Hidden Size: 200
Using SGD: lr is: 0.01, L2 regularization is: 1e-08
[Info] The model will be saved to: english_model.tar.gz
[Train Info] Start training, you have set to stop if performace not increase for 100 epochs
Epoch: 0%| | 0/100 [00:00<?, ?it/s]learning rate is set to: 0.01
--training batch: 0%| | 0/28 [00:00<?, ?it/s]
Epoch: 0%| | 0/100 [00:00<?, ?it/s]
Traceback (most recent call last):
File "trainer.py", line 237, in <module>
main()
File "trainer.py", line 233, in main
train_model(conf, conf.num_epochs, train_dataloader, dev_dataloader, test_dataloader)
File "trainer.py", line 106, in train_model
for iter, batch in tqdm(enumerate(train_loader, 1), desc="--training batch", total=len(train_loader)):
File "/home/user/anaconda3/envs/pt_lstmcrf/lib/python3.6/site-packages/tqdm/std.py", line 1185, in __iter__
for obj in iterable:
File "/home/user/anaconda3/envs/pt_lstmcrf/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 521, in __next__
data = self._next_data()
File "/home/user/anaconda3/envs/pt_lstmcrf/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 1203, in _next_data
return self._process_data(data)
File "/home/user/anaconda3/envs/pt_lstmcrf/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 1229, in _process_data
data.reraise()
File "/home/user/anaconda3/envs/pt_lstmcrf/lib/python3.6/site-packages/torch/_utils.py", line 425, in reraise
raise self.exc_type(msg)
ValueError: Caught ValueError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/user/anaconda3/envs/pt_lstmcrf/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/home/user/anaconda3/envs/pt_lstmcrf/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch
return self.collate_fn(data)
File "/home/user/Projekte/pytorch_lstmcrf/src/data/ner_dataset.py", line 118, in collate_fn
curr_max_char_seq_len = max(feature.char_seq_lens)
ValueError: max() arg is an empty sequence
I guess this is more of a PyTorch error, but can you try setting the number of workers to 0.
num_workers=0
https://github.com/allanj/pytorch_lstmcrf/blob/master/trainer.py#L219
If this is still not working, drop me an email and I will look closely into the issues with you.
It was still not working and since I am under time constraints I have set up the same model using FlairNLP in the meantime. Thanks for your help.