⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.html

📁 Conditional Random Field(CRF)是重要的串学习模型
💻 HTML
📖 第 1 页 / 共 2 页
字号:
     </ul>     <p></p></ul><li>Identifiers for distinguishing relative positions</li><p>You also need to put an identifier in templates when relative positions oftokens must be distinguished. </p><p>In the following case, the macro "%x[-2,1]" and "%x[1,1]" will be replacedinto "DT". But they indicates different "DT".</p><pre>The       DT  B-NPpen       NN  I-NPis        VB  B-VP << CURRENT TOKENa         DT  B-NP</pre><p>To distinguish both two, put an unique identifier (U01: or U02:) in thetemplate:</p><pre>U01:%x[-2,1]U02:%x[1,1]</pre><p>In this case both two templates are regarded as different ones, asthey are expanded into different features, "U01:DT" and "U02:DT".You can use any identifier whatever you like, butit is useful to use numerical numbers to manage them, because they simply correspond to feature IDs.</p><p>If you want to use "bag-of-words" feature, in other words,not to care the relative position of features, You don't need toput such identifiers.</p><li>Example</li><p>Here is the template example for <a href="http://www.cnts.ua.ac.be/conll2000/chunking/">CoNLL 2000</a> shared task and Base-NP chunkingtask. Only one bigram template ('B') is used. This means thatonly  combinations of previous output token and current token areused as bigram features. The lines starting from # or empty lines arediscarded as comments</p><pre># UnigramU00:%x[-2,0]U01:%x[-1,0]U02:%x[0,0]U03:%x[1,0]U04:%x[2,0]U05:%x[-1,0]/%x[0,0]U06:%x[0,0]/%x[1,0]U10:%x[-2,1]U11:%x[-1,1]U12:%x[0,1]qU13:%x[1,1]U14:%x[2,1]U15:%x[-2,1]/%x[-1,1]U16:%x[-1,1]/%x[0,1]U17:%x[0,1]/%x[1,1]U18:%x[1,1]/%x[2,1]U20:%x[-2,1]/%x[-1,1]/%x[0,1]U21:%x[-1,1]/%x[0,1]/%x[1,1]U22:%x[0,1]/%x[1,1]/%x[2,1]# BigramB</pre></ul></ul> <h3><a name="training">Training (encoding)</a></h3> <p>Use <i>crf_learn</i> command:  <pre>% crf_learn template_file train_file model_file</pre><p>where <i>template_file</i> and <i>train_file</i>are the files you need to prepare in advance.<i>crf_learn</i> generates the trained model file in<i>model_file</i>.</p><p>crf_learn outputs the following information.</p><pre>CRF++: Yet Another CRF Tool KitCopyright(C) 2005 Taku Kudo, All rights reserved.reading training data: 100.. 200.. 300.. 400.. 500.. 600.. 700.. 800.. Done! 1.94 sNumber of sentences: 823Number of features:  1075862Number of thread(s): 1Freq:                1eta:                 0.00010C:                   1.00000shrinking size:      20Algorithm:           CRFiter=0 terr=0.99103 serr=1.00000 obj=54318.36623 diff=1.00000iter=1 terr=0.35260 serr=0.98177 obj=44996.53537 diff=0.17161iter=2 terr=0.35260 serr=0.98177 obj=21032.70195 diff=0.53257iter=3 terr=0.23879 serr=0.94532 obj=13642.32067 diff=0.35138iter=4 terr=0.15324 serr=0.88700 obj=8985.70071 diff=0.34134iter=5 terr=0.11605 serr=0.80680 obj=7118.89846 diff=0.20775iter=6 terr=0.09305 serr=0.72175 obj=5531.31015 diff=0.22301iter=7 terr=0.08132 serr=0.68408 obj=4618.24644 diff=0.16507iter=8 terr=0.06228 serr=0.59174 obj=3742.93171 diff=0.18953</pre><ul><li>iter: number of iterations processed</li><li>terr: error rate with respect to tags. (# of error tags/# of all tag)</li><li>serr: error rate with respect to sentences. (# of error sentences/#    of all sentences)</li><li>obj: current object value. When this value converges to a    fixed point, CRF++ stops the iteration.</li><li>diff: relative difference from the previous object value.</li></ul><p>There are 4 major parameters to control the training condition<ul> <li>-a CRF-L2 or CRF-L1:<br>     Changing the regularization algorithm. Default setting is L2.     Generally speaking, L2 performs slightly better than L1, while     the number of non-zero features in L1 is drastically smaller than     that in L2. <li>-c float: <br>     With this option, you can change the hyper-parameter for the CRFs.     With larger C value, CRF tends to overfit to the give training corpus.     This parameter trades the balance between overfitting and     underfitting. The results will significantly be influenced by     this parameter. You can find an optimal value by using     held-out data or more general model selection method such as     cross validation. <li>-f NUM:<br>     This parameter sets the cut-off threshold for the features.     CRF++ uses the features that occurs no less than NUM times     in the given training data. The default value is 1.     When you apply CRF++ to large data, the number of unique features     would amount to several millions. This option is useful in such cases. <li>-p NUM:<br>    If the PC has multiple CPUs, you can make the training faster    by using multi-threading. NUM is the number of threads.</ul><p>Here is the example where these two parameters are used.</p>  <pre>% crf_learn -f 3 -c 1.5 template_file train_file model_file</pre><p>Since version 0.45, CRF++ supports single-best MIRA training. MIRA training is used when -a MIRA option is set.<pre>% crf_learn -a MIRA template train.data modelCRF++: Yet Another CRF Tool KitCopyright(C) 2005 Taku Kudo, All rights reserved.reading training data: 100.. 200.. 300.. 400.. 500.. 600.. 700.. 800.. Done! 1.92 sNumber of sentences: 823Number of features:  1075862Number of thread(s): 1Freq:                1eta:                 0.00010C:                   1.00000shrinking size:      20Algorithm:           MIRAiter=0 terr=0.11381 serr=0.74605 act=823 uact=0 obj=24.13498 kkt=28.00000iter=1 terr=0.04710 serr=0.49818 act=823 uact=0 obj=35.42289 kkt=7.60929iter=2 terr=0.02352 serr=0.30741 act=823 uact=0 obj=41.86775 kkt=5.74464iter=3 terr=0.01836 serr=0.25881 act=823 uact=0 obj=47.29565 kkt=6.64895iter=4 terr=0.01106 serr=0.17011 act=823 uact=0 obj=50.68792 kkt=3.81902iter=5 terr=0.00610 serr=0.10085 act=823 uact=0 obj=52.58096 kkt=3.98915iter=0 terr=0.11381 serr=0.74605 act=823 uact=0 obj=24.13498 kkt=28.00000...</pre><ul><li>iter, terr, serror: same as CRF training</li><li>act: number of active examples in working set</li><li>uact: number of examples whose dual parameters reach soft margin    upper-bound C. 0 uact suggests that given training data was    linear separable</li><li>obj: current object value, ||w||^2</li><li>kkt: max kkt violation value. When it gets 0.0, MIRA training finishes</li></ul><p>There are some parameters to control the MIRA training condition</p><ul> <li>-c float: <br>     Changes soft margin parameter, which is an analogue to the soft margin     parameter C in Support Vector Machines.     The definition is basically the same as -c option in CRF training.     With larger C value, MIRA tends to overfit to the give training     corpus.  <li>-f NUM:<br>     Same as CRF <li>-H NUM:<br>     Changes shrinking size. When a training sentence is not used     in updating parameter vector NUM times, we can consider that the      instance doesn't contribute training any more. MIRA tries to     remove such instances. The process is called     "shrinking". When setting smaller NUM, shrinking occurs in early     stage, which drastically reduces     training time. However, too small NUM is not recommended.     When training finishes, MIRA tries to go through all training      examples again to know whether or not all KKT conditions are really     satisfied. Too small NUM would increase the chances of recheck.</ul><h3><a name="testing">Testing (decoding)</a></h3> <p>Use <i>crf_test</i> command:  <pre>% crf_test -m model_file test_files ...</pre><p>where <i>model_file</i> is the file <i>crf_learn</i>creates.In the testing, you don't need to specify the template file,because the model file has the same information for the template.<i>test_file</i> is the test data you want to assign sequential tags.This file has to be written in the same format as training file.</p><p>Here is an output of <i>crf_test</i>:</p><pre>% crf_test -m model test.dataRockwell        NNP     B       BInternational   NNP     I       ICorp.   NNP     I       I's      POS     B       BTulsa   NNP     I       Iunit    NN      I       I..</pre><p>The last column is given (estimated) tag. If the 3rd column is true answer tag , you can evaluate the accuracy by simply seeing the difference between the 3rd and 4th columns.</p><ul><li>verbose level</li><p>The <b>-v</b> option sets verbose level. defaultvalue is 0. By increasing the level, you can have anextra information from CRF++</p><ul><li>level 1 <br>    You can also have marginal probabilities for each tag    (a kind of confidece measure for each output tag)     and a conditional probably for the output (confidence measure for    the entire output). <pre>% crf_test -v1 -m model test.data| head# 0.478113Rockwell        NNP     B       B/0.992465International   NNP     I       I/0.979089Corp.   NNP     I       I/0.954883's      POS     B       B/0.986396Tulsa   NNP     I       I/0.991966...</pre><p>The first line "# 0.478113" shows the conditional probably for the output.Also, each output tag has a probability represented like "B/0.992465".</p><li>level 2<br><p>You can also have marginal probabilities for all other candidates.</p><pre>% crf_test -v2 -m model test.data# 0.478113Rockwell        NNP     B       B/0.992465      B/0.992465      I/0.00144946    O/0.00608594International   NNP     I       I/0.979089      B/0.0105273     I/0.979089      O/0.0103833Corp.   NNP     I       I/0.954883      B/0.00477976    I/0.954883      O/0.040337's      POS     B       B/0.986396      B/0.986396      I/0.00655976    O/0.00704426Tulsa   NNP     I       I/0.991966      B/0.00787494    I/0.991966      O/0.00015949unit    NN      I       I/0.996169      B/0.00283111    I/0.996169      O/0.000999975..</pre></ul><li>N-best outputs</li><p>With the <b>-n</b> option, you can obtain N-best resultssorted by the conditional probability of CRF. With n-best output mode, CRF++ first gives one additional line like "# N prob", where N means thatrank of the output starting from 0 and prob denotes the conditionalprobability for the output. </p><p>Note that CRF++ sometimesdiscards enumerating N-best results if it cannot find candidates anymore. This is the case when you give CRF++ a shortsentence.</p> <p>CRF++ uses a combination of forward Viterbi and backward A* search. This combinationyields the exact list of n-best results. </p><p>Here is the example of the N-best results. </p><pre>% crf_test -n 20 -m model test.data# 0 0.478113Rockwell        NNP     B       BInternational   NNP     I       ICorp.   NNP     I       I's      POS     B       B...# 1 0.194335Rockwell        NNP     B       BInternational   NNP     I       I</pre></ul></ul><h2><a name="testing">Tips</a></h2> <ul> <li>CRF++ uses the exactly same data format as <a     href="http://chasen.org/~taku/software/yamcha/">YamCha</a> uses.     You may use both two toolkits for an input data and compare the     performance between CRF and SVM <li>The output of CRF++ is also compatible to <a href="http://www.cnts.ua.ac.be/conll2000/chunking/">CoNLL 2000</a> shared task.     This allows us to use the perl script      <a href="http://www.cnts.ua.ac.be/conll2000/chunking/output.html">     conlleval.pl</a> to     evaluate system outputs. This script is very useful and     give us a list of F-measures for all chunk types</ul><h2><a name="training">Case studies</a></h2>  <p> In the example directories, you can find three case studies, baseNP chunking, Text Chunking, and Japanese named entity recognition, to use CRF++.  </p> <p> In each directory, please try the following commands </p> <pre> % crf_learn template train model % crf_test  -m model test </pre><h2><a name="todo">To Do</a></h2>    <ul>     <li>Support <a	 href="http://www-2.cs.cmu.edu/~wcohen/postscript/semiCRF.pdf">semi-Markov	 CRF</a>     <li>Support <a	 href="http://www.cs.umass.edu/~mccallum/papers/lcrf-nips2004.pdf">	 piece-wise CRF</a>     <li>Provide useful C++/C API (Currently no APIs are available)    </ul><h2><a name="links">References</a></h2>    <ul>     <li>J. Lafferty, A. McCallum, and F. Pereira.       <a href="http://www.cis.upenn.edu/~pereira/papers/crf.pdf">Conditional random fields: Probabilistic models for segmenting and      labeling sequence data</a>, In Proc. of ICML, pp.282-289, 2001     <li>F. Sha and F. Pereira. <a      href="http://www.cis.upenn.edu/~feisha/pubs/shallow03.pdf">Shallow      parsing with conditional random fields</a>, In Proc. of HLT/NAACL 2003      <li><a	 href="http://staff.science.uva.nl/~erikt/research/np-chunking.html">NP chunking</a></li>      <li><a href= "http://www.cnts.ua.ac.be/conll2000/chunking/">CoNLL	 2000 shared task: Chunking</a></li>    </ul>    <hr>    <p>$Id: index.html,v 1.23 2003/01/06 13:11:21 taku-ku Exp    $;</p>    <address>      taku@chasen.org    </address>  </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -