CONFIG.md (4834B)
1 # Configuration 2 3 ## How-to Use 4 5 Train the model described in the `configs/baseline.py` file: 6 ``` 7 python -m mmsrl.train configs/baseline.py 8 ``` 9 10 Same but changing the value of the `batch_size` parameter: 11 ``` 12 python -m mmsrl.train configs/baseline.py --batch_size=42 13 ``` 14 15 When a command line argument starts with `--`, the right hand side of the `=` is `eval()`uated, to set a string parameter, the quotes should be escaped: 16 ``` 17 python -m mmsrl.train configs/baseline.py --dataname=\"covid19\" 18 ``` 19 20 Indeed, the right hand side is first evaluated in the context of the config dictionary, and can be resolved if it refers to a variable, in the following example, the value of modelname is set to the value of the config variable dataname (which is set to `all` in `configs/baseline.py`). 21 ``` 22 python -m mmsrl.train configs/baseline.py --modelname=dataname 23 ``` 24 25 This allows for some on-the-fly manipulation of config variables: 26 ``` 27 python -m mmsrl.train configs/ofa_vqa.py '--ofa_path=ofa_path.replace("vqa_large_best", "ofa_base")' 28 ``` 29 30 However, if the right hand side of `=` can't be `eval()`uated, it is cast to a string. In the following example `modelname` is set to `"datanamex"`. (This feature was asked for by Syrielle, blame her for the confusion.) 31 ``` 32 python -m mmsrl.train configs/baseline.py --modelname=datanamex 33 ``` 34 35 36 ## Available Config Parameters 37 38 - `dataname` Choose dataset, either 'uspolitics' or 'covid19', or 'all' to use both. 39 - `model` Which model to use: ofa or perceiver or baseline. 40 - `multilabel` Multi-label classification or not. 41 - `output_val` Path to the validation output file. 42 - `output_train` Path to the train output file. 43 - `output_test` Path to the test output file. 44 - `save_model` Save best model there. 45 46 ### Multimodel 47 - `unfreeze` Part of the model to train (supported: "classifier", "none", "all") 48 49 ### OFA parameters 50 - `ofa_task` Task for ofa: vqa_gen or snli_ve. 51 - `ofa_path` Path to OFA model checkpoint. 52 - `ofa_classification_head` Use a classification on the model's output instead of recasting the MMSRL problem as VQA or SNLI. 53 - `vqa_input` Input to the OFA encoder for the VQA task (either "question ocr", "ocr question", or "question"). 54 - `only_score_answer` The prediction is only made by looking at the likelihood of answer tokens, not tokens part of the question ocr, etc. 55 56 #### OFA SNLI parameters 57 The output of the SNLI model for an entity looks like the following row-normalized table: 58 59 | | no | maybe | yes | 60 | :--- | :---: | :---: | :---: | 61 | hero | A | B | C | 62 | victim | A | B | C | 63 | villain | A | B | C | 64 | *(other)* | *a* | *b* | *c* | 65 66 The output must be of size 4: one score for each of hero, victim, villain and other. 67 The conversion of the above table into this prediction on size 4 is parametrized by the following options: 68 69 - `maybe_is` Whether to group `maybe` with `yes`, `no` (or ignore it). 70 - `neither_for_other` Whether a prompt is generated for *other*, if this is false the "other" class is the sum of the `no` column(s), otherwise a prompt "entity is neither a hero, villain nor victim" is used. 71 72 When `neither_for_other` is `True`, the prediction is simply the column C (or B+C if `maybe_is="yes"`). 73 Otherwise, when the last row does not exist, the predictions for hero, victim and villain remain the same, but the prediction for other is set to the sum of unsused cells. 74 75 ### Baseline model parameters 76 - `modelname` Which transformers model to use. 77 - `hidden_size` Size of the hidden layer of the MLP for the baseline model. 78 - `dropout` Dropout of the transformers' output, before the MLP. 79 80 ### Optimizer parameters 81 - `learning_rate` Learning rate. 82 - `weight_decay` Weight decay. 83 - `max_grad_norm` Max gradient normalization. 84 - `subsample_other` Subsampling of the others class to counter the large class imbalance. 85 - `subsample_labels` Same but per-label. 86 - `class_weights` Class weights for loss computation. Doesn't work because the class imbalance is too big. Because when we have a class with low frequency, the loss gets huge and the gradient too. 87 88 ### Trainer parameters 89 - `batch_size` Model batch size. 90 - `accumulation` Nb of accumulation steps. 91 - `batch_per_epoch` Batch per epoch. 92 - `no_initial_valid` Do not validate before training. 93 - `max_epoch` Max epoch. 94 - `patience` If the dev score worsen 3 epoch in a row, stop the training. 95 - `amp` Automatic Mixed Precision training. 96 - `workers` Number of workers used to generate data. 97 98 ### Dataset parameters (Numbers chosen from exploration of the datasets) 99 - `max_text_len` Max text length (nb of tokens). (observed: 321) 100 - `max_nb_ent` Max nb of entities per image, for padding. (observed: 29) 101 - `max_ent_len` Max entity name length (nb of tokens). 102 - `image_max_edge` Resize images such that the longest edge has this length.