How to set kernel size (height and width) for 1D convolution layer in CNN Keras R API for doc2vec input?












0












$begingroup$


I am using a doc2vec matrix (6000,1024) as feature space to input in a classification model which can categorise each document(sentence in my case) into one of the two classes (A,B). My feature space has 1024 features for each of the 6000 sentence in the dataset.



So basically each row of doc2Vec matrix represents a feature vector for that sentence. I am trying to use this single matrix as input to a 1D CNN. Usually, the input to CNNs for NLP tasks have one matrix per sentence, hence the batch size is equal to the number of sentence. Whereas my situation is slightly different, I have one matrix as described above.



So basically I want the filters to have kernels (of various widths) which slide across just one sentence vector, as opposed to usually kernels which slide across a group of words (i.e slide across multiple word vectors at a time with a height greater than 1). However, I am finding it difficult to set the parameter values to the following layers in keras API for R



layer_input(shape = 1024, batch_shape = c(6000,1024), dtype = 'float64', name = 'input1')
does this input layer represent what I want it to represent, if not what should it look like otherwise?



and not sure how to set the parameter values for
layer_conv1d(filters = , kernel_size = ).



I am not sure how to give kernel_size list of values which represent (height = 1 and width = n) where n is an integer greater than 1.



So in summary I am expecting CNN to select a feature space (6000*n) from an original feature space(6000*1024) and I would column bind it with another feature space to feed it to fully connected layers in the CNN architecture.









share







New contributor




user3516188 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$


    I am using a doc2vec matrix (6000,1024) as feature space to input in a classification model which can categorise each document(sentence in my case) into one of the two classes (A,B). My feature space has 1024 features for each of the 6000 sentence in the dataset.



    So basically each row of doc2Vec matrix represents a feature vector for that sentence. I am trying to use this single matrix as input to a 1D CNN. Usually, the input to CNNs for NLP tasks have one matrix per sentence, hence the batch size is equal to the number of sentence. Whereas my situation is slightly different, I have one matrix as described above.



    So basically I want the filters to have kernels (of various widths) which slide across just one sentence vector, as opposed to usually kernels which slide across a group of words (i.e slide across multiple word vectors at a time with a height greater than 1). However, I am finding it difficult to set the parameter values to the following layers in keras API for R



    layer_input(shape = 1024, batch_shape = c(6000,1024), dtype = 'float64', name = 'input1')
    does this input layer represent what I want it to represent, if not what should it look like otherwise?



    and not sure how to set the parameter values for
    layer_conv1d(filters = , kernel_size = ).



    I am not sure how to give kernel_size list of values which represent (height = 1 and width = n) where n is an integer greater than 1.



    So in summary I am expecting CNN to select a feature space (6000*n) from an original feature space(6000*1024) and I would column bind it with another feature space to feed it to fully connected layers in the CNN architecture.









    share







    New contributor




    user3516188 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$


      I am using a doc2vec matrix (6000,1024) as feature space to input in a classification model which can categorise each document(sentence in my case) into one of the two classes (A,B). My feature space has 1024 features for each of the 6000 sentence in the dataset.



      So basically each row of doc2Vec matrix represents a feature vector for that sentence. I am trying to use this single matrix as input to a 1D CNN. Usually, the input to CNNs for NLP tasks have one matrix per sentence, hence the batch size is equal to the number of sentence. Whereas my situation is slightly different, I have one matrix as described above.



      So basically I want the filters to have kernels (of various widths) which slide across just one sentence vector, as opposed to usually kernels which slide across a group of words (i.e slide across multiple word vectors at a time with a height greater than 1). However, I am finding it difficult to set the parameter values to the following layers in keras API for R



      layer_input(shape = 1024, batch_shape = c(6000,1024), dtype = 'float64', name = 'input1')
      does this input layer represent what I want it to represent, if not what should it look like otherwise?



      and not sure how to set the parameter values for
      layer_conv1d(filters = , kernel_size = ).



      I am not sure how to give kernel_size list of values which represent (height = 1 and width = n) where n is an integer greater than 1.



      So in summary I am expecting CNN to select a feature space (6000*n) from an original feature space(6000*1024) and I would column bind it with another feature space to feed it to fully connected layers in the CNN architecture.









      share







      New contributor




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







      $endgroup$




      I am using a doc2vec matrix (6000,1024) as feature space to input in a classification model which can categorise each document(sentence in my case) into one of the two classes (A,B). My feature space has 1024 features for each of the 6000 sentence in the dataset.



      So basically each row of doc2Vec matrix represents a feature vector for that sentence. I am trying to use this single matrix as input to a 1D CNN. Usually, the input to CNNs for NLP tasks have one matrix per sentence, hence the batch size is equal to the number of sentence. Whereas my situation is slightly different, I have one matrix as described above.



      So basically I want the filters to have kernels (of various widths) which slide across just one sentence vector, as opposed to usually kernels which slide across a group of words (i.e slide across multiple word vectors at a time with a height greater than 1). However, I am finding it difficult to set the parameter values to the following layers in keras API for R



      layer_input(shape = 1024, batch_shape = c(6000,1024), dtype = 'float64', name = 'input1')
      does this input layer represent what I want it to represent, if not what should it look like otherwise?



      and not sure how to set the parameter values for
      layer_conv1d(filters = , kernel_size = ).



      I am not sure how to give kernel_size list of values which represent (height = 1 and width = n) where n is an integer greater than 1.



      So in summary I am expecting CNN to select a feature space (6000*n) from an original feature space(6000*1024) and I would column bind it with another feature space to feed it to fully connected layers in the CNN architecture.







      keras r cnn





      share







      New contributor




      user3516188 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




      user3516188 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




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









      asked 7 mins ago









      user3516188user3516188

      1




      1




      New contributor




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





      New contributor





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






      user3516188 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
          });


          }
          });






          user3516188 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%2f48328%2fhow-to-set-kernel-size-height-and-width-for-1d-convolution-layer-in-cnn-keras%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








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










          draft saved

          draft discarded


















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













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












          user3516188 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%2f48328%2fhow-to-set-kernel-size-height-and-width-for-1d-convolution-layer-in-cnn-keras%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

          How to label and detect the document text images

          Vallis Paradisi

          Tabula Rosettana