CoreNLP icon indicating copy to clipboard operation
CoreNLP copied to clipboard

NegativeArraySizeException in AbstractStochasticCachingDiffFunction.initial

Open InputNeuron opened this issue 10 years ago • 5 comments

We're building a linear classifier with a fair number of classes/labels. 50k or so...

It's not much data. About 200MB of text.

However, you're creating a large array for all these features and getting a negative array size to due integer overflow.

Can this array be sparse?

One solution is that if domainDimension returns negative at least throw an exception.

Guava Preconditions could help out greatly here...

  @Override
  public int domainDimension() {
    return numFeatures * numClasses;
  }

InputNeuron avatar Oct 22 '16 19:10 InputNeuron

Couldn't this be a N*M 2 dimensional array? I might look at the code to see if this is possible.

2B records is only 16GB of RAM which is a somewhat unreasonable restriction with modern hardware.

Java arrays can't use a long as a pointer though so an N*M array would resolve this.

InputNeuron avatar Oct 22 '16 19:10 InputNeuron

Making this an n_m array would both not solve the underlying problem (it would be a constant factor increase in the number of features), and would complicate the underlying optimization code quite a bit. At the end of the day, you're conceptually optimizing over an N_M dimensional vector, without any knowledge of "features" or "classes". So, while each datum can be [and is] sparse, the optimizer has to optimize the weight of every feature it's seen.

In all likelihood, learning a classifier over >2B parameters is probably a mistake anyways though? What features are you extracting? A trick you can try is to call Dataset#applyFeatureCountThreshold before you train from it. This should cut out any features that, e.g., only occur once in the data.

gangeli avatar Oct 23 '16 20:10 gangeli

I realize the issues with the above... but I think we're comparing apples to oranges here.

This isn't an issue with the corenlp framework exactly. This is simply because Java can't work with arrays greater than 2B entries.

Refactoring this into a 2 dimensional array would resolve this. You would have support for 2B features and 2B labels. This is clearly more than enough of course...

You might be right about the underlying code needing refactor as I haven't had a chance to dive in yet.

I'll play with applyFeatureCountThreshold though as this might be a solid work around for the interim.

InputNeuron avatar Oct 23 '16 20:10 InputNeuron

You're right, if the number of labels were to grow beyond a few dozen. But, classifiers also start to break down if you try to classify with more than 100 or so labels -- at that point you usually have to start doing something clever.

That said, I shouldn't discourage you from contributing :). I do agree that it would be nice to have an optimizer that handled arbitrarily large vectors, even if it's not a big focus for the group right now.

gangeli avatar Oct 23 '16 23:10 gangeli

You might be right.. We're trying to work with at least thousands of classifiers. For example, stock ticker symbols require at least 5000.

I will look at the code to see if its plausible to implement. My thinking was that it was just mapping the 1 dimensional space to 2 dimensional but I haven't dived into the code yet.

InputNeuron avatar Oct 23 '16 23:10 InputNeuron