Cant get LSTM model to give required predictions












0












$begingroup$


Describe the feature and the current behavior/state. I built a model which can predict parts of speech of words when given separately. Now I am building a model which can predict parts of speech of words in sentences. For this i have created two arrays. 1st Array(Input train) - which has sentences tokenized as arrays[14,546,789,4556](words as sequences, There are many arrays like this representing sentences), 2nd Array- Arrays of parts of speech of each word in14,7,3,21(respective parts of speech as sequences), .Both words and parts and speech are converted to sequences



CODE



model = tf.keras.Sequential()
model.add(tf.keras.layers.Embedding(input_dim=11040,output_dim=64,
input_length= 30, batch_input_shape=[128,None]))
model.add(tf.keras.layers.LSTM(30, activation='tanh',
recurrent_activation='hard_sigmoid',
kernel_initializer='glorot_uniform',
recurrent_initializer='orthogonal',stateful = True))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(30)) model.summary()
PROBLEM



It is returning a single array where each element in the predicted array represents a whole sentences where it should give array of parts of speech for each sentence in the input. Please tell me how to change the model and why. I am a beginner trying to learn machine learning.









share







New contributor




user56565 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$

















    0












    $begingroup$


    Describe the feature and the current behavior/state. I built a model which can predict parts of speech of words when given separately. Now I am building a model which can predict parts of speech of words in sentences. For this i have created two arrays. 1st Array(Input train) - which has sentences tokenized as arrays[14,546,789,4556](words as sequences, There are many arrays like this representing sentences), 2nd Array- Arrays of parts of speech of each word in14,7,3,21(respective parts of speech as sequences), .Both words and parts and speech are converted to sequences



    CODE



    model = tf.keras.Sequential()
    model.add(tf.keras.layers.Embedding(input_dim=11040,output_dim=64,
    input_length= 30, batch_input_shape=[128,None]))
    model.add(tf.keras.layers.LSTM(30, activation='tanh',
    recurrent_activation='hard_sigmoid',
    kernel_initializer='glorot_uniform',
    recurrent_initializer='orthogonal',stateful = True))
    model.add(tf.keras.layers.Flatten())
    model.add(tf.keras.layers.Dense(30)) model.summary()
    PROBLEM



    It is returning a single array where each element in the predicted array represents a whole sentences where it should give array of parts of speech for each sentence in the input. Please tell me how to change the model and why. I am a beginner trying to learn machine learning.









    share







    New contributor




    user56565 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      0












      0








      0





      $begingroup$


      Describe the feature and the current behavior/state. I built a model which can predict parts of speech of words when given separately. Now I am building a model which can predict parts of speech of words in sentences. For this i have created two arrays. 1st Array(Input train) - which has sentences tokenized as arrays[14,546,789,4556](words as sequences, There are many arrays like this representing sentences), 2nd Array- Arrays of parts of speech of each word in14,7,3,21(respective parts of speech as sequences), .Both words and parts and speech are converted to sequences



      CODE



      model = tf.keras.Sequential()
      model.add(tf.keras.layers.Embedding(input_dim=11040,output_dim=64,
      input_length= 30, batch_input_shape=[128,None]))
      model.add(tf.keras.layers.LSTM(30, activation='tanh',
      recurrent_activation='hard_sigmoid',
      kernel_initializer='glorot_uniform',
      recurrent_initializer='orthogonal',stateful = True))
      model.add(tf.keras.layers.Flatten())
      model.add(tf.keras.layers.Dense(30)) model.summary()
      PROBLEM



      It is returning a single array where each element in the predicted array represents a whole sentences where it should give array of parts of speech for each sentence in the input. Please tell me how to change the model and why. I am a beginner trying to learn machine learning.









      share







      New contributor




      user56565 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      Describe the feature and the current behavior/state. I built a model which can predict parts of speech of words when given separately. Now I am building a model which can predict parts of speech of words in sentences. For this i have created two arrays. 1st Array(Input train) - which has sentences tokenized as arrays[14,546,789,4556](words as sequences, There are many arrays like this representing sentences), 2nd Array- Arrays of parts of speech of each word in14,7,3,21(respective parts of speech as sequences), .Both words and parts and speech are converted to sequences



      CODE



      model = tf.keras.Sequential()
      model.add(tf.keras.layers.Embedding(input_dim=11040,output_dim=64,
      input_length= 30, batch_input_shape=[128,None]))
      model.add(tf.keras.layers.LSTM(30, activation='tanh',
      recurrent_activation='hard_sigmoid',
      kernel_initializer='glorot_uniform',
      recurrent_initializer='orthogonal',stateful = True))
      model.add(tf.keras.layers.Flatten())
      model.add(tf.keras.layers.Dense(30)) model.summary()
      PROBLEM



      It is returning a single array where each element in the predicted array represents a whole sentences where it should give array of parts of speech for each sentence in the input. Please tell me how to change the model and why. I am a beginner trying to learn machine learning.







      machine-learning python keras tensorflow regression





      share







      New contributor




      user56565 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      user56565 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      user56565 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 min ago









      user56565user56565

      1




      1




      New contributor




      user56565 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user56565 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user56565 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "557"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          user56565 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f46241%2fcant-get-lstm-model-to-give-required-predictions%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          user56565 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          user56565 is a new contributor. Be nice, and check out our Code of Conduct.













          user56565 is a new contributor. Be nice, and check out our Code of Conduct.












          user56565 is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f46241%2fcant-get-lstm-model-to-give-required-predictions%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Ponta tanko

          Tantalo (mitologio)

          Erzsébet Schaár