2016-08-12 63 views
2

我創建使用CoreNLP 3.6.0如何在NER模型上設置空白標記器?

我的道具是一個自定義模式NER:

# location of the training file 
trainFile = /home/damiano/stanford-ner.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 = 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 -classpath "stanford-ner.jar:lib/*" edu.stanford.nlp.ie.crf.CRFClassifier -prop /home/damiano/stanford-ner.prop 

問題是,當我使用這個模型檢索文本文件中的實體。該命令是:

java -classpath "stanford-ner.jar:lib/*" edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier ner-model.ser.gz -textFile file.txt 

file.txt的是:

Hello! 
my 
name 
is 
John. 

輸出是:

你好/ O/O 我/ O/O名稱/ O John/PERSON ./O

正如你可以看到它分裂「你好!」分成兩個令牌。 「約翰」同樣的事情。

我必須使用空格標記器。

我該如何設置?

爲什麼CoreNlp將這些單詞分成兩個令牌?

回答

3

通過指定類名的tokenizerFactory標誌/屬性設置自己的標記生成器:

tokenizerFactory = edu.stanford.nlp.process.WhitespaceTokenizer$WhitespaceTokenizerFactory

您可以指定實現Tokenizer<T>接口的類,但包括WhitespaceTokenizer聽起來像你想要什麼。如果標記生成器有自己的選擇,你可以用tokenizerOptions舉例來說,這裏指定它們,如果還指定了:不

tokenizerOptions = tokenizeNLs=true

(用於然後在輸入新行會在輸入保存輸出選項將東西總是轉換爲每行一個令牌格式)。

注意:像tokenize.whitespace=true這樣的選項適用於CoreNLP級別。如果提供給CRFClassifier等單個組件,則它們不會被解釋(您會收到警告,說該選項被忽略)。

正如Nikita Astrakhantsev所說,這不一定是件好事。如果您的訓練數據也是空白分隔的,但在測試時做它只會是正確的,否則會對性能產生不利影響。並且像從空白分隔中獲得的令牌一樣對後續的NLP處理(如解析)不利。

1

Upd。如果你想在這裏使用空格分詞器,只需將tokenize.whitespace=true添加到你的屬性文件。請看Christopher Manning's answer

然而,回答你的第二個問題,'爲什麼CoreNlp將這些單詞分成兩個單詞?',我建議保留默認分詞器(which is PTBTokenizer),因爲它只是爲了獲得更好的結果。通常,切換到空白標記化的原因是對處理速度或(通常 - 和)對標記化質量的低需求的高要求。 既然你打算將它用於更多的NER,我懷疑它是你的情況。

即使在你的例子中,如果在標記後有令牌John.,它也不能被公報或火車示例捕獲。 更多的細節和原因,爲什麼分詞不那麼簡單可以找到here

相關問題