2016-11-22 4 views
0

models/syntaxnet/$ echo "sentence to parse" | ./syntaxnet/demo.sh을 실행할 때 특정 텐서는 "구문 분석 할 문장"을 수신합니까?SyntaxNet : parser_eval.py가 어떻게 표준을 수신합니까?

다른 대화식 작업을 돕기 위해 SyntaxNet 서버 (AWS, django)를 만들었습니다. 서버에 문장 쿼리를 보낼 때마다 문장을 파싱하는 데 약 3.5 초가 걸립니다.

이것은 내 작업에 충분히 빠르지 않습니다. 그래서 병목 현상이있는 곳을 찾으려고 노력했습니다. import tensorflow as tf은 0.8 초가 걸리고, 매개 변수를로드하고 그래프를 작성하기 전에 SyntaxNet에 두 단계 (POS 태깅 및 구문 분석)가 있으므로 1.6 초 (2 * 0.8 초)가 소요됩니다.

내 서버가 항상 '깨어서'미리로드 된 그래프와 매개 변수로 문장을 파싱 할 수 있기를 원합니다. 그래서 SyntaxNet을 아래와 같이 수정하려고합니다. 세션은 사용자 입력을 input()까지 계속 수신하고 계산 된 텐서를 인쇄하고 절대로 꺼지지 않습니다.

import tensorflow as tf 
def multiplication(sess): 
    x1 = int(input()) 
    matrix1 = tf.constant([[x1, x1]] 
    matrix2 = tf.constant([[2],[2]]) 
    product = sess.run([tf.matmul(matrix1, matrix2)]) 
    return product 
with tf.Session() as sess: 
    while True: 
     print(multiplication(sess)) 
------------------------------------------ 
1 
[array([[4]], dtype=int32)] 
2 
[array([[8]], dtype=int32)] 
3 
[array([[12]], dtype=int32)] 

그러나 input() 부분을 구현할 수 없습니다. 실행할 때 models/syntaxnet/$ echo "sentence to parse" | ./syntaxnet/demo.sh, demo.sh은 어떻게 표준을 수신합니까? 즉, "구문 분석 할 문장"은 어디로 이동합니까? bash 스크립트에 read이 없습니다.

그래서 난 그냥 직접

python bazel-bin/syntaxnet/parser_eval \ 
    --input=stdin \ 
    --output=stdout-conll \ 
    --hidden_layer_sizes=64 \ 
    --arg_prefix=brain_tagger \ 
    --graph_builder=structured \ 
    --task_context=syntaxnet/models/parsey_mcparseface/context.pbtxt \ 
    --model_path=syntaxnet/models/parsey_mcparseface/tagger-params \ 
    --slim_model \ 
    --batch_size=1024 \ 
    --alsologtostderr \ 

에 의해 parser_eval 실행 및 파이썬 파일 syntaxnet/parser_eval.py 입력을받을 않는 경우 찾기 위해 노력했다.

아래 parser.evaluation [documents ']는 어떻게 든 stdin을받습니다.

def Eval(sess): 
... 
... 
    while True: 
    tf_eval_epochs, tf_eval_metrics, tf_documents = sess.run([ 
       parser.evaluation['epochs'], 
       parser.evaluation['eval_metrics'], 
       parser.evaluation['documents'], 
      ]) 

      if len(tf_documents): 
      logging.info('Processed %d documents', len(tf_documents)) 
      num_documents += len(tf_documents) 
      sess.run(sink, feed_dict={sink_documents: tf_documents}) 

      num_tokens += tf_eval_metrics[0] 
      num_correct += tf_eval_metrics[1] 
      if num_epochs is None: 
      num_epochs = tf_eval_epochs 
      elif num_epochs < tf_eval_epochs: 
      break 
... 
... 
def main(unused_argv): 
    print >> sys.stderr, "parser_eval.py main start", time.time() 
    logging.set_verbosity(logging.INFO) 
    temp_counter = 0 

    while True: 
    with tf.Session() as sess: 
     Eval(sess, temp_counter) 
     temp_counter +=1 

if __name__ == '__main__': 
    tf.app.run() 

는 또한 graph_builder.py, gen_parser_ops.py을 추적하지만, 특정 텐서 또는 변수가 아직 표준 입력 선고를 수신하는 찾을 수 없습니다.

SyntaxNet에서 표준 문장을 어디에서받을 수 있는지 설명해주십시오.

관련 질문에 대답 할 수 있다면 도움이 될 것입니다.

    내가 parser_eval.py 내부 while True: 루프를 넣을 수있는 방법을
  • (나는 parser_eval.py에서이 일부 시도하지만 표준 입력 한 번만받습니다.)
  • 도움이 문제를 제공 tensorflow 수 있습니까?

미리 감사드립니다.

+0

이 문제를보고 싶을 수도 있습니다. https://github.com/tensorflow/models/issues/2015 – adrin

답변

0

syntaxnet protoio 패키지에는이 읽기를 수행 할 수있는 유틸리티가 있습니다.