The `process`function yield 7 lists which are six features and labels.
The `process`function yield 9 lists which are 8 features and label.
### Neural Network Config
### Neural Network Config
`db_lstm.py` is the neural network config file to load the dictionaries and define the data provider module and network architecture during the training procedure.
`db_lstm.py` is the neural network config file to load the dictionaries and define the data provider module and network architecture during the training procedure.
Seven `data_layer` load instances from data provider. Six features are transformed into embedddings respectively, and mixed by `mixed_layer` . Deep bidirectional LSTM layers extract features for the softmax layer. The objective function is cross entropy of labels.
Nine `data_layer` load instances from data provider. Eight features are transformed into embedddings respectively, and mixed by `mixed_layer` . Deep bidirectional LSTM layers extract features for the softmax layer. The objective function is cross entropy of labels.
### Run Training
### Run Training
The script for training is `train.sh`, user just need to execute:
The script for training is `train.sh`, user just need to execute:
...
@@ -115,24 +120,36 @@ The content in `train.sh`:
...
@@ -115,24 +120,36 @@ The content in `train.sh`:
```
```
paddle train \
paddle train \
--config=./db_lstm.py \
--config=./db_lstm.py \
--use_gpu=0 \
--log_period=5000 \
--trainer_count=1 \
--show_parameter_stats_period=5000 \
--saving_period=1 \
--save_dir=./output \
--save_dir=./output \
--trainer_count=4 \
--local=1 \
--log_period=10 \
--num_passes=10000 \
--num_passes=500 \
--test_period=0 \
--use_gpu=false \
--average_test_period=10000000 \
--show_parameter_stats_period=10 \
--init_model_path=./data \
--test_all_data_in_one_period=1 \
--load_missing_parameter_strategy=rand \
--dot_period=100 \
2>&1 | tee 'train.log'
2>&1 | tee 'train.log'
```
```
-\--config=./db_lstm.py : network config file.
-\--config=./db_lstm.py : network config file.
-\--save_di=./output: output path to save models.
-\--use_gpu=false: use CPU to train, set true, if you install GPU version of PaddlePaddle and want to use GPU to train, until now crf_layer do not support GPU
-\--trainer_count=4 : set thread number (or GPU count).
-\--log_period=500: print log every 20 batches.
-\--log_period=10 : print log every 20 batches.
-\--trainer_count=1: set thread number (or GPU count).
-\--num_passes=500: set pass number, one pass in PaddlePaddle means training all samples in dataset one time.
-\--show_parameter_stats_period=5000: show parameter statistic every 100 batches.
-\--use_gpu=false: use CPU to train, set true, if you install GPU version of PaddlePaddle and want to use GPU to train.
-\--saving_period=1: save model per pass
-\--show_parameter_stats_period=10: show parameter statistic every 100 batches.
-\--save_dir=./output: output path to save models.
-\--test_all_data_in_one_period=1: test all data in every testing.
-\--local=1: traing in local mode
-\--num_passes=10000: set pass number, one pass in PaddlePaddle means training all samples in dataset one time.
-\--test_period=0: run testing each pass
-\--average_test_period=10000000: do test on average parameter every average_test_period batches
-\--load_missing_parameter_strategy=rand: random initialization unexisted parameters
-\--dot_period=100: print a dot per 100 batches
After training, the models will be saved in directory `output`.
After training, the models will be saved in directory `output`.
...
@@ -166,11 +183,13 @@ The script for prediction is `predict.sh`, user just need to execute:
...
@@ -166,11 +183,13 @@ The script for prediction is `predict.sh`, user just need to execute:
In `predict.sh`, user should offer the network config file, model path, label file, word dictionary file, feature file
In `predict.sh`, user should offer the network config file, model path, label file, word dictionary file, feature file
```
```
python predict.py
python predict.py
-c $config_file
-c $config_file \
-w $model_path
-w $best_model_path \
-l $label_file
-l $label_file \
-d $dict_file
-p $predicate_dict_file \
-i $input_file
-d $dict_file \
-i $input_file \
-o $output_file
```
```
`predict.py` is the main executable python script, which includes functions: load model, load data, data prediction. The network model will output the probability distribution of labels. In the demo, we take the label with maximum probability as result. User can also implement the beam search or viterbi decoding upon the probability distribution matrix.
`predict.py` is the main executable python script, which includes functions: load model, load data, data prediction. The network model will output the probability distribution of labels. In the demo, we take the label with maximum probability as result. User can also implement the beam search or viterbi decoding upon the probability distribution matrix.