Having to run syntaxnet twice to get both tokenized/POS-tagged file and dependency parsed file
Have to run demo.sh twice when reading a file from a directory and outputting to another file in another directory.
Below, I show my demo.sh file and my context.pbtxt file. I am reading in an english-text file from a directory and then outputting the results to files in another directory (see context.pbtxt for details). I have to run demo.sh twice (from /models/syntaxnet/) in order to get both the test_data_out and test_data_parsed. On the first run, the test_data_out is created. Then, on the second run, the test_data_parsed is created. It seems that syntaxnet is only reading through the first PARSER_EVAL on the first run and ignoring the pipe to the second PARSER_EVAL and to bazel. Then, on the second run, it sees that the output for the first PARSER_EVAL hasn't changed so it moves on to the pipes.
How can I get this all to run a single time?
demo.sh PARSER_EVAL=bazel-bin/syntaxnet/parser_eval MODEL_DIR=syntaxnet/models/parsey_mcparseface [[ "$1" == "--conll" ]] && INPUT_FORMAT=stdin-conll || INPUT_FORMAT=stdin
$PARSER_EVAL
$PARSER_EVAL
--input=test_data
--output=test_data_out
--hidden_layer_sizes=64
--arg_prefix=brain_tagger
--graph_builder=structured
--task_context=$MODEL_DIR/context.pbtxt
--model_path=$MODEL_DIR/tagger-params
--slim_model
--batch_size=1024
--alsologtostderr
|
$PARSER_EVAL
--input=test_data_out
--output=test_data_parsed
--hidden_layer_sizes=512,512
--arg_prefix=brain_parser
--graph_builder=structured
--task_context=$MODEL_DIR/context.pbtxt
--model_path=$MODEL_DIR/parser-params
--slim_model
--batch_size=1024
--alsologtostderr
|
bazel-bin/syntaxnet/conll2tree
--task_context=$MODEL_DIR/context.pbtxt
--alsologtostderrThe last three inputs from context.pbtxt input { name: 'test_data' record_format: 'english-text' Part { file_pattern: 'TestData/Microbe_test.txt' } } input { name: 'test_data_out' record_format: 'english-text' Part { file_pattern: 'TestDataOut/test_data_out.txt' } } input { name: 'test_data_parsed' record_format: 'conll-sentence' Part { file_pattern: 'TestDataOut/test_data_parsed.txt' } }
I agree!
@shaxtell
If you are writing to file it doesn't make sense to pipe the output, so just remove the pipes and have the two calls to $PARSER_EVAL separate, writing to file. I also removed the pipe to bazel-bin/syntaxnet/conll2tree. This means you wont be able to see the trees when you run the parsing, but it will perform tagging and parsing with one command.
To see the trees I made another script which has one $PARSER_EVAL call using my intermediate file as input and output to stdout-conll and then piped that to bazel-bin/syntaxnet/conll2tree (as in demo.sh). This is very inefficient since this requires re-parsing the intermediate file but this is an easy hack.
@afgiel,
This worked nicely! I removed the pipes and the bazel stuff at the bottom and all of the files came in after a single run. Thank you very much!!
@shaxtell @afgiel Can you share the script of removing the pipes? Is possible to Only output the tagging/parsing information? Thanks
@ColinUNCG, here's what I have in my demo.sh:
PARSER_EVAL=bazel-bin/syntaxnet/parser_eval MODEL_DIR=syntaxnet/models/parsey_mcparseface [[ "$1" == "--conll" ]] && INPUT_FORMAT=stdin-conll || INPUT_FORMAT=stdin
$PARSER_EVAL
$PARSER_EVAL
--input=test_data
--output=test_data_out
--hidden_layer_sizes=64
--arg_prefix=brain_tagger
--graph_builder=structured
--task_context=$MODEL_DIR/context.pbtxt
--model_path=$MODEL_DIR/tagger-params
--slim_model
--batch_size=1024
--alsologtostderr \$PARSER_EVAL
--input=test_data_out
--output=test_data_parsed
--hidden_layer_sizes=512,512
--arg_prefix=brain_parser
--graph_builder=structured
--task_context=$MODEL_DIR/context.pbtxt
--model_path=$MODEL_DIR/parser-params
--slim_model
--batch_size=1024
--alsologtostderr \
Regarding only outputting the tagging or parsing information. The dependency parser needs the tagging, so you have to do the tagging if you want the parsing. However, if you remove the second $PARSER_EVAL (like the one below) that should only run the tagger and output to your tag output file. Just make sure that your context.pbtxt is set up with the input and output files.
PARSER_EVAL=bazel-bin/syntaxnet/parser_eval MODEL_DIR=syntaxnet/models/parsey_mcparseface [[ "$1" == "--conll" ]] && INPUT_FORMAT=stdin-conll || INPUT_FORMAT=stdin
$PARSER_EVAL
$PARSER_EVAL
--input=test_data
--output=test_data_out
--hidden_layer_sizes=64
--arg_prefix=brain_tagger
--graph_builder=structured
--task_context=$MODEL_DIR/context.pbtxt
--model_path=$MODEL_DIR/tagger-params
--slim_model
--batch_size=1024
--alsologtostderr \
@shaxtell Thanks :)
A. I replaced the last three inputs from context.pbtxt
input { name: 'test_data' record_format: 'english-text' Part { file_pattern: 'TestData/Microbe_test.txt' } } input { name: 'test_data_out' record_format: 'english-text' Part { file_pattern: 'TestDataOut/test_data_out.txt' } } input { name: 'test_data_parsed' record_format: 'conll-sentence' Part { file_pattern: 'TestDataOut/test_data_parsed.txt' } }
B. created 2 folders (TestData and TestDataOut) under parsey_mcparseface C. modified demo.sh
PARSER_EVAL=bazel-bin/syntaxnet/parser_eval MODEL_DIR=syntaxnet/models/parsey_mcparseface [[ "$1" == "--conll" ]] && INPUT_FORMAT=stdin-conll || INPUT_FORMAT=stdin $PARSER_EVAL \ $PARSER_EVAL \ --input=test_data \ --output=test_data_out \ --hidden_layer_sizes=64 \ --arg_prefix=brain_tagger \ --graph_builder=structured \ --task_context=$MODEL_DIR/context.pbtxt \ --model_path=$MODEL_DIR/tagger-params \ --slim_model \ --batch_size=1024 \ --alsologtostderr \
I ran this :
echo 'Bob brought the pizza to Alice.' | syntaxnet/demo.sh
I got this error :
F syntaxnet/task_context.cc:140] Check failed: input.part_size() == 1 (0 vs. 1)label-map
did I miss anything?
@ColinUNCG what are you trying to accomplish? the current script looks as if you are attempting to output only the tagging and not the parsing
regardless, I think you should erase the first $PARSER_EVAL and make your directories in /models/syntaxnet/instead of /models/syntaxnet/syntaxnet/models/parsey_mcparseface
@afgiel
Yes. I am attempting to output ONLY the PoS tagging
A. I erased the first $PARSER_EVAL
B. moved the directories (TestData and TestDataOut) in /models/syntaxnet/
C. I ran this echo 'Bob brought the pizza to Alice.' | syntaxnet/demo.sh again
D. Still got the same error :
F syntaxnet/task_context.cc:140] Check failed: input.part_size() == 1 (0 vs. 1)label-map
Do I need create the txt files?
Microbe_test.txt, test_data_out.txt and test_data_parsed.txt
@ColinUNCG
If you define --input=test_data that means your input is coming from the test_data input defined in context.pbtxt which means the input is the file TestData/Microbe_test.txt. So yes, you need to create this file, and populate it with the text you want POS tagged (one per line). Piping to the script does nothing since your input is the file. Please do some research before asking as this should be obvious.
Here is a script that will output the POS tags given a piped input
# contents of syntaxnet/print_pos.sh
PARSER_EVAL=bazel-bin/syntaxnet/parser_eval
MODEL_DIR=syntaxnet/models/parsey_mcparseface
$PARSER_EVAL \
--input=stdin\
--output=stdout-conll \
--hidden_layer_sizes=64 \
--arg_prefix=brain_tagger \
--graph_builder=structured \
--task_context=$MODEL_DIR/context.pbtxt \
--model_path=$MODEL_DIR/tagger-params \
--slim_model \
--batch_size=1024 \
--alsologtostderr
and here is example usage
echo 'This is a test of the script' | syntaxnet/print_pos.sh
I syntaxnet/term_frequency_map.cc:101] Loaded 46 terms from syntaxnet/models/parsey_mcparseface/label-map.
I syntaxnet/embedding_feature_extractor.cc:35] Features: input.digit input.hyphen; input.prefix(length="2") input(1).prefix(length="2") input(2).prefix(length="2") input(3).prefix(length="2") input(-1).prefix(length="2") input(-2).prefix(length="2") input(-3).prefix(length="2") input(-4).prefix(length="2"); input.prefix(length="3") input(1).prefix(length="3") input(2).prefix(length="3") input(3).prefix(length="3") input(-1).prefix(length="3") input(-2).prefix(length="3") input(-3).prefix(length="3") input(-4).prefix(length="3"); input.suffix(length="2") input(1).suffix(length="2") input(2).suffix(length="2") input(3).suffix(length="2") input(-1).suffix(length="2") input(-2).suffix(length="2") input(-3).suffix(length="2") input(-4).suffix(length="2"); input.suffix(length="3") input(1).suffix(length="3") input(2).suffix(length="3") input(3).suffix(length="3") input(-1).suffix(length="3") input(-2).suffix(length="3") input(-3).suffix(length="3") input(-4).suffix(length="3"); input.token.word input(1).token.word input(2).token.word input(3).token.word input(-1).token.word input(-2).token.word input(-3).token.word input(-4).token.word
I syntaxnet/embedding_feature_extractor.cc:36] Embedding names: other;prefix2;prefix3;suffix2;suffix3;words
I syntaxnet/embedding_feature_extractor.cc:37] Embedding dims: 8;16;16;16;16;64
I syntaxnet/term_frequency_map.cc:101] Loaded 64036 terms from syntaxnet/models/parsey_mcparseface/word-map.
I syntaxnet/term_frequency_map.cc:101] Loaded 49 terms from syntaxnet/models/parsey_mcparseface/tag-map.
INFO:tensorflow:Building training network with parameters: feature_sizes: [2 8 8 8 8 8] domain_sizes: [ 5 10665 10665 8970 8970 64038]
I syntaxnet/term_frequency_map.cc:101] Loaded 49 terms from syntaxnet/models/parsey_mcparseface/tag-map.
I syntaxnet/term_frequency_map.cc:101] Loaded 46 terms from syntaxnet/models/parsey_mcparseface/label-map.
I syntaxnet/embedding_feature_extractor.cc:35] Features: input.digit input.hyphen; input.prefix(length="2") input(1).prefix(length="2") input(2).prefix(length="2") input(3).prefix(length="2") input(-1).prefix(length="2") input(-2).prefix(length="2") input(-3).prefix(length="2") input(-4).prefix(length="2"); input.prefix(length="3") input(1).prefix(length="3") input(2).prefix(length="3") input(3).prefix(length="3") input(-1).prefix(length="3") input(-2).prefix(length="3") input(-3).prefix(length="3") input(-4).prefix(length="3"); input.suffix(length="2") input(1).suffix(length="2") input(2).suffix(length="2") input(3).suffix(length="2") input(-1).suffix(length="2") input(-2).suffix(length="2") input(-3).suffix(length="2") input(-4).suffix(length="2"); input.suffix(length="3") input(1).suffix(length="3") input(2).suffix(length="3") input(3).suffix(length="3") input(-1).suffix(length="3") input(-2).suffix(length="3") input(-3).suffix(length="3") input(-4).suffix(length="3"); input.token.word input(1).token.word input(2).token.word input(3).token.word input(-1).token.word input(-2).token.word input(-3).token.word input(-4).token.word
I syntaxnet/embedding_feature_extractor.cc:36] Embedding names: other;prefix2;prefix3;suffix2;suffix3;words
I syntaxnet/embedding_feature_extractor.cc:37] Embedding dims: 8;16;16;16;16;64
I syntaxnet/term_frequency_map.cc:101] Loaded 64036 terms from syntaxnet/models/parsey_mcparseface/word-map.
INFO:tensorflow:Processed 1 documents
1 This _ DET DT _ 0 _ _
2 is _ VERB VBZ _ 0 _ _
3 a _ DET DT _ 0 _ _
4 test _ NOUN NN _ 0 _ _
5 of _ ADP IN _ 0 _ _
6 the _ DET DT _ 0 _ _
7 script _ NOUN NN _ 0 _ _
INFO:tensorflow:Total processed documents: 1
INFO:tensorflow:num correct tokens: 0
INFO:tensorflow:total tokens: 7
INFO:tensorflow:Seconds elapsed in evaluation: 0.07, eval metric: 0.00%
you could change this to take file as --input or --output pretty simply
@afgiel
Thanks and sorry I didn't explain clearly. I said "output ONLY the PoS tagging" means the output only has PoS tagging like this:
1 This _ DET DT _ 0 _ _
2 is _ VERB VBZ _ 0 _ _
3 a _ DET DT _ 0 _ _
4 test _ NOUN NN _ 0 _ _
5 of _ ADP IN _ 0 _ _
6 the _ DET DT _ 0 _ _
7 script _ NOUN NN _ 0 _ _
I am attempting remove the other info like this
I syntaxnet/term_frequency_map.cc:101] Loaded 46 terms from syntaxnet/models/parsey_mcparseface/label-map.
I syntaxnet/embedding_feature_extractor.cc:35] Features: input.digit input.hyphen; input.prefix(length="2") input(1).prefix(length="2") input(2).prefix(length="2") input(3).prefix(length="2") input(-1).prefix(length="2") input(-2).prefix(length="2") input(-3).prefix(length="2") input(-4).prefix(length="2"); input.prefix(length="3") input(1).prefix(length="3") input(2).prefix(length="3") input(3).prefix(length="3") input(-1).prefix(length="3") input(-2).prefix(length="3") input(-3).prefix(length="3") input(-4).prefix(length="3"); input.suffix(length="2") input(1).suffix(length="2") input(2).suffix(length="2") input(3).suffix(length="2") input(-1).suffix(length="2") input(-2).suffix(length="2") input(-3).suffix(length="2") input(-4).suffix(length="2"); input.suffix(length="3") input(1).suffix(length="3") input(2).suffix(length="3") input(3).suffix(length="3") input(-1).suffix(length="3") input(-2).suffix(length="3") input(-3).suffix(length="3") input(-4).suffix(length="3"); input.token.word input(1).token.word input(2).token.word input(3).token.word input(-1).token.word input(-2).token.word input(-3).token.word input(-4).token.word
I syntaxnet/embedding_feature_extractor.cc:36] Embedding names: other;prefix2;prefix3;suffix2;suffix3;words
I syntaxnet/embedding_feature_extractor.cc:37] Embedding dims: 8;16;16;16;16;64
I syntaxnet/term_frequency_map.cc:101] Loaded 64036 terms from syntaxnet/models/parsey_mcparseface/word-map.
I syntaxnet/term_frequency_map.cc:101] Loaded 49 terms from syntaxnet/models/parsey_mcparseface/tag-map.
INFO:tensorflow:Building training network with parameters: feature_sizes: [2 8 8 8 8 8] domain_sizes: [ 5 10665 10665 8970 8970 64038]
I syntaxnet/term_frequency_map.cc:101] Loaded 49 terms from syntaxnet/models/parsey_mcparseface/tag-map.
I syntaxnet/term_frequency_map.cc:101] Loaded 46 terms from syntaxnet/models/parsey_mcparseface/label-map.
I syntaxnet/embedding_feature_extractor.cc:35] Features: input.digit input.hyphen; input.prefix(length="2") input(1).prefix(length="2") input(2).prefix(length="2") input(3).prefix(length="2") input(-1).prefix(length="2") input(-2).prefix(length="2") input(-3).prefix(length="2") input(-4).prefix(length="2"); input.prefix(length="3") input(1).prefix(length="3") input(2).prefix(length="3") input(3).prefix(length="3") input(-1).prefix(length="3") input(-2).prefix(length="3") input(-3).prefix(length="3") input(-4).prefix(length="3"); input.suffix(length="2") input(1).suffix(length="2") input(2).suffix(length="2") input(3).suffix(length="2") input(-1).suffix(length="2") input(-2).suffix(length="2") input(-3).suffix(length="2") input(-4).suffix(length="2"); input.suffix(length="3") input(1).suffix(length="3") input(2).suffix(length="3") input(3).suffix(length="3") input(-1).suffix(length="3") input(-2).suffix(length="3") input(-3).suffix(length="3") input(-4).suffix(length="3"); input.token.word input(1).token.word input(2).token.word input(3).token.word input(-1).token.word input(-2).token.word input(-3).token.word input(-4).token.word
I syntaxnet/embedding_feature_extractor.cc:36] Embedding names: other;prefix2;prefix3;suffix2;suffix3;words
I syntaxnet/embedding_feature_extractor.cc:37] Embedding dims: 8;16;16;16;16;64
I syntaxnet/term_frequency_map.cc:101] Loaded 64036 terms from syntaxnet/models/parsey_mcparseface/word-map.
INFO:tensorflow:Processed 1 documents
and remove this
INFO:tensorflow:Total processed documents: 1
INFO:tensorflow:num correct tokens: 0
INFO:tensorflow:total tokens: 7
INFO:tensorflow:Seconds elapsed in evaluation: 0.07, eval metric: 0.00%
Is possible to customize the output?
@ColinUNCG AFAIK this is not possible using stdout as output but if you ouput to file it will contain only the POS tags
@afgiel
Thanks. I will try to ouput to file
@ColinUNCG It is possible to just output the POS tagged words to file or terminal.
Keep demo.sh as
[[ "$1" == "--conll" ]] && INPUT_FORMAT=stdin-conll || INPUT_FORMAT=stdin
$PARSER_EVAL
--input=${INPUT_FORMAT}
--output=stdout-conll
--hidden_layer_sizes=128
--arg_prefix=brain_pos
--graph_builder=greedy
--task_context=${MODEL_DIR}/context.pbtxt
--model_path=${MODEL_DIR}/tagger-params
--slim_model
--batch_size=1024
--alsologtostderr
@prakhar21 Thanks man. but I got this error with your code
any thoughts?
I syntaxnet/term_frequency_map.cc:101] Loaded 46 terms from syntaxnet/models/parsey_mcparseface/label-map.
I syntaxnet/embedding_feature_extractor.cc:35] Features:
I syntaxnet/embedding_feature_extractor.cc:36] Embedding names:
I syntaxnet/embedding_feature_extractor.cc:37] Embedding dims:
INFO:tensorflow:Building training network with parameters: feature_sizes: [] domain_sizes: []
Traceback (most recent call last):
File "/Users/Colin/models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/syntaxnet/parser_eval.py", line 149, in <module>
tf.app.run()
File "/Users/Colin/models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/external/tf/tensorflow/python/platform/app.py", line 30, in run
sys.exit(main(sys.argv))
File "/Users/Colin/models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/syntaxnet/parser_eval.py", line 145, in main
Eval(sess, num_actions, feature_sizes, domain_sizes, embedding_dims)
File "/Users/Colin/models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/syntaxnet/parser_eval.py", line 94, in Eval
evaluation_max_steps=FLAGS.max_steps)
File "/Users/Colin/models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/syntaxnet/graph_builder.py", line 444, in AddEvaluation
'transition_scores'], corpus_name))
File "/Users/Colin/models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/syntaxnet/graph_builder.py", line 396, in _AddDecodedReader
arg_prefix=self._arg_prefix))
File "/Users/Colin/models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/syntaxnet/ops/gen_parser_ops.py", line 203, in decoded_parse_reader
arg_prefix=arg_prefix, name=name)
File "/Users/Colin/models/syntaxnet/bazel-bin/syntaxnet/parser_eval.runfiles/external/tf/tensorflow/python/ops/op_def_library.py", line 617, in apply_op
(key, op_type_name, attr_value.i, attr_def.minimum))
ValueError: Attr 'feature_size' of 'DecodedParseReader' Op passed 0 less than minimum 1.
Just say ech "hello world" | syntaxnet/demo.sh 2>/dev/null. Then you output will be what you are expecting:
1 hello _ X UH _ 0 ROOT _ _ 2 world _ NOUN NN _ 1 dep _ _
