How to manipulate recurrent CNN model on sentence classification?Implementing the Dependency Sensitive CNN (DSCNN ) in KerasAttention using Context Vector: Hierarchical Attention Networks for Document ClassificationText understanding and mappingRight Way to Input Text Data in Keras Auto EncoderHow to compute document similarities in case of source codes?How to do give input to CNN when doing a text processing?Value of loss and accuracy does not change over EpochsSkip-thought models applied to phrases instead of sentencesArchitecture for linear regression with variable input where each input is n-sized one-hot encodedApplying CNN for cross sectional data

Someone scrambled my calling sign- who am I?

Would mining huge amounts of resources on the Moon change its orbit?

Isn't the word "experience" wrongly used in this context?

Why doesn't the chatan sign the ketubah?

How can I create URL shortcuts/redirects for task/diff IDs in Phabricator?

How can an organ that provides biological immortality be unable to regenerate?

How can a new country break out from a developed country without war?

10 year ban after applying for a UK student visa

What will the french man say?

Should I be concerned about student access to a test bank?

When did hardware antialiasing start being available?

Emojional cryptic crossword

How much propellant is used up until liftoff?

What are rules for concealing thieves tools (or items in general)?

How do researchers send unsolicited emails asking for feedback on their works?

Why do I have a large white artefact on the rendered image?

Why does Surtur say that Thor is Asgard's doom?

Norwegian Refugee travel document

Do I need an EFI partition for each 18.04 ubuntu I have on my HD?

Determine voltage drop over 10G resistors with cheap multimeter

Difficulty understanding group delay concept

Align centered, ragged right and ragged left in align environment

What is the reasoning behind standardization (dividing by standard deviation)?

Triple Trouble Tribond



How to manipulate recurrent CNN model on sentence classification?


Implementing the Dependency Sensitive CNN (DSCNN ) in KerasAttention using Context Vector: Hierarchical Attention Networks for Document ClassificationText understanding and mappingRight Way to Input Text Data in Keras Auto EncoderHow to compute document similarities in case of source codes?How to do give input to CNN when doing a text processing?Value of loss and accuracy does not change over EpochsSkip-thought models applied to phrases instead of sentencesArchitecture for linear regression with variable input where each input is n-sized one-hot encodedApplying CNN for cross sectional data













0












$begingroup$


I learned how to build recurrent cnn model for text classification and sketched out my initial implementation. However, I am wondering how to transform recurrent cnn model for sentence classification. I am curious how can I come up better implementation of recurrent cnn model for sentence classification task. Here is part of keras solution that I used:



import gensim
import numpy as np
import string
import gensim
from gensim.models import Word2Vec
from gensim.utils import simple_preprocess
from gensim.models.keyedvectors import KeyedVectors

word2vec = KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin', limit= 500000,binary=True)
embeddings = np.zeros((word2vec.syn0.shape[0] + 1, word2vec.syn0.shape[1]), dtype = "float32")
embeddings[:word2vec.syn0.shape[0]] = word2vec.syn0

MAX_TOKENS = word2vec.syn0.shape[0]
embedding_dim = word2vec.syn0.shape[1]
hidden_dim_1 = 200
hidden_dim_2 = 100
NUM_CLASSES = 10


problem



I want to learn sentence classification task by using recurrent cnn (RCNN) model. The fact that some people used RCNN for object recognition problem. And it is not very intuitive for me how to transform same idea to list of short sentences.



Here is the code that I want to make them work for sentence classification task:



document = Input(shape = (None, ), dtype = "int32")
left_context = Input(shape = (None, ), dtype = "int32")
right_context = Input(shape = (None, ), dtype = "int32")

embedder = Embedding(MAX_TOKENS + 1, embedding_dim, weights = [embeddings], trainable = False)
doc_embedding = embedder(document)
l_embedding = embedder(left_context)
r_embedding = embedder(right_context)


continuation of my code



I am struggling to make above code in problem section for sentence classification problem. Can anyone give me possible idea how to make it work for sentences classification?



If there is efficient transformation on above code, I'd like to continue my pipeline as follow to build RCNN model for sentence classification.



forward = LSTM(hidden_dim_1, return_sequences = True)(l_embedding)
backward = LSTM(hidden_dim_1, return_sequences = True, go_backwards = True)(r_embedding)
backward = Lambda(lambda x: K.reverse(x, axes = 1))(backward)
together = concatenate([forward, doc_embedding, backward], axis = 2)
semantic = Conv1D(hidden_dim_2, kernel_size = 1, activation = "tanh")(together)
pool_rnn = Lambda(lambda x: K.max(x, axis = 1), output_shape = (hidden_dim_2, ))(semantic)
model_output = Dense(NUM_CLASSES, input_dim = hidden_dim_2, activation = "softmax")(pool_rnn)
model_RCNN = Model(inputs = [document, left_context, right_context], outputs = model_output)


maybe I need to tokenize all sentences and create array for right/left context for each sentences, but I didn't get solid idea on that. Any more thoughts?



question



how can I realistically create input matrix for sentences list, right/left context of each sentence? Any workaround to get this done? Any efficient sketch solution to use recurrent cnn model for sentence classification? Thanks in advance!










share|improve this question











$endgroup$
















    0












    $begingroup$


    I learned how to build recurrent cnn model for text classification and sketched out my initial implementation. However, I am wondering how to transform recurrent cnn model for sentence classification. I am curious how can I come up better implementation of recurrent cnn model for sentence classification task. Here is part of keras solution that I used:



    import gensim
    import numpy as np
    import string
    import gensim
    from gensim.models import Word2Vec
    from gensim.utils import simple_preprocess
    from gensim.models.keyedvectors import KeyedVectors

    word2vec = KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin', limit= 500000,binary=True)
    embeddings = np.zeros((word2vec.syn0.shape[0] + 1, word2vec.syn0.shape[1]), dtype = "float32")
    embeddings[:word2vec.syn0.shape[0]] = word2vec.syn0

    MAX_TOKENS = word2vec.syn0.shape[0]
    embedding_dim = word2vec.syn0.shape[1]
    hidden_dim_1 = 200
    hidden_dim_2 = 100
    NUM_CLASSES = 10


    problem



    I want to learn sentence classification task by using recurrent cnn (RCNN) model. The fact that some people used RCNN for object recognition problem. And it is not very intuitive for me how to transform same idea to list of short sentences.



    Here is the code that I want to make them work for sentence classification task:



    document = Input(shape = (None, ), dtype = "int32")
    left_context = Input(shape = (None, ), dtype = "int32")
    right_context = Input(shape = (None, ), dtype = "int32")

    embedder = Embedding(MAX_TOKENS + 1, embedding_dim, weights = [embeddings], trainable = False)
    doc_embedding = embedder(document)
    l_embedding = embedder(left_context)
    r_embedding = embedder(right_context)


    continuation of my code



    I am struggling to make above code in problem section for sentence classification problem. Can anyone give me possible idea how to make it work for sentences classification?



    If there is efficient transformation on above code, I'd like to continue my pipeline as follow to build RCNN model for sentence classification.



    forward = LSTM(hidden_dim_1, return_sequences = True)(l_embedding)
    backward = LSTM(hidden_dim_1, return_sequences = True, go_backwards = True)(r_embedding)
    backward = Lambda(lambda x: K.reverse(x, axes = 1))(backward)
    together = concatenate([forward, doc_embedding, backward], axis = 2)
    semantic = Conv1D(hidden_dim_2, kernel_size = 1, activation = "tanh")(together)
    pool_rnn = Lambda(lambda x: K.max(x, axis = 1), output_shape = (hidden_dim_2, ))(semantic)
    model_output = Dense(NUM_CLASSES, input_dim = hidden_dim_2, activation = "softmax")(pool_rnn)
    model_RCNN = Model(inputs = [document, left_context, right_context], outputs = model_output)


    maybe I need to tokenize all sentences and create array for right/left context for each sentences, but I didn't get solid idea on that. Any more thoughts?



    question



    how can I realistically create input matrix for sentences list, right/left context of each sentence? Any workaround to get this done? Any efficient sketch solution to use recurrent cnn model for sentence classification? Thanks in advance!










    share|improve this question











    $endgroup$














      0












      0








      0





      $begingroup$


      I learned how to build recurrent cnn model for text classification and sketched out my initial implementation. However, I am wondering how to transform recurrent cnn model for sentence classification. I am curious how can I come up better implementation of recurrent cnn model for sentence classification task. Here is part of keras solution that I used:



      import gensim
      import numpy as np
      import string
      import gensim
      from gensim.models import Word2Vec
      from gensim.utils import simple_preprocess
      from gensim.models.keyedvectors import KeyedVectors

      word2vec = KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin', limit= 500000,binary=True)
      embeddings = np.zeros((word2vec.syn0.shape[0] + 1, word2vec.syn0.shape[1]), dtype = "float32")
      embeddings[:word2vec.syn0.shape[0]] = word2vec.syn0

      MAX_TOKENS = word2vec.syn0.shape[0]
      embedding_dim = word2vec.syn0.shape[1]
      hidden_dim_1 = 200
      hidden_dim_2 = 100
      NUM_CLASSES = 10


      problem



      I want to learn sentence classification task by using recurrent cnn (RCNN) model. The fact that some people used RCNN for object recognition problem. And it is not very intuitive for me how to transform same idea to list of short sentences.



      Here is the code that I want to make them work for sentence classification task:



      document = Input(shape = (None, ), dtype = "int32")
      left_context = Input(shape = (None, ), dtype = "int32")
      right_context = Input(shape = (None, ), dtype = "int32")

      embedder = Embedding(MAX_TOKENS + 1, embedding_dim, weights = [embeddings], trainable = False)
      doc_embedding = embedder(document)
      l_embedding = embedder(left_context)
      r_embedding = embedder(right_context)


      continuation of my code



      I am struggling to make above code in problem section for sentence classification problem. Can anyone give me possible idea how to make it work for sentences classification?



      If there is efficient transformation on above code, I'd like to continue my pipeline as follow to build RCNN model for sentence classification.



      forward = LSTM(hidden_dim_1, return_sequences = True)(l_embedding)
      backward = LSTM(hidden_dim_1, return_sequences = True, go_backwards = True)(r_embedding)
      backward = Lambda(lambda x: K.reverse(x, axes = 1))(backward)
      together = concatenate([forward, doc_embedding, backward], axis = 2)
      semantic = Conv1D(hidden_dim_2, kernel_size = 1, activation = "tanh")(together)
      pool_rnn = Lambda(lambda x: K.max(x, axis = 1), output_shape = (hidden_dim_2, ))(semantic)
      model_output = Dense(NUM_CLASSES, input_dim = hidden_dim_2, activation = "softmax")(pool_rnn)
      model_RCNN = Model(inputs = [document, left_context, right_context], outputs = model_output)


      maybe I need to tokenize all sentences and create array for right/left context for each sentences, but I didn't get solid idea on that. Any more thoughts?



      question



      how can I realistically create input matrix for sentences list, right/left context of each sentence? Any workaround to get this done? Any efficient sketch solution to use recurrent cnn model for sentence classification? Thanks in advance!










      share|improve this question











      $endgroup$




      I learned how to build recurrent cnn model for text classification and sketched out my initial implementation. However, I am wondering how to transform recurrent cnn model for sentence classification. I am curious how can I come up better implementation of recurrent cnn model for sentence classification task. Here is part of keras solution that I used:



      import gensim
      import numpy as np
      import string
      import gensim
      from gensim.models import Word2Vec
      from gensim.utils import simple_preprocess
      from gensim.models.keyedvectors import KeyedVectors

      word2vec = KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin', limit= 500000,binary=True)
      embeddings = np.zeros((word2vec.syn0.shape[0] + 1, word2vec.syn0.shape[1]), dtype = "float32")
      embeddings[:word2vec.syn0.shape[0]] = word2vec.syn0

      MAX_TOKENS = word2vec.syn0.shape[0]
      embedding_dim = word2vec.syn0.shape[1]
      hidden_dim_1 = 200
      hidden_dim_2 = 100
      NUM_CLASSES = 10


      problem



      I want to learn sentence classification task by using recurrent cnn (RCNN) model. The fact that some people used RCNN for object recognition problem. And it is not very intuitive for me how to transform same idea to list of short sentences.



      Here is the code that I want to make them work for sentence classification task:



      document = Input(shape = (None, ), dtype = "int32")
      left_context = Input(shape = (None, ), dtype = "int32")
      right_context = Input(shape = (None, ), dtype = "int32")

      embedder = Embedding(MAX_TOKENS + 1, embedding_dim, weights = [embeddings], trainable = False)
      doc_embedding = embedder(document)
      l_embedding = embedder(left_context)
      r_embedding = embedder(right_context)


      continuation of my code



      I am struggling to make above code in problem section for sentence classification problem. Can anyone give me possible idea how to make it work for sentences classification?



      If there is efficient transformation on above code, I'd like to continue my pipeline as follow to build RCNN model for sentence classification.



      forward = LSTM(hidden_dim_1, return_sequences = True)(l_embedding)
      backward = LSTM(hidden_dim_1, return_sequences = True, go_backwards = True)(r_embedding)
      backward = Lambda(lambda x: K.reverse(x, axes = 1))(backward)
      together = concatenate([forward, doc_embedding, backward], axis = 2)
      semantic = Conv1D(hidden_dim_2, kernel_size = 1, activation = "tanh")(together)
      pool_rnn = Lambda(lambda x: K.max(x, axis = 1), output_shape = (hidden_dim_2, ))(semantic)
      model_output = Dense(NUM_CLASSES, input_dim = hidden_dim_2, activation = "softmax")(pool_rnn)
      model_RCNN = Model(inputs = [document, left_context, right_context], outputs = model_output)


      maybe I need to tokenize all sentences and create array for right/left context for each sentences, but I didn't get solid idea on that. Any more thoughts?



      question



      how can I realistically create input matrix for sentences list, right/left context of each sentence? Any workaround to get this done? Any efficient sketch solution to use recurrent cnn model for sentence classification? Thanks in advance!







      deep-learning nlp cnn recurrent-neural-net






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 3 hours ago







      Dan

















      asked 19 hours ago









      DanDan

      62




      62




















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



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f47490%2fhow-to-manipulate-recurrent-cnn-model-on-sentence-classification%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















          draft saved

          draft discarded
















































          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%2f47490%2fhow-to-manipulate-recurrent-cnn-model-on-sentence-classification%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

          Ружовы пелікан Змест Знешні выгляд | Пашырэнне | Асаблівасці біялогіі | Літаратура | НавігацыяДагледжаная версіяправерана1 зменаДагледжаная версіяправерана1 змена/ 22697590 Сістэматыкана ВіківідахВыявына Вікісховішчы174693363011049382

          ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3)2019 Community Moderator ElectionError when checking : expected dense_1_input to have shape (None, 5) but got array with shape (200, 1)Error 'Expected 2D array, got 1D array instead:'ValueError: Error when checking input: expected lstm_41_input to have 3 dimensions, but got array with shape (40000,100)ValueError: Error when checking target: expected dense_1 to have shape (7,) but got array with shape (1,)ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Keras exception: ValueError: Error when checking input: expected conv2d_1_input to have shape (150, 150, 3) but got array with shape (256, 256, 3)Steps taking too long to completewhen checking input: expected dense_1_input to have shape (13328,) but got array with shape (317,)ValueError: Error when checking target: expected dense_3 to have shape (None, 1) but got array with shape (7715, 40000)Keras exception: Error when checking input: expected dense_input to have shape (2,) but got array with shape (1,)

          Illegal assignment from SObject to ContactFetching String, Id from Map - Illegal Assignment Id to Field / ObjectError: Compile Error: Illegal assignment from String to BooleanError: List has no rows for assignment to SObjectError on Test Class - System.QueryException: List has no rows for assignment to SObjectRemote action problemDML requires SObject or SObject list type error“Illegal assignment from List to List”Test Class Fail: Batch Class: System.QueryException: List has no rows for assignment to SObjectMapping to a user'List has no rows for assignment to SObject' Mystery