How to use spaCy CLI to train NER from scratch?
When I did read here I thought I could easily train NER with a file containing two columns: first the word and the second the NER tag in IOB format or any other ones. But I was wrong. What is the exact format that spacy expects to get when issuing the following:
python -m spacy convert infile out-dir -c ner
or this one:
python -m spacy convert input-file output-dir -c bio
The errors I get:
$ python -m spacy convert ner-training-data Ner-output-dir -c ner
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "MYPYTHON-ENV/lib/python3.5/site-packages/spacy/__main__.py", line 30, in <module>
plac.call(commands[command])
File "MYPYTHON-ENV/lib/python3.5/site-packages/plac_core.py", line 328, in call
cmd, result = parser.consume(arglist)
File "MYPYTHON-ENV/lib/python3.5/site-packages/plac_core.py", line 207, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "MYPYTHON-ENV/lib/python3.5/site-packages/spacy/cli/convert.py", line 46, in convert
n_sents=n_sents, use_morphology=morphology)
File "MYPYTHON-ENV/lib/python3.5/site-packages/spacy/cli/converters/conll_ner2json.py", line 14, in conll_ner2json
docs = read_conll_ner(input_path)
File "MYPYTHON-ENV/lib/python3.5/site-packages/spacy/cli/converters/conll_ner2json.py", line 40, in read_conll_ner
words, tags, chunks, iob_ents = zip(*[line.split() for line in lines])
ValueError: not enough values to unpack (expected 4, got 2)
and this one:
$ python -m spacy convert ner-training-data Ner-output-dir -c iob
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "MYPYTHON-ENV/lib/python3.5/site-packages/spacy/__main__.py", line 30, in <module>
plac.call(commands[command])
File "MYPYTHON-ENV/lib/python3.5/site-packages/plac_core.py", line 328, in call
cmd, result = parser.consume(arglist)
File "MYPYTHON-ENV/lib/python3.5/site-packages/plac_core.py", line 207, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "MYPYTHON-ENV/lib/python3.5/site-packages/spacy/cli/convert.py", line 46, in convert
n_sents=n_sents, use_morphology=morphology)
File "MYPYTHON-ENV/lib/python3.5/site-packages/spacy/cli/converters/iob2json.py", line 15, in iob2json
sentences = read_iob(file_)
File "MYPYTHON-ENV/lib/python3.5/site-packages/spacy/cli/converters/iob2json.py", line 34, in read_iob
words, iob = zip(*tokens)
ValueError: not enough values to unpack (expected 2, got 1)
Your Environment
- Python version: 3.5.2
- spaCy version: 2.0.3
- Platform: Linux-4.11.0-14-generic-x86_64-with-LinuxMint-18.2-sonya
- Models: en, en_default
The exact format is CoNLL-2003 NER as mentioned here. You can find a brief description here. But if you go deeper into the converter code you can notice, that the chunk tags aren't used. Also though the POS tags are present in final .json, they aren't used in training, as I've noticed (proof). So I've written a simple converter to create as first conll, and then use spaCy convert command to get final json (I am not looking for easy ways :smile:)
Thanks a lot, @GreenRiverRUS! After reading your script I realized the expected file format and made a JSON file. Now I'm going to use it to train my NER model.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.