Commit Graph

100 Commits

Author SHA1 Message Date
Matthew Honnibal
bede11b67c
Improve label management in parser and NER (#2108)
This patch does a few smallish things that tighten up the training workflow a little, and allow memory use during training to be reduced by letting the GoldCorpus stream data properly.

Previously, the parser and entity recognizer read and saved labels as lists, with extra labels noted separately. Lists were used becaue ordering is very important, to ensure that the label-to-class mapping is stable.

We now manage labels as nested dictionaries, first keyed by the action, and then keyed by the label. Values are frequencies. The trick is, how do we save new labels? We need to make sure we iterate over these in the same order they're added. Otherwise, we'll get different class IDs, and the model's predictions won't make sense.

To allow stable sorting, we map the new labels to negative values. If we have two new labels, they'll be noted as having "frequency" -1 and -2. The next new label will then have "frequency" -3. When we sort by (frequency, label), we then get a stable sort.

Storing frequencies then allows us to make the next nice improvement. Previously we had to iterate over the whole training set, to pre-process it for the deprojectivisation. This led to storing the whole training set in memory. This was most of the required memory during training.

To prevent this, we now store the frequencies as we stream in the data, and deprojectivize as we go. Once we've built the frequencies, we can then apply a frequency cut-off when we decide how many classes to make.

Finally, to allow proper data streaming, we also have to have some way of shuffling the iterator. This is awkward if the training files have multiple documents in them. To solve this, the GoldCorpus class now writes the training data to disk in msgpack files, one per document. We can then shuffle the data by shuffling the paths.

This is a squash merge, as I made a lot of very small commits. Individual commit messages below.

* Simplify label management for TransitionSystem and its subclasses

* Fix serialization for new label handling format in parser

* Simplify and improve GoldCorpus class. Reduce memory use, write to temp dir

* Set actions in transition system

* Require thinc 6.11.1.dev4

* Fix error in parser init

* Add unicode declaration

* Fix unicode declaration

* Update textcat test

* Try to get model training on less memory

* Print json loc for now

* Try rapidjson to reduce memory use

* Remove rapidjson requirement

* Try rapidjson for reduced mem usage

* Handle None heads when projectivising

* Stream json docs

* Fix train script

* Handle projectivity in GoldParse

* Fix projectivity handling

* Add minibatch_by_words util from ud_train

* Minibatch by number of words in spacy.cli.train

* Move minibatch_by_words util to spacy.util

* Fix label handling

* More hacking at label management in parser

* Fix encoding in msgpack serialization in GoldParse

* Adjust batch sizes in parser training

* Fix minibatch_by_words

* Add merge_subtokens function to pipeline.pyx

* Register merge_subtokens factory

* Restore use of msgpack tmp directory

* Use minibatch-by-words in train

* Handle retokenization in scorer

* Change back-off approach for missing labels. Use 'dep' label

* Update NER for new label management

* Set NER tags for over-segmented words

* Fix label alignment in gold

* Fix label back-off for infrequent labels

* Fix int type in labels dict key

* Fix int type in labels dict key

* Update feature definition for 8 feature set

* Update ud-train script for new label stuff

* Fix json streamer

* Print the line number if conll eval fails

* Update children and sentence boundaries after deprojectivisation

* Export set_children_from_heads from doc.pxd

* Render parses during UD training

* Remove print statement

* Require thinc 6.11.1.dev6. Try adding wheel as install_requires

* Set different dev version, to flush pip cache

* Update thinc version

* Update GoldCorpus docs

* Remove print statements

* Fix formatting and links [ci skip]
2018-03-19 02:58:08 +01:00
ines
29106ec740 Add "new" tag to is_currency [ci skip] 2018-02-18 14:16:26 +01:00
ines
ca2fcad5a3 Add v2.1 tag to new arguments [ci skip] 2018-02-18 14:15:18 +01:00
ines
64f97adef1 Document new Matcher.pipe keyword args [ci skip]
See 1cf774bdc1
2018-02-18 14:13:58 +01:00
ines
61052df31f Document is_currency 2018-02-18 13:30:03 +01:00
ines
26bc75134d Fix typo 2018-02-08 11:28:44 +01:00
ines
58eb178667 Update Doc.char_span docs [ci skip] 2018-02-07 01:08:30 +01:00
Mateusz Tatusko
dda0e58c11
Update _pos-tags.jade
really small changes to English tags description, but might help some people while working on projects
1) -PRB- should be -RRB- instead 
2) space gets tagged as _SP, and not SP
2018-01-15 12:01:51 +09:00
ines
bbee48080d Clarify hyperparameters and alias usage in spacy train (resolves #1838) [ci skip] 2018-01-14 14:32:50 +01:00
Matthew Honnibal
a2a06dce24
Merge pull request #1792 from explosion/feature-improve-model-download
💫 Improve model downloading and linking
2018-01-11 20:02:08 +01:00
pbnsilva
4cfd848bc3 Fixes typo in PhraseMatcher API docs 2018-01-11 17:35:59 +01:00
Matthew Honnibal
7ca49c2061
Merge branch 'master' into feature-improve-model-download 2018-01-10 18:21:55 +01:00
ines
ef210c73dd Update cli.download and cli.validate docs 2018-01-03 21:34:03 +01:00
ines
cc9df10e69 Document util.set_lang_class (see #1737) 2018-01-03 20:13:25 +01:00
Ines Montani
874f174ab1
Merge pull request #1790 from nirdesh37/patch-1
Update goldparse.jade
2018-01-03 18:37:07 +00:00
ines
1fa6ba8130 Fix Doc.from_array example to make it work (see #1527) 2018-01-03 16:59:38 +01:00
ines
49635350f0 Add .from_disk() to pipeline component init example (resolves #1728) 2018-01-03 16:50:24 +01:00
nirdesh37
67fdceed6a
Update goldparse.jade 2018-01-03 17:25:21 +05:30
Kristofer Berggren
1cb8c997fb
Fix typo Span -> Token on Token API page
Change Span.vector_norm to Token.vector_norm.
2017-12-17 20:32:19 +08:00
ines
24e80c51b8 Document init-model command 2017-12-07 10:14:37 +01:00
ines
b078e276e6 Document offsets_from_biluo_tags 2017-12-06 13:40:51 +01:00
Mark Dodwell
9d4c185860
Fix link to CLEAR Style dependency labels PDF 2017-12-04 23:28:06 -08:00
ines
e4ee666be5 Fix biluo_tags_from_offsets example and docs 2017-11-26 16:37:32 +01:00
pavillet
ad2935f0c3
Update _spacy.jade
Doc example gives 'object is not subscriptable' error.
Correcting as an attribuet
2017-11-17 00:02:20 +01:00
ines
40c4e8fc09 Remove "optional" from dev_data arg and add more info (see #1578) 2017-11-14 20:26:05 +01:00
KMLDS
d5b20ac3b6
Update span.jade 2017-11-13 19:27:20 -05:00
ines
4c5d2c80d5 Re-add python -m to commands, too brittle :( (see #1536) 2017-11-10 02:30:55 +01:00
ines
33b84f4c39 Change clear_vectors to reset_vectors (resolves #1516) 2017-11-08 18:11:23 +01:00
ines
97a5892347 Document Vectors.resize() and update v2 incompatibilities (resolves #1514) 2017-11-08 17:11:11 +01:00
ines
1768703e1c Update website for v2.0 2017-11-07 14:48:17 +01:00
ines
a4662a31a9 Move model package templates to cli.package and update docs 2017-11-07 12:15:35 +01:00
ines
a09c096d3c Get docs ready for v2.0.0 2017-11-07 12:00:43 +01:00
ines
912c1b1821 Document "simple training style" 2017-11-07 00:23:19 +01:00
ines
8fb48b9b91 Update and document new util functions 2017-11-07 00:22:43 +01:00
ines
972298e0c9 Update Pipe component docs and training API 2017-11-06 14:42:24 +01:00
ines
86d6bd7503 Fix wording 2017-11-05 19:23:50 +01:00
ines
a6ffa942bb Update UD schemes 2017-11-05 18:46:24 +01:00
ines
4810be4b44 Update POS scheme docs and add links for other schemes 2017-11-05 18:16:34 +01:00
ines
15de2bb01d Update and simplify other annotation scheme data 2017-11-05 16:09:48 +01:00
ines
2d59dd374b Use collapsible sections for pos/dep scheme and update
Will ensure better overview as we add more schemes for more languages
2017-11-05 16:09:30 +01:00
ines
2ba4e4fc88 Fix broken links and add check_links shortcut script 2017-11-01 21:11:10 +01:00
ines
12954ab218 Don't document the tensorizer for now 2017-11-01 19:49:04 +01:00
ines
1c7313051f Document Token.is_sent_start 2017-11-01 14:13:22 +01:00
ines
9e429b5a8a Update formatting of deprecation note 2017-11-01 14:13:08 +01:00
ines
0d8f4a534b Update Vectors API docs 2017-11-01 00:56:54 +01:00
ines
33af6ac69a Use even smaller examle size
100 was still too much, so try 20 instead
2017-10-30 19:46:45 +01:00
ines
f02b0af821 Fix path and use smaller example size
500 was too larger and caused laggy rendering
2017-10-30 19:44:35 +01:00
ines
18dde7869a Update training data docs and add vocab JSONL 2017-10-30 19:40:05 +01:00
ines
57534253e6 Move CLI docs to own page 2017-10-30 19:39:26 +01:00
ines
ec657c1ddc Update vocab docs and document Vocab.prune_vectors 2017-10-30 19:35:41 +01:00