Tensorflow/Keras, How to convert tf.feature_column into input tensors? The 2019 Stack Overflow Developer Survey Results Are InTensorFlow and Categorical variablesUsing tensorflow to test a variable amount of correct labelsfeature extraction for a pretrained model in kerasTensor Decomposition in TensorFlow for multinomial time series dimensionality reductionTensorflow regression predicting 1 for all inputsDynamic rnn for toysequence classificationMy Neural network in Tensorflow does a bad job in comparison to the same Neural network in KerasComparing tensors in TensorFlowVisualizing word embeddingsHow is this tensorflow command interpreted?

Worn-tile Scrabble

How to translate "being like"?

Why is the Constellation's nose gear so long?

Why are there uneven bright areas in this photo of black hole?

Cooking pasta in a water boiler

The phrase "to the numbers born"?

How to check whether the reindex working or not in Magento?

Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?

If I score a critical hit on an 18 or higher, what are my chances of getting a critical hit if I roll 3d20?

How to manage monthly salary

slides for 30min~1hr skype tenure track application interview

What is the motivation for a law requiring 2 parties to consent for recording a conversation

Can we generate random numbers using irrational numbers like π and e?

Balance problems for leveling up mid-fight?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

Are spiders unable to hurt humans, especially very small spiders?

Loose spokes after only a few rides

Should I use my personal e-mail address, or my workplace one, when registering to external websites for work purposes?

Why can't devices on different VLANs, but on the same subnet, communicate?

Pokemon Turn Based battle (Python)

Aging parents with no investments

Can one be advised by a professor who is very far away?

Keeping a retro style to sci-fi spaceships?

two types of coins, decide which type it is based on 100 flips



Tensorflow/Keras, How to convert tf.feature_column into input tensors?



The 2019 Stack Overflow Developer Survey Results Are InTensorFlow and Categorical variablesUsing tensorflow to test a variable amount of correct labelsfeature extraction for a pretrained model in kerasTensor Decomposition in TensorFlow for multinomial time series dimensionality reductionTensorflow regression predicting 1 for all inputsDynamic rnn for toysequence classificationMy Neural network in Tensorflow does a bad job in comparison to the same Neural network in KerasComparing tensors in TensorFlowVisualizing word embeddingsHow is this tensorflow command interpreted?










0












$begingroup$


I have the following code to average embeddings for list of item-ids.
(Embedding is trained on review_meta_id_input, and used as look up for pirors_input and for getting average embedding)



 review_meta_id_input = tf.keras.layers.Input(shape=(1,), dtype='int32', name='review_meta_id')
priors_input = tf.keras.layers.Input(shape=(None,), dtype='int32', name='priors') # array of ids
item_embedding_layer = tf.keras.layers.Embedding(
input_dim=100, # max number
output_dim=self.item_embedding_size,
name='item')

review_meta_id_embedding = item_embedding_layer(review_meta_id_input)
selected = tf.nn.embedding_lookup(review_meta_id_embedding, priors_input)
non_zero_count = tf.cast(tf.math.count_nonzero(priors_input, axis=1), tf.float32)
embedding_sum = tf.reduce_sum(selected, axis=1)
item_average = tf.math.divide(embedding_sum, non_zero_count)


I also have some feature columns such as..
(I just thought feature_column looked cool, but not many documents to look for..)



 kid_youngest_month = feature_column.numeric_column("kid_youngest_month")
kid_age_youngest_buckets = feature_column.bucketized_column(kid_youngest_month, boundaries=[12, 24, 36, 72, 96])


I'd like to define [review_meta_id_iput, priors_input, (tensors from feature_columns)] as an input to keras Model.



something like:



 inputs = [review_meta_id_input, priors_input] + feature_layer
model = tf.keras.models.Model(inputs=inputs, outputs=o)


In order to get tensors from feature columns, the closest lead I have now is



fc_to_tensor = fc: input_layer(features, [fc]) for fc in feature_columns


from https://github.com/tensorflow/tensorflow/issues/17170



However I'm not sure what the features are in the code.

There's no clear example on https://www.tensorflow.org/api_docs/python/tf/feature_column/input_layer either.



How should I construct the features variable for fc_to_tensor ?



Or is there a way to use keras.layers.Input and feature_column at the same time?



Or is there an alternative than tf.feature_column to do the bucketing as above? then I'll just drop the feature_column for now;










share|improve this question









$endgroup$
















    0












    $begingroup$


    I have the following code to average embeddings for list of item-ids.
    (Embedding is trained on review_meta_id_input, and used as look up for pirors_input and for getting average embedding)



     review_meta_id_input = tf.keras.layers.Input(shape=(1,), dtype='int32', name='review_meta_id')
    priors_input = tf.keras.layers.Input(shape=(None,), dtype='int32', name='priors') # array of ids
    item_embedding_layer = tf.keras.layers.Embedding(
    input_dim=100, # max number
    output_dim=self.item_embedding_size,
    name='item')

    review_meta_id_embedding = item_embedding_layer(review_meta_id_input)
    selected = tf.nn.embedding_lookup(review_meta_id_embedding, priors_input)
    non_zero_count = tf.cast(tf.math.count_nonzero(priors_input, axis=1), tf.float32)
    embedding_sum = tf.reduce_sum(selected, axis=1)
    item_average = tf.math.divide(embedding_sum, non_zero_count)


    I also have some feature columns such as..
    (I just thought feature_column looked cool, but not many documents to look for..)



     kid_youngest_month = feature_column.numeric_column("kid_youngest_month")
    kid_age_youngest_buckets = feature_column.bucketized_column(kid_youngest_month, boundaries=[12, 24, 36, 72, 96])


    I'd like to define [review_meta_id_iput, priors_input, (tensors from feature_columns)] as an input to keras Model.



    something like:



     inputs = [review_meta_id_input, priors_input] + feature_layer
    model = tf.keras.models.Model(inputs=inputs, outputs=o)


    In order to get tensors from feature columns, the closest lead I have now is



    fc_to_tensor = fc: input_layer(features, [fc]) for fc in feature_columns


    from https://github.com/tensorflow/tensorflow/issues/17170



    However I'm not sure what the features are in the code.

    There's no clear example on https://www.tensorflow.org/api_docs/python/tf/feature_column/input_layer either.



    How should I construct the features variable for fc_to_tensor ?



    Or is there a way to use keras.layers.Input and feature_column at the same time?



    Or is there an alternative than tf.feature_column to do the bucketing as above? then I'll just drop the feature_column for now;










    share|improve this question









    $endgroup$














      0












      0








      0





      $begingroup$


      I have the following code to average embeddings for list of item-ids.
      (Embedding is trained on review_meta_id_input, and used as look up for pirors_input and for getting average embedding)



       review_meta_id_input = tf.keras.layers.Input(shape=(1,), dtype='int32', name='review_meta_id')
      priors_input = tf.keras.layers.Input(shape=(None,), dtype='int32', name='priors') # array of ids
      item_embedding_layer = tf.keras.layers.Embedding(
      input_dim=100, # max number
      output_dim=self.item_embedding_size,
      name='item')

      review_meta_id_embedding = item_embedding_layer(review_meta_id_input)
      selected = tf.nn.embedding_lookup(review_meta_id_embedding, priors_input)
      non_zero_count = tf.cast(tf.math.count_nonzero(priors_input, axis=1), tf.float32)
      embedding_sum = tf.reduce_sum(selected, axis=1)
      item_average = tf.math.divide(embedding_sum, non_zero_count)


      I also have some feature columns such as..
      (I just thought feature_column looked cool, but not many documents to look for..)



       kid_youngest_month = feature_column.numeric_column("kid_youngest_month")
      kid_age_youngest_buckets = feature_column.bucketized_column(kid_youngest_month, boundaries=[12, 24, 36, 72, 96])


      I'd like to define [review_meta_id_iput, priors_input, (tensors from feature_columns)] as an input to keras Model.



      something like:



       inputs = [review_meta_id_input, priors_input] + feature_layer
      model = tf.keras.models.Model(inputs=inputs, outputs=o)


      In order to get tensors from feature columns, the closest lead I have now is



      fc_to_tensor = fc: input_layer(features, [fc]) for fc in feature_columns


      from https://github.com/tensorflow/tensorflow/issues/17170



      However I'm not sure what the features are in the code.

      There's no clear example on https://www.tensorflow.org/api_docs/python/tf/feature_column/input_layer either.



      How should I construct the features variable for fc_to_tensor ?



      Or is there a way to use keras.layers.Input and feature_column at the same time?



      Or is there an alternative than tf.feature_column to do the bucketing as above? then I'll just drop the feature_column for now;










      share|improve this question









      $endgroup$




      I have the following code to average embeddings for list of item-ids.
      (Embedding is trained on review_meta_id_input, and used as look up for pirors_input and for getting average embedding)



       review_meta_id_input = tf.keras.layers.Input(shape=(1,), dtype='int32', name='review_meta_id')
      priors_input = tf.keras.layers.Input(shape=(None,), dtype='int32', name='priors') # array of ids
      item_embedding_layer = tf.keras.layers.Embedding(
      input_dim=100, # max number
      output_dim=self.item_embedding_size,
      name='item')

      review_meta_id_embedding = item_embedding_layer(review_meta_id_input)
      selected = tf.nn.embedding_lookup(review_meta_id_embedding, priors_input)
      non_zero_count = tf.cast(tf.math.count_nonzero(priors_input, axis=1), tf.float32)
      embedding_sum = tf.reduce_sum(selected, axis=1)
      item_average = tf.math.divide(embedding_sum, non_zero_count)


      I also have some feature columns such as..
      (I just thought feature_column looked cool, but not many documents to look for..)



       kid_youngest_month = feature_column.numeric_column("kid_youngest_month")
      kid_age_youngest_buckets = feature_column.bucketized_column(kid_youngest_month, boundaries=[12, 24, 36, 72, 96])


      I'd like to define [review_meta_id_iput, priors_input, (tensors from feature_columns)] as an input to keras Model.



      something like:



       inputs = [review_meta_id_input, priors_input] + feature_layer
      model = tf.keras.models.Model(inputs=inputs, outputs=o)


      In order to get tensors from feature columns, the closest lead I have now is



      fc_to_tensor = fc: input_layer(features, [fc]) for fc in feature_columns


      from https://github.com/tensorflow/tensorflow/issues/17170



      However I'm not sure what the features are in the code.

      There's no clear example on https://www.tensorflow.org/api_docs/python/tf/feature_column/input_layer either.



      How should I construct the features variable for fc_to_tensor ?



      Or is there a way to use keras.layers.Input and feature_column at the same time?



      Or is there an alternative than tf.feature_column to do the bucketing as above? then I'll just drop the feature_column for now;







      keras tensorflow






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 30 at 9:39









      eugeneeugene

      1064




      1064




















          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%2f48253%2ftensorflow-keras-how-to-convert-tf-feature-column-into-input-tensors%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%2f48253%2ftensorflow-keras-how-to-convert-tf-feature-column-into-input-tensors%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

          Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

          Tähtien Talli Jäsenet | Lähteet | NavigointivalikkoSuomen Hippos – Tähtien Talli

          Do these cracks on my tires look bad? The Next CEO of Stack OverflowDry rot tire should I replace?Having to replace tiresFishtailed so easily? Bad tires? ABS?Filling the tires with something other than air, to avoid puncture hassles?Used Michelin tires safe to install?Do these tyre cracks necessitate replacement?Rumbling noise: tires or mechanicalIs it possible to fix noisy feathered tires?Are bad winter tires still better than summer tires in winter?Torque converter failure - Related to replacing only 2 tires?Why use snow tires on all 4 wheels on 2-wheel-drive cars?