parser_trainer_test.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. # Copyright 2016 Google Inc. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # ==============================================================================
  16. # This test trains a parser on a small dataset, then runs it in greedy mode and
  17. # in structured mode with beam 1, and checks that the result is identical.
  18. set -eux
  19. BINDIR=$TEST_SRCDIR/$TEST_WORKSPACE/syntaxnet
  20. CONTEXT=$BINDIR/testdata/context.pbtxt
  21. TMP_DIR=/tmp/syntaxnet-output
  22. mkdir -p $TMP_DIR
  23. sed "s=SRCDIR=$TEST_SRCDIR=" "$CONTEXT" | \
  24. sed "s=OUTPATH=$TMP_DIR=" > $TMP_DIR/context
  25. PARAMS=128-0.08-3600-0.9-0
  26. "$BINDIR/parser_trainer" \
  27. --arg_prefix=brain_parser \
  28. --batch_size=32 \
  29. --compute_lexicon \
  30. --decay_steps=3600 \
  31. --graph_builder=greedy \
  32. --hidden_layer_sizes=128 \
  33. --learning_rate=0.08 \
  34. --momentum=0.9 \
  35. --output_path=$TMP_DIR \
  36. --task_context=$TMP_DIR/context \
  37. --training_corpus=training-corpus \
  38. --tuning_corpus=tuning-corpus \
  39. --params=$PARAMS \
  40. --num_epochs=12 \
  41. --report_every=100 \
  42. --checkpoint_every=1000 \
  43. --logtostderr
  44. "$BINDIR/parser_eval" \
  45. --task_context=$TMP_DIR/brain_parser/greedy/$PARAMS/context \
  46. --hidden_layer_sizes=128 \
  47. --input=tuning-corpus \
  48. --output=stdout \
  49. --arg_prefix=brain_parser \
  50. --graph_builder=greedy \
  51. --model_path=$TMP_DIR/brain_parser/greedy/$PARAMS/model \
  52. --logtostderr \
  53. > $TMP_DIR/greedy-out
  54. "$BINDIR/parser_eval" \
  55. --task_context=$TMP_DIR/context \
  56. --hidden_layer_sizes=128 \
  57. --beam_size=1 \
  58. --input=tuning-corpus \
  59. --output=stdout \
  60. --arg_prefix=brain_parser \
  61. --graph_builder=structured \
  62. --model_path=$TMP_DIR/brain_parser/greedy/$PARAMS/model \
  63. --logtostderr \
  64. > $TMP_DIR/struct-beam1-out
  65. diff $TMP_DIR/greedy-out $TMP_DIR/struct-beam1-out
  66. STRUCT_PARAMS=128-0.001-3600-0.9-0
  67. "$BINDIR/parser_trainer" \
  68. --arg_prefix=brain_parser \
  69. --batch_size=8 \
  70. --compute_lexicon \
  71. --decay_steps=3600 \
  72. --graph_builder=structured \
  73. --hidden_layer_sizes=128 \
  74. --learning_rate=0.001 \
  75. --momentum=0.9 \
  76. --pretrained_params=$TMP_DIR/brain_parser/greedy/$PARAMS/model \
  77. --pretrained_params_names=\
  78. embedding_matrix_0,embedding_matrix_1,embedding_matrix_2,bias_0,weights_0 \
  79. --output_path=$TMP_DIR \
  80. --task_context=$TMP_DIR/context \
  81. --training_corpus=training-corpus \
  82. --tuning_corpus=tuning-corpus \
  83. --params=$STRUCT_PARAMS \
  84. --num_epochs=20 \
  85. --report_every=25 \
  86. --checkpoint_every=200 \
  87. --logtostderr
  88. "$BINDIR/parser_eval" \
  89. --task_context=$TMP_DIR/context \
  90. --hidden_layer_sizes=128 \
  91. --beam_size=8 \
  92. --input=tuning-corpus \
  93. --output=stdout \
  94. --arg_prefix=brain_parser \
  95. --graph_builder=structured \
  96. --model_path=$TMP_DIR/brain_parser/structured/$STRUCT_PARAMS/model \
  97. --logtostderr \
  98. > $TMP_DIR/struct-beam8-out
  99. echo "PASS"