2017-05-16 1 views
0

나는 Stanford-NER로 사용자 지정 NER 모델을 교육했습니다. 속성 파일을 만들고 java 명령에 -serverProperties 인수를 사용하여 서버를 시작한 다음 (내 다른 질문 (예 : here 참조)) 사용자 정의 NER 모델 을로드하지만 서버가 내 사용자 정의를로드하려고 시도 할 때을로드합니다. java.io.EOFException: Unexpected end of ZLIB input stream은 다음NER 분류기로드 중 오류 - ZLIB 입력 스트림의 예상치 못한 끝

오류가있는 stderr.log 출력 될 때 : 내가 2007-에서 자바 문제에 관해서입니다 읽은 내용의 오류 대부분을 검색 좀

[main] INFO CoreNLP - --- StanfordCoreNLPServer#main() called --- 
[main] INFO CoreNLP - setting default constituency parser 
[main] INFO CoreNLP - warning: cannot find edu/stanford/nlp/models/srparser/englishSR.ser.gz 
[main] INFO CoreNLP - using: edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz instead 
[main] INFO CoreNLP - to use shift reduce parser download English models jar from: 
[main] INFO CoreNLP - http://stanfordnlp.github.io/CoreNLP/download.html 
[main] INFO CoreNLP -  Threads: 4 
[main] INFO CoreNLP - Liveness server started at /0.0.0.0:9000 
[main] INFO CoreNLP - Starting server... 
[main] INFO CoreNLP - StanfordCoreNLPServer listening at /0.0.0.0:80 
[pool-1-thread-3] INFO CoreNLP - [/127.0.0.1:35546] API call w/annotators tokenize,ssplit,pos,lemma,depparse,natlog,ner,openie 
[pool-1-thread-3] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator tokenize 
[pool-1-thread-3] INFO edu.stanford.nlp.pipeline.TokenizerAnnotator - No tokenizer type provided. Defaulting to PTBTokenizer. 
[pool-1-thread-3] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator ssplit 
[pool-1-thread-3] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator pos 
[pool-1-thread-3] INFO edu.stanford.nlp.tagger.maxent.MaxentTagger - Loading POS tagger from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... done [0.7 sec]. 
[pool-1-thread-3] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator lemma 
[pool-1-thread-3] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator depparse 
[pool-1-thread-3] INFO edu.stanford.nlp.parser.nndep.DependencyParser - Loading depparse model file: edu/stanford/nlp/models/parser/nndep/english_UD.gz ... [pool-1-thread-3] INFO edu.stanford.nlp.parser.nndep.Classifier - PreComputed 99996, Elapsed Time: 12.297 (s) 
[pool-1-thread-3] INFO edu.stanford.nlp.parser.nndep.DependencyParser - Initializing dependency parser ... done [13.6 sec]. 
[pool-1-thread-3] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator natlog 
[pool-1-thread-3] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator ner 
java.io.EOFException: Unexpected end of ZLIB input stream 
    at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:240 
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)  
    at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:117)  
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) 
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) 
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345) 
    at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2620) 
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2636)  
    at java.io.ObjectInputStream$BlockDataInputStream.readDoubles(ObjectInputStream.java:3333) 
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1920) 
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1529) 
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1933) 
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1529) 
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422) 
    at edu.stanford.nlp.ie.crf.CRFClassifier.loadClassifier(CRFClassifier.java:2650) 
    at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1462) 
    at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1494) 
    at edu.stanford.nlp.ie.crf.CRFClassifier.getClassifier(CRFClassifier.java:2963)  
    at edu.stanford.nlp.ie.ClassifierCombiner.loadClassifierFromPath(ClassifierCombiner.java:282) 
    at edu.stanford.nlp.ie.ClassifierCombiner.loadClassifiers(ClassifierCombiner.java:266) 
    at edu.stanford.nlp.ie.ClassifierCombiner.<init>(ClassifierCombiner.java:141) 
    at edu.stanford.nlp.ie.NERClassifierCombiner.<init>(NERClassifierCombiner.java:128)  
    at edu.stanford.nlp.pipeline.AnnotatorImplementations.ner(AnnotatorImplementations.java:121)  
    at edu.stanford.nlp.pipeline.AnnotatorFactories$6.create(AnnotatorFactories.java:273) 
    at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:152) 
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:451)  
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:154) 
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:145) 
    at edu.stanford.nlp.pipeline.StanfordCoreNLPServer.mkStanfordCoreNLP(StanfordCoreNLPServer.java:273)  
    at edu.stanford.nlp.pipeline.StanfordCoreNLPServer.access$500(StanfordCoreNLPServer.java:50)  
    at edu.stanford.nlp.pipeline.StanfordCoreNLPServer$CoreNLPHandler.handle(StanfordCoreNLPServer.java:583)  
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)  
    at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83) 
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)  
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675) 
    at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)  
    at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:748) 

모델은이 오류와 함께 실패 2010 년 EOFException이 "a 우습게 "던져 버렸다. 이 정보는 here입니다.

"는 EOFException는이 일관성이 발생합니다 일부 파일 ((Deflater.BEST_COMPRESSION, TRUE) 새로운 디플렉터를 통해)은 gzip을 사용하고 파일이 올바른 있지만 예외 : EOFException가. 팽창의 끝에서 발생하는 경우, 버그가 있습니다 일부 파일은 던져지고 다른 파일은 그렇지 않습니다. "

이 오류 상태와 관련하여 다른 사람들의 질문에 대답하면 gzip의 출력 스트림을 닫아야합니다 ...? 이것이 의미하는 바가 무엇인지 모를 때 Stanford-NER가 gzip 파일을 만드는 소프트웨어라는 점에서 그 충고를 어떻게 실행해야할지 모르겠다.

질문 :이 오류를 제거하기 위해 취할 수있는 조치는 무엇입니까? 나는 이것이 과거에 다른 사람들에게 일어 났길 바란다. 또한 @StanfordNLPHelp로부터 과거에 제기 된 유사한 문제가 있었는지 및이 문제를 해결하기 위해 CoreNLP 소프트웨어에 수행 된 작업/무언가가 있는지 여부에 대한 피드백을 찾고 있습니다. CoreNLP의 솔루션이 있다면 변경해야하는 파일, CoreNLP 프레임 워크 내에있는 파일의 위치 및 변경해야 할 사항은 무엇입니까?

ADDED 정보 (PER @StanfordNLPHelp 코멘트) :

내 모델은 방향을 사용하여 훈련되었다 here을 발견했다. 모델을 교육하기 위해 나는 약 90 건의 문서의 텍스트가 포함 된 지시 사항에 설명 된대로 TSV를 사용했습니다. 이것은 훈련 할 상당한 양의 데이터가 아니라는 것을 알지만 테스트 단계에 있으며 더 많은 데이터를 수집 할 때 모델을 개선 할 것입니다.

이 TSV 파일과 Standford-NER 소프트웨어를 사용하여 아래 명령을 실행했습니다.

java -cp stanford-ner.jar edu.stanford.nlp.ie.crf.CRFClassifier -prop austen.prop

그때 나는 내 모델을 구축 있었다 심지어로드하고 성공적으로 스탠포드 NER 소프트웨어와 함께 제공되는 NER의 GUI와 텍스트의 큰 신체에 태그를 할 수 있었다.

왜 모델을 작동시키지 못했는지 문제가 발생하는 동안 CoreNLP에서 표준으로 제공되는 "3 클래스 모델"에 대한 파일 경로로 server.properties 파일을 업데이트하려고 시도했습니다. 다시 같은 오류로 실패했습니다.

내 사용자 지정 모델과 3 클래스 모델이 둘 다 Stanford-NER 소프트웨어에서 작동하지만로드하지 못하면 내 사용자 지정 모델이 문제가 아니며 CoreNLP 소프트웨어가로드되는 방식에 문제가 있다는 것을 알 수 있습니다 이 모델들은 -serverProperties 인수를 통해 나타납니다. 아니면 내가 모르는 뭔가 일 수 있습니다.

NER 모델을 학습하는 데 사용한 속성 파일은 열차 파일이 변경된 방향의 켜기 기능과 유사하고 출력 파일 이름이 변경되었습니다. 그것은 다음과 같습니다

# location of the training file 
trainFile = custom-model-trainingfile.tsv 
# location where you would like to save (serialize) your 
# classifier; adding .gz at the end automatically gzips the file, 
# making it smaller, and faster to load 
serializeTo = custome-ner-model.ser.gz 

# structure of your training file; this tells the classifier that 
# the word is in column 0 and the correct answer is in column 1 
map = word=0,answer=1 

# This specifies the order of the CRF: order 1 means that features 
# apply at most to a class pair of previous class and current class 
# or current class and next class. 
maxLeft=1 

# these are the features we'd like to train with 
# some are discussed below, the rest can be 
# understood by looking at NERFeatureFactory 
useClassFeature=true 
useWord=true 
# word character ngrams will be included up to length 6 as prefixes 
# and suffixes only 
useNGrams=true 
noMidNGrams=true 
maxNGramLeng=6 
usePrev=true 
useNext=true 
useDisjunctive=true 
useSequences=true 
usePrevSequences=true 
# the last 4 properties deal with word shape features 
useTypeSeqs=true 
useTypeSeqs2=true 
useTypeySequences=true 
wordShape=chris2useLC 

내 server.properties 파일 나는 또한 시작 스크립트는 $ CLASSPATH 변수에 /path/to/custom_model을 추가 한 줄 ner.model = /path/to/custom_model.ser.gz

가 포함되어 있습니다. 라인 CLASSPATH="$CLASSPATH:$JARCLASSPATH="$CLASSPATH:$JAR:/path/to/custom_model.ser.gz으로 변경했습니다. 내가 ZLIB 오류 메시지가 처음으로 표시되기 때문에 이것이 필요한 단계인지 확실하지 않습니다. 완전성을 위해 이것을 포함하고 싶었습니다.

gunzip custom_model.ser.gz 명령으로 내 사용자 정의 모델을 "gunzip"하려고 시도했지만 모델을로드하려고 할 때와 유사한 오류가 발생했습니다. 그것입니다 gzip: custom_model.ser.gz: unexpected end of file

+0

@ChristopherManning 분명히 CoreNLP에 대해 꽤 많이 알고 있고 오류 관련 질문에 대답하는 경향이 있습니다. 전에 본 적 있어요? –

+0

실제로 훈련 된 모델을 실제로 성공적으로 실행 한 적이 있습니까? 새 ner 모델을 어떻게 훈련했는지에 대한 세부 정보를 제공 할 수 있습니까? 예를 들어 명령 및 특성 파일이 사용 되었습니까? 이런 오류가 발생하면 훈련 된 모델 파일 자체에 문제가 있다고 생각하게됩니다. – StanfordNLPHelp

+0

또한 명령 줄에서 파일을 gunzip'ing 했습니까? 나는 파일이 gzip으로 작동해야한다고 생각하지 않는다. 따라서 gzip으로 압축되지 않은 버전을로드하려고 시도 할 수 있습니다. – StanfordNLPHelp

답변

0

나는 스탠포드 CoreNLP 3.7.0을 다운로드하고 어딘가에 stanford-corenlp-full-2016-10-31라고 폴더를 가지고 있다고 가정합니다. 이 예의 경우 /Users/stanfordnlphelp/stanford-corenlp-full-2016-10-31에 있다고 가정 해 봅시다 (특정 상황으로 변경하십시오)

또한 Java 프로그램을 실행할 때 CLASSPATH에서 컴파일 된 코드 및 리소스를 찾습니다. CLASSPATH을 설정하는 일반적인 방법은 환경 변수를 export 명령으로 설정하는 것입니다.

일반적으로 Java 컴파일 된 코드와 리소스는 jar 파일에 저장됩니다.

stanford-corenlp-full-2016-10-31을 보면 .jar 개의 파일이 표시됩니다. 그 중 하나는 stanford-corenlp-3.7.0-models.jar입니다. 다음 명령을 사용하여 jar 파일 내부의 내용을 볼 수 있습니다 : jar tf stanford-corenlp-3.7.0-models.jar.

다양한 파일 형식이있는 파일을 들여다 보면 알 수 있습니다. 예를 들어, 다음 파일을보아야합니다.

edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz 

(모델 병)

우리가 제대로 작동하게하려면 서버를 실행하고 1 개의 모델 만로드하도록 지정해야합니다 (기본적으로 3을로드하므로).

  1. 실행 (파일 ner-server.properties과 같은 디렉토리에) 하나 개의 창에서 이러한 명령 ner-server.properties이있는 2 라인 파일 인과

    export CLASSPATH=/Users/stanfordnlphelp/stanford-corenlp-full-2016-10-31/*: 
    
    java -Xmx12g edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000 -serverProperties ner-server.properties 
    

이 2 개 라인 :

annotators = tokenize,ssplit,pos,lemma,ner 
ner.model = edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz 

위에 그 디렉토리의 모든 병을 넣어되는 export 명령 . 이것이 바로 *의 의미입니다. 따라서 stanford-corenlp-3.7.0-models.jarCLASSPATH에 있어야합니다. 따라서 Java 코드가 실행되면 edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz을 찾을 수 있습니다.이 실행하면 서버가 어디

wget --post-data 'Joe Smith lives in Hawaii.' 'localhost:9000/?properties={"outputFormat":"json"}' -O - 

, 당신은 (첫 번째 창에 표시되어야합니다

다른 터미널 창에서
  • 발행이 명령

      달리기)이 모델 만이 edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz을로드 중입니다. 당신은 당신이 당신의 파일에서 ner.model을 삭제하고 모든 이들의 재했다면, 3 개 모델은 1

      대신로드 것이라는 점을주의해야한다

      는 모든 작동하는지 여부를 알려 주시기 바랍니다.

      custom_model.ser.gz이라는 NER 모델을 만든 것으로 가정하고 그 파일은 교육 과정 후에 StanfordCoreNLP가 출력 한 파일입니다. 폴더 /Users/stanfordnlphelp/에 넣었다고 가정 해 봅시다. 1 단계와 2 단계 근무

      경우,이에 ner-server.properties을 변경 할 수 있어야한다 :

      annotators = tokenize,ssplit,pos,lemma,ner 
      ner.model = /Users/stanfordnlphelp/custom_model.ser.gz 
      

      을 그리고 당신은 같은 일을 수행 할 때, 그것은 사용자 정의 모델 로딩을 보여줍니다. 어떤 종류의 gzip 문제도 있어서는 안됩니다. 아직 gzip 문제가있는 경우 어떤 시스템을 실행하고 있는지 알려 주시기 바랍니다. 맥 OS X, 유닉스, 윈도우 등 ...?

      그리고 스탠포드 NER 소프트웨어로 맞춤형 NER 모델을 실행했다고 말했습니까? 그렇다면 모델 파일이 정상적으로 들리는 것 같습니다.

  • +0

    사용자 정의 모델을 성공적으로로드 할 수있었습니다. 다른 스택 사이트에서 다른 질문을 통해 한 OS (내 경우에는 Windows)에서 gzip 파일을 만들고 다른 OS (이 경우 Linux)에서 gzip을 활용하려고 할 때 문제가 있음을 알았습니다. 내 Windows 시스템에 내 모델을로드 할 때 오류가 발생하지 않았습니다. ** 가장 큰 테이크 아웃은로드하려는 동일한 OS에서 모델을 만드는 것입니다. ** 상식처럼 보이지만 이제는 알 수 있습니다. 다시 한번 감사드립니다. –

    관련 문제