TensorFlow.NET icon indicating copy to clipboard operation
TensorFlow.NET copied to clipboard

Is bidirectional for LSTM even supported ? I am getting empty ( in C#/Tensorflow.NET 0 parameters) [Question]:

Open jaroslav-hook opened this issue 1 year ago • 8 comments

Description

        ILayer forwardLayer = keras.layers.LSTM(units: 10, activation: keras.activations.Sigmoid, return_sequences: true, go_backwards: false);
        ILayer backwardlayer = keras.layers.LSTM(units: 10, activation: keras.activations.Sigmoid, return_sequences: true, go_backwards: true);
        model.add(keras.layers.Bidirectional(forwardLayer, merge_mode: "sum", backward_layer: backwardlayer));

Alternatives

No response

jaroslav-hook avatar Jan 16 '24 21:01 jaroslav-hook

Have you checked this example? https://github.com/SciSharp/SciSharp.Models/blob/8bd848c3bc67395d4c787e15e8eddf7ed6707fdf/SciSharp.Models.TimeSeries/RNNModel.cs#L14

Oceania2018 avatar Jan 17 '24 02:01 Oceania2018

Yes, it has been support. You can refer to https://github.com/SciSharp/TensorFlow.NET/blob/8cab730f98112a845461bb635f137e220f272adb/test/TensorFlowNET.Keras.UnitTest/Layers/Rnn.Test.cs#L158-L165

But it may not have tested all parameters and situations like you set go_backwards to true in backward_layer here. So it may have some bugs here. And could you mind to provide more information, such as a minimal code for reproduction and more error information?

Wanglongzhi2001 avatar Jan 17 '24 12:01 Wanglongzhi2001

after the model is defined, it model.summary() retuns zero parameters for the bidirectional layers this gives zro parameters i summary public static void buildModel2() { //int embed_dim = 256; int lstm_out = 196; // var max_features = 4000; var model = keras.Sequential(); //model.add(keras.layers.Embedding(max_features, embed_dim, input_length : 35)); model.add(keras.layers.Dropout(0.4f)); // SpatialDropout1D model.add(keras.layers.Bidirectional(keras.layers.LSTM(lstm_out, dropout: 0.05f, recurrent_dropout: 0.2f))); // Add f model.add(keras.layers.Dense(2, activation : keras.activations.Softmax)); // replace 'Softmax' with keras.activations.Softmax model.compile(loss: "MeanSquaredError", optimizer: "adam", metrics: new string[] { "accuracy" }); model.summary(); }

jaroslav-hook avatar Jan 19 '24 20:01 jaroslav-hook

    This  gives no parameters   in model.summary()

public static void buildModel2() { //int embed_dim = 256; int lstm_out = 196; // var max_features = 4000; var model = keras.Sequential(); //model.add(keras.layers.Embedding(max_features, embed_dim, input_length : 35)); model.add(keras.layers.Dropout(0.4f)); // SpatialDropout1D model.add(keras.layers.Bidirectional(keras.layers.LSTM(lstm_out, dropout: 0.05f, recurrent_dropout: 0.2f))); // Add f model.add(keras.layers.Dense(2, activation : keras.activations.Softmax)); // replace 'Softmax' with keras.activations.Softmax model.compile(loss: "MeanSquaredError", optimizer: "adam", metrics: new string[] { "accuracy" }); model.summary(); }

jaroslav-hook avatar Jan 19 '24 20:01 jaroslav-hook

I encountered a similar problem, did you manage to find a solution?

MaSobkowiak avatar Aug 14 '24 11:08 MaSobkowiak

Tensor.NET is full of bug and inconsistencies… Better not to use it

From: Maciej Sobkowiak @.> Sent: Wednesday, August 14, 2024 6:37 AM To: SciSharp/TensorFlow.NET @.> Cc: Hook, Jaroslav @.>; Author @.> Subject: Re: [SciSharp/TensorFlow.NET] Is bidirectional for LSTM even supported ? I am getting empty ( in C#/Tensorflow.NET 0 parameters) [Question]: (Issue #1227)

CAUTION: This email originated from outside of Thermo Fisher Scientific. If you believe it to be suspicious, report using the Report Phish button in Outlook or send to @.***

I encountered a similar problem, did you manage to find a solution?

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/SciSharp/TensorFlow.NET/issues/1227*issuecomment-2288511363__;Iw!!HLrAl2XzZ3iCLg!DQEi2LZY0_Az3AH8pm0bLesqbAQ44bSDgmjjLzfJeSb9XRmtemaFYCYWFss97ktG89A3ol0NKeJIrLDxDc8dnIyd7M7RcbCZ$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AWWYDG2HQRCKY5ZRWKKIZ5DZRM6MLAVCNFSM6AAAAABB5PTAN2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBYGUYTCMZWGM__;!!HLrAl2XzZ3iCLg!DQEi2LZY0_Az3AH8pm0bLesqbAQ44bSDgmjjLzfJeSb9XRmtemaFYCYWFss97ktG89A3ol0NKeJIrLDxDc8dnIyd7PnUgGQD$. You are receiving this because you authored the thread.Message ID: @.@.>>

jaroslav-hook avatar Aug 14 '24 14:08 jaroslav-hook

If you dont mind me asking, do you find any better alternative, or you stick with Python version?

Maybe have you tried using python inside .NET with Python.NET?

MaSobkowiak avatar Aug 14 '24 16:08 MaSobkowiak

I tried to implement LSTM ( both training and inference) in Tensor.NET. LSTM Training was OK with some difficulties ( even though some features were missing), but when I switched the inference was a total disaster: VS started complaining on some version inconsistencies, some missing libraries, non-existing functions etc… Basically Tensorflow.NET is an inconsistent mess: the things do not work as advertised... I would not waste time on it … Stick with Python.

From: Maciej Sobkowiak @.> Sent: Wednesday, August 14, 2024 11:17 AM To: SciSharp/TensorFlow.NET @.> Cc: Hook, Jaroslav @.>; Author @.> Subject: Re: [SciSharp/TensorFlow.NET] Is bidirectional for LSTM even supported ? I am getting empty ( in C#/Tensorflow.NET 0 parameters) [Question]: (Issue #1227)

CAUTION: This email originated from outside of Thermo Fisher Scientific. If you believe it to be suspicious, report using the Report Phish button in Outlook or send to @.***

If you dont mind me asking, do you find any better alternative, or you stick with Python version?

Maybe have you tried using python inside .NET with Python.NET?

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/SciSharp/TensorFlow.NET/issues/1227*issuecomment-2289225668__;Iw!!HLrAl2XzZ3iCLg!BiIK8vAY6dMMLCrEq6CW1r989bul0C-bXhVsH6cilT0NkeN8XKbJzy3xPm7uyC85zWkhU6LbCugtdPUF5BLzot1nVbJsuOMJ$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AWWYDGZJZJ7IFKBJHRC5RLLZRN7G5AVCNFSM6AAAAABB5PTAN2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBZGIZDKNRWHA__;!!HLrAl2XzZ3iCLg!BiIK8vAY6dMMLCrEq6CW1r989bul0C-bXhVsH6cilT0NkeN8XKbJzy3xPm7uyC85zWkhU6LbCugtdPUF5BLzot1nVVGlYaTe$. You are receiving this because you authored the thread.Message ID: @.@.>>

jaroslav-hook avatar Aug 14 '24 16:08 jaroslav-hook