Train parser without PoS tags?
There is no mention of PoS tags in the train_parser.py script - does the parser really work without PoS tags, or is it just something missing? Parsing without PoS tags seems highly unlikely, as all syntactic parsers require tagged input data as far as I know. I'm having trouble imaging that spaCy can reach close to state-of-the-art parsing accuracies without knowing PoS tags, as these are very useful and informative for the syntactic parsing (and a range of other downstream applications).
Any updates on this?
I'm wondering about this too. I didn't think it was possible to predict dependencies with any degree of accuracy without PoS tags?
Any updates?
I've just pushed a new version of the bin/parser/train_ud.py script. Accuracy log on Italian:
Iter UAS POS
0: 64.251 90.546
1: 73.789 94.812
2: 74.164 95.021
3: 76.068 95.294
4: 75.169 94.351
5: 77.237 94.980
6: 74.661 93.386
7: 77.125 95.996
8: 78.582 95.378
9: 80.151 96.007
10: 78.150 95.430
11: 80.166 96.007
12: 81.062 95.996
13: 80.666 95.535
14: 80.390 95.933
UAS LAS POS
Final: 84.881 81.538 96.845
Accuracy can be improved a lot by providing Brown clusters, trained on a good sample of unannotated data.
Trying to run train_ud.pyon the Norwegian UD data set, I get the following error:
(spacy) spacy_nor > python3 train_ud.py no-ud-train.conllu no-ud-dev.conllu models ud_tag_map.json
['PRON', 'VERB', 'ADP', 'PROPN', 'PROPN', 'PUNCT']
Traceback (most recent call last):
File "train_ud.py", line 103, in <module>
plac.call(main)
File "/Users/petterhohle/.pyenv/versions/spacy/lib/python3.5/site-packages/plac_core.py", line 328, in call
cmd, result = parser.consume(arglist)
File "/Users/petterhohle/.pyenv/versions/spacy/lib/python3.5/site-packages/plac_core.py", line 207, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "train_ud.py", line 92, in main
tagger.update(doc, gold)
File "spacy/tagger.pyx", line 253, in spacy.tagger.Tagger.update (spacy/tagger.cpp:6803)
File "spacy/morphology.pyx", line 41, in spacy.morphology.Morphology.assign_tag (spacy/morphology.cpp:3943)
KeyError: 0
The error occurs at tag_id = self.reverse_index[tag], so I'm guessing that the tag is not in the dictionary, for some reason.
Are you running on the current version of master?
I was not! I pulled from master, and now it's working like a charm and giving me some great results - thanks a bunch!
Alas, that is only until model.end_training() is called. See below.
(spacy) spacy_nor > python3 spacy/bin/parser/train_ud.py no-ud-train.conllu no-ud-dev.conllu models/ ud_tag_map.json
['PRON', 'VERB', 'ADP', 'PROPN', 'PROPN', 'PUNCT']
0: 71.170 92.168
1: 75.913 92.870
2: 78.578 94.601
3: 76.076 94.000
4: 81.362 95.157
5: 82.539 95.761
6: 82.567 95.470
7: 82.971 95.799
8: 82.593 95.676
9: 83.834 96.054
10: 84.217 95.840
11: 84.413 96.202
12: 84.058 96.172
13: 84.613 96.235
14: 84.385 96.142
Traceback (most recent call last):
File "spacy/bin/parser/train_ud.py", line 103, in <module>
plac.call(main)
File "/Users/petterhohle/.pyenv/versions/spacy/lib/python3.5/site-packages/plac_core.py", line 326, in call
cmd, result = parser_from(obj).consume(arglist)
File "/Users/petterhohle/.pyenv/versions/spacy/lib/python3.5/site-packages/plac_core.py", line 209, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "spacy/bin/parser/train_ud.py", line 97, in main
nlp.end_training(model_dir)
File "/Users/petterhohle/coding/spacy_nor/spaCy/spacy/language.py", line 361, in end_training
self.tagger.model.dump(str(path / 'pos' / 'model'))
File "thinc/linear/avgtron.pyx", line 75, in thinc.linear.avgtron.AveragedPerceptron.dump (thinc/linear/avgtron.cpp:2754)
File "thinc/linear/serialize.pyx", line 23, in thinc.linear.serialize.Writer.__init__ (thinc/linear/serialize.cpp:1521)
AssertionError
FYI, models is simply an empty directory, as I'm guessing it's meant for storing the created models?
You'll need pos, vocab and deps directories within the model directory
Getting there, ever so closely
(spacy) spacy_nor > python3 spacy/bin/parser/train_ud.py no-ud-train.conllu no-ud-dev.conllu models/ ud_tag_map.json
['PRON', 'VERB', 'ADP', 'PROPN', 'PROPN', 'PUNCT']
0: 71.170 92.168
1: 75.011 92.629
2: 77.784 93.964
3: 80.723 95.127
4: 81.167 94.348
5: 80.200 95.506
6: 82.492 95.643
7: 83.918 95.900
8: 82.332 96.197
9: 82.463 95.574
10: 83.026 95.925
11: 84.081 95.867
12: 82.835 95.407
13: 84.412 95.634
14: 84.286 96.117
Traceback (most recent call last):
File "spacy/bin/parser/train_ud.py", line 103, in <module>
plac.call(main)
File "/Users/petterhohle/.pyenv/versions/spacy/lib/python3.5/site-packages/plac_core.py", line 326, in call
cmd, result = parser_from(obj).consume(arglist)
File "/Users/petterhohle/.pyenv/versions/spacy/lib/python3.5/site-packages/plac_core.py", line 209, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "spacy/bin/parser/train_ud.py", line 97, in main
nlp.end_training(model_dir)
File "/Users/petterhohle/coding/spacy_nor/spaCy/spacy/language.py", line 397, in end_training
(HEAD, head_freqs)
TypeError: a bytes-like object is required, not 'str'
Edit: Dirty (and very temporary) quick fix by simply skipping the serialization in the final step. The results out-of-the-box are very promising. On dev: 87.57% UAS, 84.12% LAS, 96.96% tagger accuracy On test: 86.68% UAS, 83.34% LAS, 96.42% tagger accuracy
Cool, glad it's working. You're still averaging the model, right?
The Brown cluster training program is here: https://github.com/percyliang/brown-cluster
You can probably get by with just training 50 or 100 clusters to start with, to get something up and running. You should experiment with more clusters to see if they help.
It is working, but not optimally. I do want to be able to output the serialization - do you know why I get the TypeError: a bytes-like object is required, not 'str' error?
I'm not doing anything in particular to average the model, but I didn't make any changes in the train_ud.py script; do I need to make any changes to average the model?
I'll look into Brown clusters, thanks!
Hm, try doing pip3 install ujson. ujson expects to write binary strings, while the normal json library expects to write unicode.
Already got ujson installed and it's imported successfully.
Think I found the error, and another. Sec.
Try pulling and recompiling now.
Still getting the same error, unfortunately.
Edit: I may have jumped the gun here, sec
The error moved!
(spacy) spacy_nor > python spacy/bin/parser/train_ud.py no-ud-train.conllu no-ud-test.conllu models/ ud_tag_map.json
Traceback (most recent call last):
File "spacy/bin/parser/train_ud.py", line 111, in <module>
plac.call(main)
File "/Users/petterhohle/.pyenv/versions/spacy/lib/python3.5/site-packages/plac_core.py", line 326, in call
cmd, result = parser_from(obj).consume(arglist)
File "/Users/petterhohle/.pyenv/versions/spacy/lib/python3.5/site-packages/plac_core.py", line 209, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "spacy/bin/parser/train_ud.py", line 75, in main
json.dump({'pseudoprojective': True, 'labels': actions, 'features': features}, file_)
File "/Users/petterhohle/.pyenv/versions/3.5.2/lib/python3.5/json/__init__.py", line 179, in dump
fp.write(chunk)
TypeError: a bytes-like object is required, not 'str'
Okay, should be fixed now. I also made sure the parser deprojectivises before evaluation. Are there many non-projective sentences in the treebank?
And fixed it is! Thanks a lot, you've been a huge help - even on a friday night!
I have to admit I'm not really sure about how many non-projective sentences there is, but there are probably more than a few.
You asked about averaging the model earlier - any specific steps I must take here, or is it already done?
It's done as part of the end_training() method. I was just worried you'd commented that out.
The number of non-projective sentences will depend on the treebank annotation conventions more than anything. Either way, the pseudo-projective trick works pretty well.
Btw, how morphologically rich is Norwegian? Do you need to lemmatize to parse well?