PaPie 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. papie-0.5.0.dist-info/METADATA +375 -0
  2. papie-0.5.0.dist-info/RECORD +50 -0
  3. papie-0.5.0.dist-info/WHEEL +5 -0
  4. papie-0.5.0.dist-info/entry_points.txt +2 -0
  5. papie-0.5.0.dist-info/licenses/LICENSE +21 -0
  6. papie-0.5.0.dist-info/top_level.txt +2 -0
  7. pie/__init__.py +0 -0
  8. pie/constants.py +8 -0
  9. pie/data/__init__.py +5 -0
  10. pie/data/base_reader.py +104 -0
  11. pie/data/conll_reader.py +144 -0
  12. pie/data/dataset.py +927 -0
  13. pie/data/preprocessors/__init__.py +4 -0
  14. pie/data/preprocessors/edit_tree_tuples.py +11 -0
  15. pie/data/preprocessors/edit_trees.py +184 -0
  16. pie/data/preprocessors/greedy_scripts.py +126 -0
  17. pie/data/reader.py +119 -0
  18. pie/data/tabreader.py +160 -0
  19. pie/default_settings.json +183 -0
  20. pie/initialization.py +74 -0
  21. pie/models/__init__.py +8 -0
  22. pie/models/attention.py +182 -0
  23. pie/models/base_model.py +190 -0
  24. pie/models/beam_search.py +122 -0
  25. pie/models/decoder.py +520 -0
  26. pie/models/embedding.py +236 -0
  27. pie/models/encoder.py +69 -0
  28. pie/models/highway.py +39 -0
  29. pie/models/lstm.py +148 -0
  30. pie/models/model.py +631 -0
  31. pie/models/scorer.py +430 -0
  32. pie/optimize.py +150 -0
  33. pie/pretrain_encoder.py +372 -0
  34. pie/scripts/__init__.py +0 -0
  35. pie/scripts/evaluate.py +110 -0
  36. pie/scripts/group.py +129 -0
  37. pie/scripts/inspect_model.py +17 -0
  38. pie/scripts/tag.py +42 -0
  39. pie/scripts/tag_pipe.py +54 -0
  40. pie/scripts/train.py +316 -0
  41. pie/settings.py +156 -0
  42. pie/tagger.py +194 -0
  43. pie/torch_utils.py +313 -0
  44. pie/trainer.py +438 -0
  45. pie/utils.py +279 -0
  46. pie/webapp/__init__.py +138 -0
  47. test/__init__.py +0 -0
  48. test/data/__init__.py +0 -0
  49. test/data/test_data.py +132 -0
  50. test/data/test_tabreader.py +149 -0
@@ -0,0 +1,375 @@
1
+ Metadata-Version: 2.4
2
+ Name: PaPie
3
+ Version: 0.5.0
4
+ Summary: A Framework for Joint Learning of Sequence Labeling Tasks, forked from Pie
5
+ Home-page: https://github.com/lascivaroma/PaPie
6
+ Author: Enrique Manjavacas; Mike Kestemont; Thibault Clerice
7
+ License: MIT
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.6
12
+ Classifier: Programming Language :: Python :: Implementation :: CPython
13
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
14
+ Classifier: Topic :: Text Processing :: Linguistic
15
+ Requires-Python: >=3.6.0
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: numpy
19
+ Requires-Dist: JSON_minify>=0.3.0
20
+ Requires-Dist: tqdm>=4.23.3
21
+ Requires-Dist: termcolor>=1.1.0
22
+ Requires-Dist: terminaltables~=3.1.0
23
+ Requires-Dist: torch~=2.4.0
24
+ Requires-Dist: pyyaml~=6.0
25
+ Requires-Dist: typing
26
+ Requires-Dist: click
27
+ Requires-Dist: pytorch-optimizer~=2.7.0
28
+ Requires-Dist: torchmetrics
29
+ Dynamic: author
30
+ Dynamic: classifier
31
+ Dynamic: description
32
+ Dynamic: description-content-type
33
+ Dynamic: home-page
34
+ Dynamic: license
35
+ Dynamic: license-file
36
+ Dynamic: requires-dist
37
+ Dynamic: requires-python
38
+ Dynamic: summary
39
+
40
+
41
+
42
+ # (Pa)PIE: A Framework for Joint Learning of Sequence Labeling Tasks
43
+
44
+ [![DOI](https://zenodo.org/badge/131014015.svg)](https://zenodo.org/badge/latestdoi/131014015)
45
+
46
+ ![Improving Lemmatization of Non-Standard Languages with Joint Learning (NAACL19 Paper)](https://www.aclweb.org/anthology/N19-1153/)
47
+
48
+ **Warning:** This is a fork from [pie](https://github.com/emanjavacas/pie). It provides some sometime *unstable* improvement over the original software.
49
+
50
+ PIE was primarily conceived to make experimentation on sequence labeling of variation-rich languages easy and user-friendly. PIE has been tested mostly for Lemmatization but other SoTA accuracies from other tasks like POS have been reproduced (cf. Plank et al ). PIE is *highly* configurable both in terms of input preprocessing and model definition, in principle not requiring users to write any code (instead experiments are defined with json files). It is highly modular and therefore easy to extend. It includes transductive lemmatization as an additional sequence labeling task and, finally, it is reasonably fast and memory efficient.
51
+
52
+ Documentation is work in progress and it will improve over the following months. A good place to learn about its functionality is to check `pie/default_settings.json` which explains all input parameters and shows a full example of a config file (minus input data).
53
+
54
+ If you find `pie` useful, please use the following reference:
55
+
56
+ ```
57
+ @inproceedings{manjavacas-etal-2019-improving,
58
+ title = "Improving Lemmatization of Non-Standard Languages with Joint Learning",
59
+ author = "Manjavacas, Enrique and
60
+ K{\'a}d{\'a}r, {\'A}kos and
61
+ Kestemont, Mike",
62
+ booktitle = "Proceedings of the 2019 Conference of the North {A}merican Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers)",
63
+ month = jun,
64
+ year = "2019",
65
+ address = "Minneapolis, Minnesota",
66
+ publisher = "Association for Computational Linguistics",
67
+ url = "https://www.aclweb.org/anthology/N19-1153",
68
+ doi = "10.18653/v1/N19-1153",
69
+ pages = "1493--1503",
70
+ abstract = "Lemmatization of standard languages is concerned with (i) abstracting over morphological differences and (ii) resolving token-lemma ambiguities of inflected words in order to map them to a dictionary headword. In the present paper we aim to improve lemmatization performance on a set of non-standard historical languages in which the difficulty is increased by an additional aspect (iii): spelling variation due to lacking orthographic standards. We approach lemmatization as a string-transduction task with an Encoder-Decoder architecture which we enrich with sentence information using a hierarchical sentence encoder. We show significant improvements over the state-of-the-art by fine-tuning the sentence encodings to jointly optimize a bidirectional language model loss. Crucially, our architecture does not require POS or morphological annotations, which are not always available for historical corpora. Additionally, we also test the proposed model on a set of typologically diverse standard languages showing results on par or better than a model without fine-tuned sentence representations and previous state-of-the-art systems. Finally, to encourage future work on processing of non-standard varieties, we release the dataset of non-standard languages underlying the present study, which is based on openly accessible sources.",
71
+ }
72
+ ```
73
+
74
+ ## 1. Installation
75
+
76
+ PIE is available from pypi: `pip install PaPie`
77
+
78
+ You can also install it from source:
79
+
80
+ ```bash
81
+ git clone https://github.com/lascivaroma/PaPie.git
82
+ cd PaPie
83
+ pip install .
84
+ ```
85
+
86
+
87
+ ### For development
88
+
89
+ If you are planning to develop on top of PIE, the easiest way is to get setup is to download the repository and install the dependencies (see `requirements.txt`). The only step needed to have `pie` available from any place in the file system is to add the path to `pie` to the `PYTHONPATH` environment variable. There are two ways to accomplish this:
90
+
91
+ - From your bash init file (depending on your distro and configuration this could be `.bashrc`, `.bash_profile`, `.profile`, etc...):
92
+
93
+ ```bash
94
+ export PYTHONPATH="$PYTHONPATH:/path/to/pie"
95
+ ```
96
+
97
+ - From your python script, using `sys`:
98
+
99
+ ```python
100
+ import sys
101
+ sys.path.append('/path/to/pie')
102
+ ```
103
+
104
+ ## 2. Training
105
+
106
+ Training models is done with `pie train path/to/config.json` (or script `python pie/scripts/train.py`. All non-nested parameters can be overwritten directly from the command line using environment variables like `PIE_DEVICE=cpu` (for input parameter `device`. Warning: bear in mind that due to the way bash parses environment variables `PIE_...=False` will be parsed into a boolean `True`, which might be counter-intuitive. If you wish to get `False` for a parameter from the command line you can use `PIE_...=""`).
107
+
108
+ ## 3. Evaluation
109
+
110
+ A given model can be evaluated with `pie evaluate` (or `python pie/scripts/evaluate.py`).
111
+
112
+ ## 4. Tagging
113
+
114
+ Given one or several trained models, two scripts are provided in order to tag given input: `pie tag` and `pie tag-pipe` (or `python pie/scripts/tag.py`, `python pie/scripts/tag_pipe.py`), the difference being that the first tags input files and the second can take input from a unix pipe.
115
+
116
+ Common to both scripts is the *model specification* that allows to combine several models, where the output for a particular task is taken from a model that excels at that task.
117
+ For example, given models `good-pos-tagger.tar` and `good-lemma-tagger.tar`, we can define a tagger that uses `good-pos-tagger.tar` for POS-tagging and `good-lemma-tagger.tar` for lemmatization with the following specification: `<good-lemma-tagger.tar,lemma><good-pos-tagger.tar,pos>`.
118
+
119
+ - If your input is in a file `test.txt` (with a sentence per line) you can use:
120
+
121
+ `pie tag "<good-lemma-tagger.tar,lemma><good-pos-tagger.tar,pos>" test.txt`
122
+
123
+ and the output will be written to `test.pie.txt`
124
+
125
+ - If you want to pass input from the command line, you can use:
126
+ ```
127
+ $ echo "el gato duerme encima de la silla" | pie tag-pipe spanish-lemmatizer.rar
128
+
129
+ token lemma
130
+ el el
131
+ gato gato
132
+ duerme dormir
133
+ encima encima
134
+ de de
135
+ la el
136
+ silla silla
137
+ ```
138
+
139
+ ## 5. Model
140
+
141
+ PIE underlying model comprises a set of hierarchical feature extractors from the character-level up to the sentence-level. For each input token a sentence-level feature vector is extracted and used for the prediction of any number of target tasks (e.g. POS-tagging, lemmatization, ...). A visualization of the underlying model using bidirectional RNNs to extract word-level and sentence-level features is shown below.
142
+
143
+ ![PIE](./img/PIE.svg)
144
+
145
+ Prediction is accomplished with decoder modules. We provide implementations of a `linear` decoder trained to maximize the probability assigned by the model to the corpus data via a softmax function (similar to a MaxEnt classifier). A `crf` decoder, particularly suited for tasks that imply a dependency between neighboring output tags and an `attentional` decoder, suited for tasks that can be solved by generating the token-level output character by characters in a string transduction manner (e.g. lemmatization, normalization).
146
+
147
+ ## 6. Configuration files
148
+
149
+ Training a model only requires a model specification and paths to training and dev datasets. Pie user interface employs a simple json file (in order to allow in-line comments, we make use of the package `JSON_minify`), an example of which can be seen below:
150
+
151
+ ```json
152
+ {
153
+ "modelname": "lemmatization-latin",
154
+ "modelpath": "models",
155
+
156
+ "input_path": "datasets/LLCT1/train.tsv",
157
+ "dev_path": "datasets/LLCT1/dev.tsv",
158
+ "sep": "\t",
159
+
160
+ "tasks": [
161
+ {
162
+ "name": "lemma",
163
+ "target": true,
164
+ "context": "sentence",
165
+ "level": "char",
166
+ "decoder": "attentional",
167
+ "settings": {
168
+ "bos": true,
169
+ "eos": true,
170
+ "lower": true,
171
+ "target": "lemma"
172
+ },
173
+ "layer": -1
174
+ }
175
+ ],
176
+ "batch_size": 25,
177
+ "epochs": 100,
178
+
179
+ "dropout": 0.25,
180
+ "optimizer": "Adam",
181
+ "patience": 3,
182
+ "lr": 0.001,
183
+ "lr_factor": 0.75,
184
+ "lr_patience": 2,
185
+
186
+ "cell": "GRU",
187
+ "num_layers": 1,
188
+ "hidden_size": 150,
189
+ "wemb_dim": 0,
190
+ "cemb_dim": 300,
191
+ "cemb_type": "rnn",
192
+ "cemb_layers": 2
193
+ }
194
+ ```
195
+
196
+ All options as well as default values are stored in [`./pie/default_settings.json`](./pie/default_settings.json)
197
+
198
+ The very minimum set of options required to train a model includes `input_path` (path to files with training data), `dev_path` (path to files with development data), and `tasks`, which defines the model to be trained. Other parameters refer to model hyperparameters (`cell`, `num_layers`, `hidden_size`, `wemb_dim`, `cemb_dim`, `cemb_type`, `cemb_layers`), training (`batch_size`, `epochs`) and optimization (`dropout`, `optimizer`, `patience`, `lr`, `lr_factor`, `lr_patience).
199
+
200
+ ### POS tagging using a CRF
201
+
202
+ ```json
203
+ {
204
+ "tasks": [
205
+ {
206
+ "name": "pos",
207
+ "target": true,
208
+ "decoder": "crf",
209
+ "layer": -1
210
+ }
211
+ ]
212
+ }
213
+
214
+ ```
215
+
216
+ ### POS tagging using a linear decoder and 2 auxiliary tasks
217
+ ```json
218
+ {
219
+ "tasks": [
220
+ {
221
+ "name": "pos",
222
+ "level": "token",
223
+ "target": true,
224
+ "decoder": "crf",
225
+ "layer": -1,
226
+ "schedule": {
227
+ "patience": 3
228
+ }
229
+ },
230
+ {
231
+ "name": "case",
232
+ "level": "token",
233
+ "target": false,
234
+ "decoder": "linear",
235
+ "layer": 0,
236
+ "schedule": {
237
+ "patience": 2,
238
+ "factor": 0.5
239
+ }
240
+ },
241
+ {
242
+ "name": "number",
243
+ "level": "token",
244
+ "target": false,
245
+ "decoder": "linear",
246
+ "layer": 0,
247
+ "schedule": {
248
+ "patience": 2,
249
+ "factor": 0.5
250
+ }
251
+ }
252
+ ]
253
+ }
254
+ ```
255
+
256
+ By setting a schedule we can fine-tune the learning dynamics of auxiliary tasks in a multi-task settings (see below for more information on this).
257
+
258
+ To avoid verbosity, parameters invariant across auxiliary tasks can be specified only once using `task_defaults`. Similarly, learning schedule parameters invariant across tasks (`factor`, `patience`, `threshold`, `min_weight`) can be factored out of the task schedule definition. In summary, the previous configuration can be rewritten in the following form:
259
+
260
+ ```json
261
+ {
262
+ "tasks": [
263
+ {
264
+ "name": "pos",
265
+ "level": "token",
266
+ "target": true,
267
+ "decoder": "crf",
268
+ "layer": -1,
269
+ "schedule": {
270
+ "patience": 3
271
+ }
272
+ },
273
+ {
274
+ "name": "case"
275
+ },
276
+ {
277
+ "name": "number"
278
+ }
279
+ ],
280
+ "task_defaults": {
281
+ "level": "token",
282
+ "decoder": "linear",
283
+ "layer": 0
284
+ },
285
+ "patience": 2,
286
+ "factor": 0.5
287
+ }
288
+
289
+ ```
290
+
291
+ ### Transduction-based lemmatization
292
+
293
+ PIE has built-in support for lemmatization as a string transduction task using an Encoder-Decoder architecture as shown below (lemmatizing Latin token "esse" to its lemma "edo"):
294
+
295
+ ![Encoder-Decoder for lemmatization](./img/seq2seq.png)
296
+
297
+ PIE implements several state-of-the-art attention mechanisms to faciliate information flow between the encoder and the decoder. Additionally, the decoder can be conditioned on sentence-level features to help with disambiguating.
298
+
299
+ A task configuration for lemmatization with an Encoder-Decoder model and integrated sentence-level features is shown below.
300
+
301
+ ```json
302
+ {
303
+ "tasks": [
304
+ {
305
+ "name": "lemma",
306
+ "level": "char",
307
+ "target": true,
308
+ "decoder": "attentional",
309
+ "context": "sentence",
310
+ "layer": -1,
311
+ "schedule": {
312
+ "patience": 3
313
+ }
314
+ }
315
+ ]
316
+ }
317
+ ```
318
+
319
+ ## 7. Improving feature extraction with a joint Language Model loss
320
+
321
+ Pie has a built-in option to improve feature extraction by predicting neighboring words from the sentence-level feature vectors. The mechanism has been thoroughly tested for lemmatization in research currently submitted to review and it has been shown to be very effective for languages without a fixed writing standard (e.g. historical languages) and other languages with high token-lemma ambiguity. Besides, there is nothing in theory opposing the idea that it might help with other tasks such as POS-tagging, morphological analyses, etc... The options affecting the joint LM-loss are: `include_lm` (switch on the option), `lm_shared_softmax` (whether to share parameters between forward and backward LMs, recommended value: `true`), `lm_schedule` (parameters to lower the weight assigned to the LM loss over training, once the LM loss starts overfitting it is a good idea to start reducing the loss and eventually set it to 0 to avoid affecting the learning of the target task).
322
+
323
+ ## 8. Multi-task learning
324
+
325
+ When more than one task is defined, at least and at most one task has to have the key-value pair `"target": true`, denoting that that's the task we ultimately care about. All the other tasks will be treated as auxiliary tasks with the goal of extracting better features for the target task. Note that in any case the model will still be able to predict output for auxiliary tasks, but in the spirit of multi-task learning, you will prefer to train a separate model for each of the tasks you care about, selecting each time the appropriate target task and letting all other tasks help the optimization. In the end, you have as many models as tasks you care about, each of which has been optimized for the respective task.
326
+
327
+ ### More on auxiliary tasks
328
+
329
+ An auxiliary task might help learning better features that the classifier for the target task can exploit to produce better (in terms of classification performance) and more robust output (less susceptible to spurious correlations). However, training dynamics in a multi-task setting are complex (even more so than in a normal setting), since different tasks usually results in different learning curves that have to be monitored. In particular, if an auxiliary task converges before the target task, further training might lead that auxiliary task towards overfitting, thereby undoing the potential work done so far. Moreover, losses from different tasks are usually in different scales and this might have the effect that an auxiliary task with a loss on a higher scale dominates training.
330
+
331
+ In order to avoid it, the strategy chosen for PIE consists on set learning schedules for tasks (similar to early stopping) that decrease the weights given to particular tasks over time based on development performance.
332
+
333
+ Multi-task learning consists on jointly training a model for different tasks while sharing parts of the general architecture for all tasks. This can be accomplished by either computing the loss for all tasks every batch and aggregating it before the backward pass, or optimizing in each batch for a single task randomly sampled based on a particular distribution. PIE follows the latter setting, which is known to produce better results.
334
+
335
+ Additionally, it is also important, in case of a multi-layer sentence-level feature extractor, to select at what layer a particular task can help the most (this can be controlled with the "layer" option).
336
+
337
+ Finally, multi-task learning is far from being a silver bullet and it is an empirical question whether a multi-task learning setup will yield improvements. It is recommended to first train a single model, and then try different multi-task learning configuration to see if improvements can be achieved.
338
+
339
+ ## 9. Fine-tuning [New !]
340
+
341
+ Fine-tuning a PIE model (for cases like domain adaptation or transfer to a similar language for instance) is possible with the option `load_pretrained_model` of the config file.
342
+
343
+ For example:
344
+
345
+ ```json
346
+ {
347
+ "load_pretrained_model": {
348
+ "pretrained": "path/to/pie_model.tar",
349
+ "labels_mode": "replace",
350
+ "exclude": ["pos"]
351
+ },
352
+ }
353
+ ```
354
+
355
+ Sub-option **"labels_mode"** indicates how to adapt the vocabularies of the parent model (characters, words, target labels) for the child model. Available values are:
356
+ - *"replace"*: do not use the parent vocabularies, instead compute new ones from the finetuning data and use them
357
+ - *"expand"* (default): keep all parent vocabularies, and if the values indicated by options `word_max_size`, `char_max_size`, `word_min_freq` and `char_min_freq` permit it, append new entries (chars/words/labels) based on the finetuning data (`input_data`)
358
+ - *e.g. the parent model was trained on 1M words, `word_max_size` was set to 10000 and the vocabulary contains 9000 words. You can finetune with `"labels_mode": "expand"` and `"word_max_size": 10000` to include 1000 new words, or increase `"word_max_size": 20000` to include more new words from the finetuning data*
359
+ - *"replace_fill"*: similar to "expand", except we first replace the vocabulary with a new one computed from the finetuning data, and then we fill the seats left with the parent vocabularies (in order of frequency, depending on options `word_max_size`, `char_max_size`, `word_min_freq` and `char_min_freq`)
360
+ - *"skip"*: keep all parent vocabularies, and only set new ones if the child model will be trained on new task(s)
361
+ - *e.g. the parent model was trained for POS tagging and the child model will be trained for lemmatization. The parent model does not have a target characters vocabulary for the lemmatization task, so PIE will create only this one, and keep the parent ones for the rest (input characters, words)*
362
+
363
+ Sub-option **"exclude"** can be used to control which layers (state_dict weights) should be loaded or not. Possible values are: "wemb", "cemb", "cemb_rnn", "sent_rnn", "lm" as well as any target task (e.g. "pos", "lemma"). Excluded modules will be left with the default initialization until training starts.
364
+
365
+ The config options related to the model architecture (`wemb_dim`, `cemb_dim`, `cemb_type`, `cemb_layers`, `linear_layers`, `hidden_size`, `num_layers` and `cell`) must be the same as the parent model. You can run the following scrip to get this information:
366
+
367
+ ```bash
368
+ python ./scripts/get_pie_model_params.py path/to/model.tar
369
+ ```
370
+
371
+ The fine-tuning command is the same as for training:
372
+
373
+ ```bash
374
+ pie train path/to/config.json
375
+ ```
@@ -0,0 +1,50 @@
1
+ papie-0.5.0.dist-info/licenses/LICENSE,sha256=JT6OFU0MuKDsg8-CSPHDWQKJBqebOApcSKnpF3JdMl4,1075
2
+ pie/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ pie/constants.py,sha256=DtzsFIV7IW_fRA0CjPSQp-2H9B3rPEaUy4oo1SblBp0,92
4
+ pie/default_settings.json,sha256=BoJtW0Oze8apOoYdI_IKg283YRfmMQEqW9qxIGnybNA,9068
5
+ pie/initialization.py,sha256=8y7Xl29depgFAvJhO7wUpZBambPq4FnOPoToyi9bOIA,2445
6
+ pie/optimize.py,sha256=xLdAT8_jf2p_V-0hcsqVzpUU1WMM_sc8qFua0Z5TckI,4661
7
+ pie/pretrain_encoder.py,sha256=h7uKo4ic9xtK8JXfik4ZxFqxT9HqbrkSUBJe7DgVTFs,14445
8
+ pie/settings.py,sha256=gy65QS93RSR_hCWHzNWtMrdvPvgyUOSWIblQjPczFdU,4554
9
+ pie/tagger.py,sha256=kKV1k7Pt673EHJkIdzNphCzeeNryKFdgF4Ol-jcpbjk,6105
10
+ pie/torch_utils.py,sha256=mRgVIGytU_UDE0-V0cBiCFzcede9vFXb_qcp1aoN-7E,9686
11
+ pie/trainer.py,sha256=WimjoDREVqwibkTfm9I7RSJbcnxZEPmRtvrHaUr2oQk,15709
12
+ pie/utils.py,sha256=HBiAt1-ShizU5YUwNY1Upbk6sbv4iamILieoTL1T7Uo,7136
13
+ pie/data/__init__.py,sha256=op6Pj1qsH83L8qAKNzEzxeJKoO3yl7vHWoissVNKMV8,181
14
+ pie/data/base_reader.py,sha256=zMHHzLGzk5VE36w27KZKoBhZal8k5LPhtBevlNj6MpY,3316
15
+ pie/data/conll_reader.py,sha256=zTQR00Q5zPsiqeB-u7nSxWsVBUIe-qrc57-WSh6TonI,4257
16
+ pie/data/dataset.py,sha256=J3Kx8Ygs8WurRWxRJDxEoT7CZt0gFrMnrAFNGzWToGE,34899
17
+ pie/data/reader.py,sha256=BYzRgCcvDCKiTe0B5R3P6jJS_3zLXdNU32w4rS2AJOg,3114
18
+ pie/data/tabreader.py,sha256=hDdCE89JXqw5o7Ku75u5396wckF-XOEgJm1RP_sIxeA,5414
19
+ pie/data/preprocessors/__init__.py,sha256=pXZH09nJ0roMV7xbOYl85Y4a7bTgXH3t0JqBZ-k7870,86
20
+ pie/data/preprocessors/edit_tree_tuples.py,sha256=DtKI2zPrBD3p32cZENOIkEdcRR7I_IbiL3TIWs3dQIw,245
21
+ pie/data/preprocessors/edit_trees.py,sha256=vvXLI9USHfoTiXjRTEgvpE_vCtcNkxWU3k685pRywPk,4940
22
+ pie/data/preprocessors/greedy_scripts.py,sha256=oDp27QJVTLZPwa4735wJ-Q6_a5ltAKF4RVEWXQ6CUOw,4272
23
+ pie/models/__init__.py,sha256=HURuDs-NofpTKv0zT2MOeGvNH8ZP_4Oj0qxEKMOVJcY,331
24
+ pie/models/attention.py,sha256=jCmWf-V0Sg5jZf3tdj3-4uTxJ-yTq9z6l-hTogS4l0U,6377
25
+ pie/models/base_model.py,sha256=FdC3MNylAxHBOm8edlRuBTXtW1UPZMXHPx5-kdFogiM,6422
26
+ pie/models/beam_search.py,sha256=uMQ0icazFvw0un5xbQHmAe-8fJcpXk2iBlaE1tPYXYw,4018
27
+ pie/models/decoder.py,sha256=sSbDH_wkDyoB7KImZprRYOdwaD0JdFGVmPW3JhlmZlE,20129
28
+ pie/models/embedding.py,sha256=52cRp6Jyx5q1WsuX2xf7EpxhO-iZiL47zvfJ7cvTGgM,8320
29
+ pie/models/encoder.py,sha256=K8i2Pfj-CofkdkEgjJ_8Mc9YcN5MbjLkPwhA729lbkY,2356
30
+ pie/models/highway.py,sha256=vUJeKx1syxnI-htmJLXyZY7mPzCxscwZEqLNvVXUuCA,970
31
+ pie/models/lstm.py,sha256=kzfW-rytqrq1YcSkVr4sF124nKsc0emeUxkM0N4SONs,5655
32
+ pie/models/model.py,sha256=IUaBeoZpo-tDjwNyskIBYjikeEnAHgSeDmkET9yz42M,28704
33
+ pie/models/scorer.py,sha256=oufvKPwzDaVlJXQhkCtDAMWpjSs_bPv1yKeBsg4hDFU,15899
34
+ pie/scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
+ pie/scripts/evaluate.py,sha256=qDzAEpAU0WMvLQCHDa6SSH1HINEOfbvlvHlIFlQYd38,4738
36
+ pie/scripts/group.py,sha256=rBR8Fz3TuOZCCdfGSCjY0_GawjxaFQEZEOTUyiPI18Y,5664
37
+ pie/scripts/inspect_model.py,sha256=0jHKvD_8_SZ9zH61nrY05v4FNifZr56ujH0YNZ-QoK8,348
38
+ pie/scripts/tag.py,sha256=tf2lY5sKFi_1k9nUtPyuXwx_Ya2Hu1Y5H9PO5tJs9ow,1683
39
+ pie/scripts/tag_pipe.py,sha256=CjOzGymO3lIVr3d0y0dsLZ02JWjQrE_FzYnPK2CPNds,1807
40
+ pie/scripts/train.py,sha256=jqf4ggxxG8I061VJ_yiW1RAjb4Dh5WivOK9qP6bJ_-k,12520
41
+ pie/webapp/__init__.py,sha256=WfwJFYWL7cHmvXcdGTI7ESpMKENAZ1qNpoqvqmiIA9U,4644
42
+ test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
43
+ test/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
+ test/data/test_data.py,sha256=VAW3lnC4rT-3As_AlYdvvSpjp4WiHDcnO_B5T_7wEQM,4876
45
+ test/data/test_tabreader.py,sha256=HTFyFkHGAZggRWnI9l_Gg9H4YumFges7x6gQG3jC0rI,5311
46
+ papie-0.5.0.dist-info/METADATA,sha256=9E7rPSy5fgAzBJ11OYUvWirXMg_svQ1ShbnihP2SmyE,19179
47
+ papie-0.5.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
48
+ papie-0.5.0.dist-info/entry_points.txt,sha256=8x4y4eNVcxHRbrKi3Lae2fEg6zsUCzTtlsRFolp2smg,50
49
+ papie-0.5.0.dist-info/top_level.txt,sha256=_DmrzjzWVPMdHtFLxJizv_K1_ILpFJtz6ssP-9o4IyU,9
50
+ papie-0.5.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (78.1.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pie = pie.scripts.group:pie_cli
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Enrique Manjavacas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ pie
2
+ test
pie/__init__.py ADDED
File without changes
pie/constants.py ADDED
@@ -0,0 +1,8 @@
1
+
2
+ PAD = '<PAD>'
3
+ EOS = '<EOS>'
4
+ BOS = '<BOS>'
5
+ UNK = '<UNK>'
6
+ INVALID = '<INVALID>'
7
+
8
+ TINY = 1e-8
pie/data/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+
2
+ from .dataset import LabelEncoder, MultiLabelEncoder, Dataset
3
+ from .dataset import pack_batch, device_wrapper
4
+ from .reader import Reader, TokenIterator
5
+ from . import preprocessors
@@ -0,0 +1,104 @@
1
+
2
+ import logging
3
+
4
+
5
+ class LineParseException(Exception):
6
+ pass
7
+
8
+
9
+ class MissingDefaultException(Exception):
10
+ def __init__(self, task):
11
+ self.task = task
12
+
13
+
14
+ class BaseReader(object):
15
+ """
16
+ Abstract reader class
17
+ """
18
+ def __init__(self, settings, fpath):
19
+ self.fpath = fpath
20
+ self.tasks = tuple(self.get_tasks())
21
+ self.tasks_defaults = {task['name']: task.get("default")
22
+ for task in settings.tasks if task['name'] in self.tasks}
23
+
24
+ def get_default(self, task, value):
25
+ """
26
+ Get default value for task if given
27
+ """
28
+ default = self.tasks_defaults.get(task)
29
+ if default is not None:
30
+ if default.lower() == 'copy':
31
+ return value
32
+ return default
33
+
34
+ raise MissingDefaultException(task)
35
+
36
+ def readsents(self, silent=True, only_tokens=False):
37
+ """
38
+ Generator over dataset sentences. Each output is a tuple of (Input, Tasks)
39
+ objects with, where each entry is a list of strings.
40
+ """
41
+ current_sent, lines = 0, self.parselines()
42
+
43
+ while True:
44
+ try:
45
+ line = next(lines)
46
+ current_sent += 1
47
+ # check if parse exception
48
+ if isinstance(line, LineParseException):
49
+ if not silent:
50
+ logging.warning(
51
+ "Parse error at [{}:sent={}]\n => {}"
52
+ .format(self.fpath, current_sent + 1, str(line)))
53
+ continue
54
+
55
+ inp, tasks = line
56
+ if only_tokens:
57
+ yield inp
58
+ else:
59
+ yield (self.fpath, current_sent), (inp, tasks)
60
+
61
+ except StopIteration:
62
+ break
63
+
64
+ def check_tasks(self, expected=None):
65
+ """
66
+ Returns the union of the tasks across files. If `expected` is passed,
67
+ it is understood to be a subset of all available tasks and it will check
68
+ whether all `expected` are in fact available in all files as per the output
69
+ of `get_tasks`.
70
+
71
+ Returns
72
+ ========
73
+ List of tasks available in all files (or a subset if `expected` is passed)
74
+ """
75
+ if expected is not None:
76
+ diff = set(expected).difference(set(self.tasks))
77
+ if diff:
78
+ raise ValueError("Following expected tasks are missing "
79
+ "from at least one file: '{}'"
80
+ .format('"'.join(diff)))
81
+
82
+ return tuple(expected or self.tasks)
83
+
84
+ def parselines(self):
85
+ """
86
+ Generator over tuples of (Input, Tasks) holding input and target data
87
+ as lists of strings. Some tasks might be missing from a file, in which
88
+ case the corresponding value is None.
89
+
90
+ ParseError can be thrown if an issue is encountered during processing.
91
+ The issue can be documented by passing an error message as second argument
92
+ to ParseError
93
+ """
94
+ raise NotImplementedError
95
+
96
+ def get_tasks(self):
97
+ """
98
+ Reader is responsible for extracting the expected tasks in the file.
99
+
100
+ Returns
101
+ =========
102
+ Set of tasks in a file
103
+ """
104
+ raise NotImplementedError