|
| 1 | +# Neural Identifier Splitter |
| 2 | +Article [Splitting source code identifiers using Bidirectional LSTM Recurrent Neural Network](https://arxiv.org/abs/1805.11651). |
| 3 | + |
| 4 | +### Agenda |
| 5 | +* Data |
| 6 | +* Training pipeline |
| 7 | +* How to launch |
| 8 | + |
| 9 | +### Data |
| 10 | +You can download the dataset [here](https://drive.google.com/open?id=1wZR5zF1GL1fVcA1gZuAN_9rSLd5ssqKV). More information about the dataset is available [here](https://github.com/src-d/datasets/tree/master/Identifiers). |
| 11 | +#### Data format |
| 12 | +* format of file: `.csv.gz`. |
| 13 | +* the `csv` structure: |
| 14 | + |
| 15 | +|num_files|num_occ|num_repos|token|token_split| |
| 16 | +|:--|:--|:--|:--|:--| |
| 17 | +|1|2|1|quesesSet|queses set| |
| 18 | +|...|...|...|...|...| |
| 19 | + |
| 20 | +#### Data stats |
| 21 | +* 49 millions of identifiers |
| 22 | +* 1 GB |
| 23 | + |
| 24 | +### Training pipeline |
| 25 | +Training pipeline consists of several steps |
| 26 | +* [prepare features](https://github.com/src-d/ml/blob/master/sourced/ml/algorithms/id_splitter/features.py#L44-#L118) - read data, extract features, train/test split |
| 27 | +* [prepare generators for keras](https://github.com/src-d/ml/blob/master/sourced/ml/cmd/train_id_split.py#L34-#L48) |
| 28 | +* [prepare model - RNN or CNN](https://github.com/src-d/ml/blob/master/sourced/ml/cmd/train_id_split.py#L53-#L76) |
| 29 | +* [training](https://github.com/src-d/ml/blob/master/sourced/ml/cmd/train_id_split.py#L78-#L89) |
| 30 | +* [quality report and save the model](https://github.com/src-d/ml/blob/master/sourced/ml/cmd/train_id_split.py#L91-#L96) |
| 31 | + |
| 32 | +### How to launch |
| 33 | +First of all you need to download data using link above. |
| 34 | + |
| 35 | +Usage: |
| 36 | +```console |
| 37 | +usage: srcml train-id-split [-h] -i INPUT [-e EPOCHS] [-b BATCH_SIZE] |
| 38 | + [-l LENGTH] -o OUTPUT [-t TEST_RATIO] |
| 39 | + [-p {pre,post}] [--optimizer {RMSprop,Adam}] |
| 40 | + [--lr LR] [--final-lr FINAL_LR] |
| 41 | + [--samples-before-report SAMPLES_BEFORE_REPORT] |
| 42 | + [--val-batch-size VAL_BATCH_SIZE] [--seed SEED] |
| 43 | + [--devices DEVICES] |
| 44 | + [--csv-identifier CSV_IDENTIFIER] |
| 45 | + [--csv-identifier-split CSV_IDENTIFIER_SPLIT] |
| 46 | + [--include-csv-header] --model {RNN,CNN} |
| 47 | + [-s STACK] |
| 48 | + [--type-cell {GRU,LSTM,CuDNNLSTM,CuDNNGRU}] |
| 49 | + [-n NEURONS] [-f FILTERS] [-k KERNEL_SIZES] |
| 50 | + [--dim-reduction DIM_REDUCTION] |
| 51 | + |
| 52 | +optional arguments: |
| 53 | + -h, --help show this help message and exit |
| 54 | + -i INPUT, --input INPUT |
| 55 | + Path to the input data in CSV |
| 56 | + format:num_files,num_occ,num_repos,token,token_split |
| 57 | + -e EPOCHS, --epochs EPOCHS |
| 58 | + Number of training epochs. The more the betterbut the |
| 59 | + training time is proportional. (default: 10) |
| 60 | + -b BATCH_SIZE, --batch-size BATCH_SIZE |
| 61 | + Batch size. Higher values better utilize GPUsbut may |
| 62 | + harm the convergence. (default: 500) |
| 63 | + -l LENGTH, --length LENGTH |
| 64 | + RNN sequence length. (default: 40) |
| 65 | + -o OUTPUT, --output OUTPUT |
| 66 | + Path to store the trained model. |
| 67 | + -t TEST_RATIO, --test-ratio TEST_RATIO |
| 68 | + Fraction of the dataset to use for evaluation. |
| 69 | + (default: 0.2) |
| 70 | + -p {pre,post}, --padding {pre,post} |
| 71 | + Whether to pad before or after each sequence. |
| 72 | + (default: post) |
| 73 | + --optimizer {RMSprop,Adam} |
| 74 | + Algorithm to use as an optimizer for the neural net. |
| 75 | + (default: Adam) |
| 76 | + --lr LR Initial learning rate. (default: 0.001) |
| 77 | + --final-lr FINAL_LR Final learning rate. The decrease from the initial |
| 78 | + learning rate is done linearly. (default: 1e-05) |
| 79 | + --samples-before-report SAMPLES_BEFORE_REPORT |
| 80 | + Number of samples between each validation reportand |
| 81 | + training updates. (default: 5000000) |
| 82 | + --val-batch-size VAL_BATCH_SIZE |
| 83 | + Batch size for validation.It can be increased to speed |
| 84 | + up the pipeline butit proportionally increases the |
| 85 | + memory consumption. (default: 2000) |
| 86 | + --seed SEED Random seed. (default: 1989) |
| 87 | + --devices DEVICES Device(s) to use. '-1' means CPU. (default: 0) |
| 88 | + --csv-identifier CSV_IDENTIFIER |
| 89 | + Column name in the CSV file for the raw identifier. |
| 90 | + (default: 3) |
| 91 | + --csv-identifier-split CSV_IDENTIFIER_SPLIT |
| 92 | + Column name in the CSV file for the splitidentifier. |
| 93 | + (default: 4) |
| 94 | + --include-csv-header Treat the first line of the input CSV as a |
| 95 | + regularline. (default: False) |
| 96 | + --model {RNN,CNN} Neural Network model to use to learn the |
| 97 | + identifiersplitting task. |
| 98 | + -s STACK, --stack STACK |
| 99 | + Number of layers stacked on each other. (default: 2) |
| 100 | + --type-cell {GRU,LSTM,CuDNNLSTM,CuDNNGRU} |
| 101 | + Recurrent layer type to use. (default: LSTM) |
| 102 | + -n NEURONS, --neurons NEURONS |
| 103 | + Number of neurons on each layer. (default: 256) |
| 104 | + -f FILTERS, --filters FILTERS |
| 105 | + Number of filters for each kernel size. (default: |
| 106 | + 64,32,16,8) |
| 107 | + -k KERNEL_SIZES, --kernel-sizes KERNEL_SIZES |
| 108 | + Sizes for sliding windows. (default: 2,4,8,16) |
| 109 | + --dim-reduction DIM_REDUCTION |
| 110 | + Number of 1-d kernels to reduce dimensionalityafter |
| 111 | + each layer. (default: 32) |
| 112 | +``` |
| 113 | + |
| 114 | + |
| 115 | +Examples of commands: |
| 116 | +1) Train RNN with LSTM cells |
| 117 | +```console |
| 118 | +srcml train-id-split --model RNN --input /path/to/input.csv.gz --output /path/to/output |
| 119 | +``` |
| 120 | +2) Train RNN with CuDNNLSTM cells |
| 121 | +```console |
| 122 | +srcml train-id-split --model RNN --input /path/to/input.csv.gz --output /path/to/output \ |
| 123 | +--type-cell CuDNNLSTM |
| 124 | +``` |
| 125 | +3) Train CNN |
| 126 | +```console |
| 127 | +srcml train-id-split --model CNN --input /path/to/input.csv.gz --output /path/to/output |
| 128 | +``` |
0 commit comments