zhongkaifu / RNNSharp

RNNSharp is a toolkit of deep recurrent neural network which is widely used for many different kinds of tasks, such as sequence labeling, sequence-to-sequence and so on. It's written by C# language and based on .NET framework 4.6 or above versions. RNNSharp supports many different types of networks, such as forward and bi-directional network, sequence-to-sequence network, and different types of layers, such as LSTM, Softmax, sampled Softmax and others.
BSD 3-Clause "New" or "Revised" License
285 stars 92 forks source link

Null reference exception with ForwardRNN #31

Closed bill3code closed 7 years ago

bill3code commented 7 years ago

Hello! When I try to run RNNSharpConsole with the parameters:

MODEL_TYPE = SEQLABEL

MODEL_DIRECTION = Forward

it throws exception "NullReferenceException"

220 line of code er += srcvec[j] * srcmatrix[j][i]; file RNNHelpers.cs

I tried to solve it, but I could not understand, why DenseWeights are not initialized.

''Необработанное исключение: System.AggregateException: Произошла одна или несколь ко ошибок. ---> System.NullReferenceException: Ссылка на объект не указывает на экземпляр объекта. в RNNSharp.RNNHelper.<>cDisplayClass27_0.b0(Int32 i) в C:\Users\vanin\Documents\Visual Studio 2015\Projects\RNNSharpnew\RNNSharp\RNN Helper.cs:строка 220 в System.Threading.Tasks.Parallel.<>cDisplayClass17_0`1.b1() в System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask) в System.Threading.Tasks.Task.<>c__DisplayClass176_0. b__0(Object ) --- Конец трассировки внутреннего стека исключений --- в System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledE xceptions) в System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationTok en cancellationToken) в System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int3 2 toExclusive, ParallelOptions parallelOptions, Action1 body, Action2 bodyWith State, Func4 bodyWithLocal, Func1 localInit, Action1 localFinally) в System.Threading.Tasks.Parallel.For(Int32 fromInclusive, Int32 toExclusive, Action1 body) в RNNSharp.RNNHelper.matrixXvectorADDErr(Single[] dest, Single[] srcvec, Matr ix1 srcmatrix, Int32 DestSize, Int32 SrcSize) в C:\Users\vanin\Documents\Visual Studio 2015\Projects\RNNSharpnew\RNNSharp\RNNHelper.cs:строка 215 в RNNSharp.SimpleLayer.ComputeLayerErr(SimpleLayer nextLayer) в C:\Users\vani n\Documents\Visual Studio 2015\Projects\RNNSharpnew\RNNSharp\SimpleLayer.cs:стро ка 287 в RNNSharp.DropoutLayer.ComputeLayerErr(SimpleLayer nextLayer) в C:\Users\van in\Documents\Visual Studio 2015\Projects\RNNSharpnew\RNNSharp\DropoutLayer.cs:ст рока 124 в RNNSharp.ForwardRNN1.ProcessSequenceCRF(Sequence pSequence, RunningMode ru nningMode) в C:\Users\vanin\Documents\Visual Studio 2015\Projects\RNNSharpnew\RN NSharp\FowardRNN.cs:строка 436 в RNNSharp.RNN1.TrainNet(DataSet1 trainingSet, Int32 iter) в C:\Users\vanin \Documents\Visual Studio 2015\Projects\RNNSharpnew\RNNSharp\RNN.cs:строка 317 в RNNSharp.RNNEncoder`1.Train() в C:\Users\vanin\Documents\Visual Studio 2015 \Projects\RNNSharpnew\RNNSharp\RNNEncoder.cs:строка 96 в RNNSharpConsole.Program.Train() в C:\Users\vanin\Documents\Visual Studio 20 15\Projects\RNNSharpnew\RNNSharpConsole\Program.cs:строка 542 в RNNSharpConsole.Program.Main(String[] args) в C:\Users\vanin\Documents\Visu al Studio 2015\Projects\RNNSharpnew\RNNSharpConsole\Program.cs:строка 292

zhongkaifu commented 7 years ago

Hi @bill3code

According call stack, RNN-CRF and dropout layer are applied for your training. In dropout layer, weights are shared with other layers. Could you please share complete configuration file with me ? I will try to repro it on my machine. To unblock your training, you can remove dropout layer from your configuration file before the issue is fixed.

bill3code commented 7 years ago

Hello! Thank you for workaround. It's my full config:

CURRENT_DIRECTORY = .\model1cfg

MODEL_TYPE = SEQLABEL

MODEL_DIRECTION = Forward

MODEL_FILEPATH = model.bin

HIDDEN_LAYER = LSTM:200, Dropout:0.3, LSTM:100

OUTPUT_LAYER = Simple

CRF_LAYER = True

TFEATURE_FILENAME = tfeatures

Binary and Freq are supported

TFEATURE_WEIGHT_TYPE = Freq

TFEATURE_CONTEXT = 0,1,2

PRETRAIN_TYPE = Embedding

WORDEMBEDDING_FILENAME = vector.bin

WORDEMBEDDING_CONTEXT = -1,0,1

WORDEMBEDDING_COLUMN = 0

AUTOENCODER_CONFIG = D:\RNNSharpDemoPackage\config_autoencoder.txt

SEQ2SEQ_AUTOENCODER_CONFIG: D:\RNNSharpDemoPackage\config_seq2seq_autoencoder.txt

RTFEATURE_CONTEXT = -2,-1

zhongkaifu commented 7 years ago

This problem has already been fixed. You can use Dropout layer for forward-RNN now.