日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Stanford NER CRF FAQ

發布時間:2024/3/12 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Stanford NER CRF FAQ 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原網頁http://nlp.stanford.edu/software/crf-faq.html

  • 1.我能夠訓練自己的NER模型么?
  • 2.我可以使用盡量少的內存來訓練NER模型么?
  • 3.我如何從多個文件中訓練一個模型?
  • 4.在程序中使用CRFClassifier,API是什么?
  • 5.我可以設置斯坦福NER系統,允許單個jar部署,而不是必須從分離的多個文件加載NER模型?
  • 6.對于我們的web 5.0系統,我能夠運行Stanford NER作為一個server/service/servlet?
  • 7.有哪些選項可用于格式化分類器的輸出?
  • 8.為什么我無法重現您的CoNLL 2003系統的結果? 或者:我如何使用CoNLL 2003在英語上獲得更好的性能?
  • 9.如何讓德語NER工作正常? 我對字符編碼理解不深。
  • 10.什么是分類器的漸進內存增長?
  • 11.現有的模型可以擴展么?
  • 12.你可以發布用于構建公開發布的模型的數據么?
  • 13.NER結果是確定性的嗎? 為什么同一數據的結果會發生變化?
  • 14.如何NER標記已分詞的文本?
  • 15.什么選項可用于文本輸入處理?
  • 16.NER是否使用詞性標簽?
  • 17.我如何在Stanford NER的幫助下使用gazette?
  • 18.斯坦福NER可以與Solr集成么?

這里僅僅先只對第一個大致翻譯
你應該至少瀏覽CRFClassifier 和 NERFeatureFactory類的javaDoc。
訓練數據應該是使用tab鍵分隔的列,至少要有兩列,單詞一列,單詞的類別標簽一列。
新建jane-austen-emma-ch1.txt文件(將下面內容粘貼進去),或者直接下載從http://nlp.stanford.edu/software/ner-example/jane-austen-emma-ch1.txt

CHAPTER IEmma Woodhouse handsome clever and rich with a comfortable home and happy disposition seemed to unite some of the best blessings of existence and had lived nearly twenty one years in the world with very little to distress or vex her She was the youngest of the two daughters of a most affectionate indulgent father and had in consequence of her sister's marriage been mistress of his house from a very early period Her mother had died too long ago for her to have more than an indistinct remembrance of her caresses and her place had been supplied by an excellent woman as governess who had fallen little short of a mother in affection Sixteen years had Miss Taylor been in Mr Woodhouse's family less as a governess than a friend very fond of both daughters but particularly of Emma Between them it was more the intimacy of sisters Even before Miss Taylor had ceased to hold the nominal office of governess the mildness of her temper had hardly allowed her to impose any restraint and the shadow of authority being now long passed away they had been living together as friend and friend very mutually attached and Emma doing just what she liked highly esteeming Miss Taylor's judgment but directed chiefly by her own The real evils indeed of Emma's situation were the power of having rather too much her own way and a disposition to think a little too well of herself these were the disadvantages which threatened alloy to her many enjoyments The danger however was at present so unperceived that they did not by any means rank as misfortunes with her Sorrow came a gentle sorrow but not at all in the shape of any disagreeable consciousness Miss Taylor married It was Miss Taylor's loss which first brought grief It was on the wedding day of this beloved friend that Emma first sat in mournful thought of any continuance The wedding over and the bride people gone her father and herself were left to dine together with no prospect of a third to cheer a long evening Her father composed himself to sleep after dinner as usual and she had then only to sit and think of what she had lost The event had every promise of happiness for her friend Mr Weston was a man of unexceptionable character easy fortune suitable age and pleasant manners and there was some satisfaction in considering with what self denying generous friendship she had always wished and promoted the match but it was a black morning's work for her The want of Miss Taylor would be felt every hour of every day She recalled her past kindness the kindness the affection of sixteen years how she had taught and how she had played with her from five years old how she had devoted all her powers to attach and amuse her in health and how nursed her through the various illnesses of childhood A large debt of gratitude was owing here but the intercourse of the last seven years the equal footing and perfect unreserve which had soon followed Isabella's marriage on their being left to each other was yet a dearer tenderer recollection She had been a friend and companion such as few possessed intelligent well informed useful gentle knowing all the ways of the family interested in all its concerns and peculiarly interested in herself in every pleasure every scheme of hers one to whom she could speak every thought as it arose and who had such an affection for her as could never find fault How was she to bear the change It was true that her friend was going only half a mile from them but Emma was aware that great must be the difference between a Mrs Weston only half a mile from them and a Miss Taylor in the house and with all her advantages natural and domestic she was now in great danger of suffering from intellectual solitude She dearly loved her father but he was no companion for her He could not meet her in conversation rational or playful The evil of the actual disparity in their ages and Mr Woodhouse had not married early was much increased by his constitution and habits for having been a valetudinarian all his life without activity of mind or body he was a much older man in ways than in years and though everywhere beloved for the friendliness of his heart and his amiable temper his talents could not have recommended him at any time Her sister though comparatively but little removed by matrimony being settled in London only sixteen miles off was much beyond her daily reach and many a long October and November evening must be struggled through at Hartfield before Christmas brought the next visit from Isabella and her husband and their little children to fill the house and give her pleasant society again Highbury the large and populous village almost amounting to a town to which Hartfield in spite of its separate lawn and shrubberies and name did really belong afforded her no equals The Woodhouses were first in consequence there All looked up to them She had many acquaintance in the place for her father was universally civil but not one among them who could be accepted in lieu of Miss Taylor for even half a day It was a melancholy change and Emma could not but sigh over it and wish for impossible things till her father awoke and made it necessary to be cheerful His spirits required support He was a nervous man easily depressed fond of every body that he was used to and hating to part with them hating change of every kind Matrimony as the origin of change was always disagreeable and he was by no means yet reconciled to his own daughter's marrying nor could ever speak of her but with compassion though it had been entirely a match of affection when he was now obliged to part with Miss Taylor too and from his habits of gentle selfishness and of being never able to suppose that other people could feel differently from himself he was very much disposed to think Miss Taylor had done as sad a thing for herself as for them and would have been a great deal happier if she had spent all the rest of her life at Hartfield Emma smiled and chatted as cheerfully as she could to keep him from such thoughts but when tea came it was impossible for him not to say exactly as he had said at dinnerPoor Miss Taylor I wish she were here again What a pity it is that Mr Weston ever thought of herI cannot agree with you papa you know I cannot Mr Weston is such a good humoured pleasant excellent man that he thoroughly deserves a good wife and you would not have had Miss Taylor live with us for ever and bear all my odd humours when she might have a house of her ownA house of her own But where is the advantage of a house of her own This is three times as large And you have never any odd humours my dearHow often we shall be going to see them and they coming to see us We shall be always meeting We must begin we must go and pay wedding visit very soonMy dear how am I to get so far Randalls is such a distance I could not walk half so farNo papa nobody thought of your walking We must go in the carriage to be sureThe carriage But James will not like to put the horses to for such a little way and where are the poor horses to be while we are paying our visitThey are to be put into Mr Weston's stable papa You know we have settled all that already We talked it all over with Mr Weston last night And as for James you may be very sure he will always like going to Randalls because of his daughter's being housemaid there I only doubt whether he will ever take us anywhere else That was your doing papa You got Hannah that good place Nobody thought of Hannah till you mentioned her James is so obliged to youI am very glad I did think of her It was very lucky for I would not have had poor James think himself slighted upon any account and I am sure she will make a very good servant she is a civil pretty spoken girl I have a great opinion of her Whenever I see her she always curtseys and asks me how I do in a very pretty manner and when you have had her here to do needlework I observe she always turns the lock of the door the right way and never bangs it I am sure she will be an excellent servant and it will be a great comfort to poor Miss Taylor to have somebody about her that she is used to see Whenever James goes over to see his daughter you know she will be hearing of us He will be able to tell her how we all areEmma spared no exertions to maintain this happier flow of ideas and hoped by the help of backgammon to get her father tolerably through the evening and be attacked by no regrets but her own The backgammon table was placed but a visitor immediately afterwards walked in and made it unnecessary Mr Knightley a sensible man about seven or eight and thirty was not only a very old and intimate friend of the family but particularly connected with it as the elder brother of Isabella's husband He lived about a mile from Highbury was a frequent visitor and always welcome and at this time more welcome than usual as coming directly from their mutual connexions in London He had returned to a late dinner after some days absence and now walked up to Hartfield to say that all were well in Brunswick Square It was a happy circumstance and animated Mr Woodhouse for some time Mr Knightley had a cheerful manner which always did him good and his many inquiries after poor Isabella and her children were answered most satisfactorily When this was over Mr Woodhouse gratefully observed It is very kind of you Mr Knightley to come out at this late hour to call upon us I am afraid you must have had a shocking walkNot at all sir It is a beautiful moonlight night and so mild that I must draw back from your great fireBut you must have found it very damp and dirty I wish you may not catch coldDirty sir Look at my shoes Not a speck on themWell that is quite surprising for we have had a vast deal of rain here It rained dreadfully hard for half an hour while we were at breakfast I wanted them to put off the weddingBy the bye I have not wished you joy Being pretty well aware of what sort of joy you must both be feeling I have been in no hurry with my congratulations but I hope it all went off tolerably well How did you all behave Who cried mostAh poor Miss Taylor Tis a sad businessPoor Mr and Miss Woodhouse if you please but I cannot possibly say poor Miss Taylor I have a great regard for you and Emma but when it comes to the question of dependence or independence At any rate it must be better to have only one to please than twoEspecially when one of those two is such a fanciful troublesome creature said Emma playfully That is what you have in your head I know and what you would certainly say if my father were not byI believe it is very true my dear indeed said Mr Woodhouse with a sigh I am afraid I am sometimes very fanciful and troublesomeMy dearest papa You do not think I could mean you or suppose Mr Knightley to mean you What a horrible idea Oh no I meant only myself Mr Knightley loves to find fault with me you know in a joke it is all a joke We always say what we like to one anotherMr Knightley in fact was one of the few people who could see faults in Emma Woodhouse and the only one who ever told her of them and though this was not particularly agreeable to Emma herself she knew it would be so much less so to her father that she would not have him really suspect such a circumstance as her not being thought perfect by every body Emma knows I never flatter her said Mr Knightley but I meant no reflection on any body Miss Taylor has been used to have two persons to please she will now have but one The chances are that she must be a gainerWell said Emma willing to let it pass you want to hear about the wedding and I shall be happy to tell you for we all behaved charmingly Every body was punctual every body in their best looks not a tear and hardly a long face to be seen Oh no we all felt that we were going to be only half a mile apart and were sure of meeting every dayDear Emma bears every thing so well said her father But Mr Knightley she is really very sorry to lose poor Miss Taylor and I am sure she will miss her more than she thinks forEmma turned away her head divided between tears and smiles It is impossible that Emma should not miss such a companion said Mr Knightley We should not like her so well as we do sir if we could suppose it but she knows how much the marriage is to Miss Taylor's advantage she knows how very acceptable it must be at Miss Taylor's time of life to be settled in a home of her own and how important to her to be secure of a comfortable provision and therefore cannot allow herself to feel so much pain as pleasure Every friend of Miss Taylor must be glad to have her so happily marriedAnd you have forgotten one matter of joy to me said Emma and a very considerable one that I made the match myself I made the match you know four years ago and to have it take place and be proved in the right when so many people said Mr Weston would never marry again may comfort me for any thingMr Knightley shook his head at her Her father fondly replied Ah my dear I wish you would not make matches and foretell things for whatever you say always comes to pass Pray do not make any more matchesI promise you to make none for myself papa but I must indeed for other people It is the greatest amusement in the world And after such success you know Every body said that Mr Weston would never marry again Oh dear no Mr Weston who had been a widower so long and who seemed so perfectly comfortable without a wife so constantly occupied either in his business in town or among his friends here always acceptable wherever he went always cheerful Mr Weston need not spend a single evening in the year alone if he did not like it Oh no Mr Weston certainly would never marry again Some people even talked of a promise to his wife on her deathbed and others of the son and the uncle not letting him All manner of solemn nonsense was talked on the subject but I believed none of it Ever since the day about four years ago that Miss Taylor and I met with him in Broadway Lane when because it began to drizzle he darted away with so much gallantry and borrowed two umbrellas for us from Farmer Mitchell's I made up my mind on the subject I planned the match from that hour and when such success has blessed me in this instance dear papa you cannot think that I shall leave off match makingI do not understand what you mean by success said Mr Knightley Success supposes endeavour Your time has been properly and delicately spent if you have been endeavouring for the last four years to bring about this marriage A worthy employment for a young lady's mind But if which I rather imagine your making the match as you call it means only your planning it your saying to yourself one idle day I think it would be a very good thing for Miss Taylor if Mr Weston were to marry her and saying it again to yourself every now and then afterwards why do you talk of success Where is your merit What are you proud of You made a lucky guess and that is all that can be saidAnd have you never known the pleasure and triumph of a lucky guess I pity you I thought you cleverer for depend upon it a lucky guess is never merely luck There is always some talent in it And as to my poor word success which you quarrel with I do not know that I am so entirely without any claim to it You have drawn two pretty pictures but I think there may be a third a something between the do nothing and the do all If I had not promoted Mr Weston's visits here and given many little encouragements and smoothed many little matters it might not have come to any thing after all I think you must know Hartfield enough to comprehend thatA straightforward open hearted man like Weston and a rational unaffected woman like Miss Taylor may be safely left to manage their own concerns You are more likely to have done harm to yourself than good to them by interferenceEmma never thinks of herself if she can do good to others rejoined Mr Woodhouse understanding but in part But my dear pray do not make any more matches they are silly things and break up one's family circle grievouslyOnly one more papa only for Mr Elton Poor Mr Elton You like Mr Elton papa I must look about for a wife for him There is nobody in Highbury who deserves him and he has been here a whole year and has fitted up his house so comfortably that it would be a shame to have him single any longer and I thought when he was joining their hands to day he looked so very much as if he would like to have the same kind office done for him I think very well of Mr Elton and this is the only way I have of doing him a serviceMr Elton is a very pretty young man to be sure and a very good young man and I have a great regard for him But if you want to shew him any attention my dear ask him to come and dine with us some day That will be a much better thing I dare say Mr Knightley will be so kind as to meet himWith a great deal of pleasure sir at any time said Mr Knightley laughing and I agree with you entirely that it will be a much better thing Invite him to dinner Emma and help him to the best of the fish and the chicken but leave him to chuse his own wife Depend upon it a man of six or seven and twenty can take care of himself

然后,You can convert it to one token per line with our tokenizer (included in the box) with the following command:

java -cp stanford-ner.jar edu.stanford.nlp.process.PTBTokenizer jane-austen-emma-ch1.txt > jane-austen-emma-ch1.tok

運行完成此命令之后,你可以看到生成了一個jane-austen-emma-ch1.tok文件,此文件的每一行均只有一個單詞。
然后需要對訓練數據進行實體標記,有多種工具可以使用。可以使用文本文檔工具進行手工標記。由于內容太多,可以使用程序對每一行加上制表符(tab)和0,perl的代碼如下;然后,再使用文本文檔編輯器,對特殊的行進行手工修改標記。
運行下面命令產生jane-austen-emma-ch1.tsv文件(每一行均加上’\t0’字符串)

perl -ne 'chomp; print "$_\tO\n"' jane-austen-emma-ch1.tok > jane-austen-emma-ch1.tsv

如果你不想做上述步驟,可以從這個鏈接下載tsv文件http://nlp.stanford.edu/software/ner-example/jane-austen-emma-ch1.tsv
我們僅僅標注了一個實體類型——用“PERS”表示人名;但是,你可以在這個數據中加入第二種實體類型,如地理位置“LOC”。你應該確定每行僅僅只包括內容字段和制表符(tab),空格也不能有,額外的制表符(tab)也不能有,否則訓練文件解析器可能會出錯。一個空行分隔兩個“document”,一個“document”只能是一個句子,或者更大一點兒的單元,如段落;這是CRF推斷的單位。“document”不能太大,否則你將浪費許多內存,并且還可能碰到很多問題。你仍然可以使用一些測試數據去判斷系統是否可以良好運行,這里有jane-austen-emma-ch2.txt(http://nlp.stanford.edu/software/ner-example/jane-austen-emma-ch2.txt)和jane-austen-emma-ch2.tsv(http://nlp.stanford.edu/software/ner-example/jane-austen-emma-ch2.tsv)

新建austen.prop屬性文件

#location of the training file trainFile = jane-austen-emma-ch1.tsv #location where you would like to save (serialize to) your #classifier; adding .gz at the end automatically gzips the file, #making it faster and smaller 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#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 useNGrams=true #no ngrams will be included that do not contain either the #beginning or end of the word noMidNGrams=true useDisjunctive=true maxNGramLeng=6 usePrev=true useNext=true useSequences=true usePrevSequences=true maxLeft=1 #the next 4 deal with word shape features useTypeSeqs=true useTypeSeqs2=true useTypeySequences=true wordShape=chris2useLC

然后用下面的命令訓練一個分類器

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

一旦完成上述命令。將產生一個NER模型文件ner-model.ser.gz,判斷它是否有效,使用下面命令來測試

java -cp stanford-ner.jar edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier ner-model.ser.gz -testFile jane-austen-emma-ch2.tsv

最后得到的結果如下

可以看到第一列是作為輸入項的單詞列,第二列是正確標注的結果,第三類是由Stanford NER猜的結果。你能夠發現此分類器發現了大多數的人名實體,但不是全部的。主要是因為訓練數據比較少,而且這只是一個相對基本的特征集。代碼最后評估出實體精確分類的性能,用recall(召回率)表示,用符號F1代表。最后的結果F1是85.95%.(不知道為什么我的是77.11%)


所以訓練自己的NER模型步驟是:
1)訓練數據的源數據
2)指定了你想用的屬性的屬性文件(這個是可選的,但是有最好)
3)測試文件
對于訓練數據的源數據,需要保證每一個單詞占據一行,并且附有正確答案(單詞與答案之間使用制表符分隔開)。如果要明確指定單詞的更多特征,可以將這些特征添加到文件的新列中,然后在屬性文件的map 行中設置適當結構。例如,如果你的數據中添加了第三列表示新的特征,則可以寫成“map = word = 0,answer = 1,mySpecialFeature = 2”。

Right now, most arbitrarily named features (like mySpecialFeature) will not work without making modifications to the source code. To see which features can already be attached to a CoreLabel, look at edu.stanford.nlp.ling.AnnotationLookup. There is a table which creates a mapping between key and annotation type. For example, if you search in this file for LEMMA_KEY, you will see that lemma produces a LemmaAnnotation. If you have added a new annotation, you can add its type to this table, or you can use one of the known names that already work, like tag, lemma, chunk, web.

If you modify AnnotationLookup, you need to read the data from the column, translate it to the desired object type, and attach it to the CoreLabel using a CoreAnnotation. Quite a few CoreAnnotations are provided in the class appropriately called CoreAnnotations. If the particular one you are looking for is not present, you can add a new subclass by using one of the existing CoreAnnotations as an example.

If the feature you attached to the CoreLabel is not already used as a feature in NERFeatureFactory, you will need to add code that extracts the feature from the CoreLabel and adds it to the feature set. Bear in mind that features must have unique names, or they will conflict with existing features, which is why we add markers such as “-GENIA”, “-PGENIA”, and “-NGENIA” to our features. As long as you choose a unique marker, the feature itself can be any string followed by its marker and will not conflict with any existing features. Processing is done using a bag of features model, with all of the features mixed together, which is why it is important to not have any name conflicts.

Once you’ve annotated your data, you make a properties file with the features you want. You can use the example properties file, and refer to the NERFeatureFactory for more possible features. Finally, you can test on your annotated test data as shown above or annotate more text using the -textFile command rather than -testFile.

備用:在上文中提到了使用perl語言,對文本文檔的每一行后面添加一個tab鍵與0,不僅僅可以使用編程語言perl,python等來完成這樣的步驟,其實還有一個更簡單的方法,使用sublime text,或者notepad++等這樣的文本編輯軟件,也可以達到目的。
????給每行首部位置加上內容,用sublime text打開文本文檔文件之后,菜單find—replace,打開替換功能,先勾選替換框下部的模式為正則表達式(Regular Expression),在“查找目標”(Find what)處輸入^,在“替換為”(Replace with)處輸入想要添加的內容,最后點擊按鈕“replace all”即可。
????給每行尾部位置加上內容,一樣的步驟,在“查找目標”(Find what)處輸入$,后面一樣。通過這種文本編輯軟件來進行處理,速度更快!

總結

以上是生活随笔為你收集整理的Stanford NER CRF FAQ的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。