2016-06-28 1 views
3

を使用してNERモデルを訓練し、私はここにチュートリアルLINKに示すようにpropetyファイルを使用して、私のNERモデルを訓練してきています。私は同じpropファイルを使用していますが、プログラム的に行う方法については理解していません。以下に示すようにはプログラムによる.propファイル

props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, sentiment, regexner"); 
props.setProperty("ner.model", "resources/NER.prop"); 

小道具ファイルは次のとおりです。

# location of the training file 
trainFile = nerTEST.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 = resources/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 

エラー:

java.io.StreamCorruptedException: invalid stream header: 23206C6F 
.... 
.. 
Caused by: java.io.IOException: Couldn't load classifier from resources/NER.prop 

SO上の別の質問から、私はあなたが直接モデルファイルを提供し理解しています。しかし、どのようにプロパティファイルの助けを借りてそれを行うことができますか?

答えて

2

あなたは、コマンドラインからこのコマンドを実行する必要があります

java -cp "*" edu.stanford.nlp.ie.crf.CRFClassifier -prop NER.prop 

Javaコードでこれを実行したい場合、あなたはこのような何か行うことができます:

String[] args = new String[]{"-props", "NER.prop"}; 
CRFClassifier.main(args); 

に.propファイルをありますモデルをトレーニングするための設定を指定するファイル。コードがエラーの原因となっているモデル自体として.propファイルを読み込もうとしています。いずれかを行う

私はよくある質問から理解リソース/ NER-model.ser.gz

+0

これで、最終的なモデルを生成します。しかし、どのようにプロパティファイルからそのモデルファイルを生成できますか? – Betafish

+0

作成した.propファイルで指定されたとおりにコマンドを実行すると、モデルはresources/ner-model.ser.gzに保存されます... JavaコードのCRFClassifierのメインメソッド()も呼び出すことができますお勧めしていません – StanfordNLPHelp

1
public class TrainModel { 
private void trainCrf(String serializeFile, String prop) { 
    Properties props = StringUtils.propFileToProperties(prop); 
    props.setProperty("serializeTo", serializeFile); 
    SeqClassifierFlags flags = new SeqClassifierFlags(props); 
    CRFClassifier<CoreLabel> crf = new CRFClassifier<>(flags); 
    crf.train(); 
    crf.serializeClassifier(serializeFile); 
} 

public static void main(String[] args) { 

    String serializeFile = "skill/ner-model.ser.gz"; 
    String prop = "ner.props"; 
    TrainModel trainModel = new TrainModel(); 
    trainModel.trainCrf(serializeFile, prop); 
} 

}

+0

ありがとう....それは働いた。 – ELITE

関連する問題