這篇文章主要介紹“OpenNLP的Name Finder怎么使用”,在日常操作中,相信很多人在OpenNLP的Name Finder怎么使用問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”OpenNLP的Name Finder怎么使用”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
##Named Entity Recognition 命令實體識別## Name Finder可以檢測文本中的命名實體和數字。要檢測實體,Name Finder需要一個模型。模型依賴于它訓練的語言和實體類型。OpenNlP提供了許多預訓練的name finder模型,他們使用各種各樣可以免費得到的語料庫訓練。他們可以在我們的模型下載頁面下載。在未經處理的(raw)文本中發現names,這個文本必須被分割成tokens和Sentences。在Sentence detector和tokenizer 入門中給出了詳細的描述。確保用于訓練的tokenization數據和輸入文本是相同的。
###Name Finder Tool### ###Name Finder API### 在一個生產系統中使用Name Finder,強烈推薦直接嵌入它到應用程序中,而不是使用命令行接口。首先,必須從磁盤或者其他源加載name finder模型。下面的示例實在磁盤加載的.
InputStream modelIn = new FileInputStream("en-ner-person.bin");
try {
TokenNameFinderModel model = new TokenNameFinderModel(modelIn);
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if (modelIn != null) {
try {
modelIn.close();
}
catch (IOException e) {
}
}
}有許多原因會導致模型加載失?。?/p>
基本的I/O問題
模型的版本和OpenNLP版本不兼容
模型加載到錯誤的組件,例如,一個tokenizer模型加載到TokenNameFinderModel類
由于其他一些原因模型內容不可用
在模型加載后,NameFinderME可以實例化。
NameFinderME nameFinder = new NameFinderME(model);
初始化現在完成,Name Finder現在可以使用。NameFinderME不是線程安全的,他必須只在一個線程中調用。要使用多線程多NameFinderME實例共享可以創建相同的模型實例。輸入本文必須切分成documents,sentences,和tokens。應用程序調用find方法在文檔中的每一個sentence中執行實體檢測。After every document clearAdaptiveData must be called to clear the adaptive data in the feature generators.Not calling clearAdaptiveData can lead to a sharp drop in the detection rate after a few documents. 下面的代碼解釋了這個:
for (String document[][] : documents) {
for (String[] sentence : document) {
Span nameSpans[] = nameFinder.find(sentence);
// do something with the names
}
nameFinder.clearAdaptiveData()
}下面的片段展示了find的一個調用:
String sentence[] = new String[]{
"Pierre",
"Vinken",
"is",
"61",
"years"
"old",
"."
};
Span nameSpans[] = nameFinder.find(sentence);到此,關于“OpenNLP的Name Finder怎么使用”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。