Hello again,

Ok so the cross-validator needs an empty Map in order not to throw a NPE. The correct method is:

public String cross-validate(String fname, int kFolds){

FileInputStream sampleDataIn = new FileInputStream(fname);
ObjectStream<NameSample> sampleStream = new NameSampleDataStream(
new PlainTextByLineStream( sampleDataIn.getChannel(), "UTF-8"));
TokenNameFinderCrossValidator judge =
new TokenNameFinderCrossValidator("en", null, new TrainingParameters(), null, new HashMap(), null);

judge.evaluate(sampleStream, kFolds);
 FMeasure result = evaluator.getFMeasure();
 return result.toString();

}


However if i try to pass a "NameEvaluationErrorListener" as the last parameter instead of null the cross-validator just hangs before i can do getFMeasure()!!! Actually it hangs right after printing the misclassifications for the last document in the training data...If i leave the listeners parameter as null or with a different listener (e.g TokenNameFinderDetailedFMeasureListener) it works just fine meaning i can get my FMeasure and print it...

Any ideas as to what could be the problem with the NameEvaluationErrorListener which is indeed the most useful listener for cross-validation?

Thanks in advance...

Jim


On 09/03/12 17:34, [email protected] wrote:
Hi,

Although the JavaDoc states that you can pass in a null resource, looks
like it causes the null pointer exception later.

Please try passing an empty map instead of null.

Open a Jira issue so we can improve it.

Thank you,
William

On Thu, Mar 8, 2012 at 6:28 PM, Jim - FooBar();<[email protected]>wrote:

I should clarify that i 'm using the latest code from svn...

Any ideas?



On 08/03/12 16:10, Dimitrios wrote:

Hi everyone,

Can someone please explain why i 'm getting this NPE when trying to use
the TokenNameFinderCrossValidator?
TokenNameFinderEvaluator seems to be working just fine but because i've
got very little training-data i'd like to do cross-validation as well...

*The code is as follows:*

public String cross-validate(String fname, int kFolds){

FileInputStream sampleDataIn = new FileInputStream(fname);
ObjectStream<NameSample>  sampleStream = new NameSampleDataStream(

    new PlainTextByLineStream(

    sampleDataIn.getChannel(), "UTF-8"));
TokenNameFinderCrossValidator judge = new TokenNameFinderCrossValidator(*
*"en",

  null,

  new TrainingParameters(),

  null,

  null,

  null);
  judge.evaluate(sampleStream, kFolds);
  FMeasure result = evaluator.getFMeasure();
  return result.toString();

}

*The exception is thrown right after the first 100 iterations for the
first fold*:

NullPointerException   opennlp.tools.namefind.**TokenNameFinderModel.<init>
(TokenNameFinderModel.java:90)

*If i omit the "new NameSampleDataStream()" (as shown in the docs) i get
a different error saying:*

ClassCastException java.lang.String cannot be cast to
opennlp.tools.namefind.**NameSample  opennlp.tools.namefind.**
TokenNameFinderCrossValidator$**NameToDocumentSampleStream.**read (**
TokenNameFinderCrossValidator.**java:67)

What am i missing?

Thanks in advance...

Jim






Reply via email to