# Tensorflow: When should I use or not use `feed_dict`?

## Tensorflow: When should I use or not use `feed_dict`?

In a tensorflow model you can define a placeholder such as `x = tf.placeholder(tf.float32)`, then you will use `x` in your model.

For example, I define a simple set of operations as:

``````x = tf.placeholder(tf.float32)
y = x * 42
``````

Now when I ask tensorflow to compute `y`, its clear that `y` depends on `x`.

``````with tf.Session() as sess:
sess.run(y)
``````

This will produce an error because I did not give it a value for `x`. In this case, because `x` is a placeholder, if it gets used in a computation you must pass it in via `feed_dict`. If you dont its an error.

Lets fix that:

``````with tf.Session() as sess:
sess.run(y, feed_dict={x: 2})
``````

The result this time will be `84`. Great. Now lets look at a trivial case where `feed_dict` is not needed:

``````x = tf.constant(2)
y = x * 42
``````

Now there are no placeholders (`x` is a constant) and so nothing needs to be fed to the model. This works now:

``````with tf.Session() as sess:
sess.run(y)
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.76670325,"math_prob":0.88620234,"size":996,"snap":"2022-05-2022-21","text_gpt3_token_len":270,"char_repetition_ratio":0.110887095,"word_repetition_ratio":0.08743169,"special_character_ratio":0.2751004,"punctuation_ratio":0.15811966,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99375194,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-22T07:06:45Z\",\"WARC-Record-ID\":\"<urn:uuid:5e2d0990-35ba-40f9-bb2a-520d8148c1b0>\",\"Content-Length\":\"61113\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:cdc321cb-bc94-45db-aa44-27aad5c4bca2>\",\"WARC-Concurrent-To\":\"<urn:uuid:d8be2fcb-2715-4e46-9c1f-a20b839205e9>\",\"WARC-IP-Address\":\"104.21.66.3\",\"WARC-Target-URI\":\"https://technoteshelp.com/tensorflow-when-should-i-use-or-not-use-feed_dict/\",\"WARC-Payload-Digest\":\"sha1:UTU5F6YIAGEFXVGDIUBVQMMFUMEFKT2B\",\"WARC-Block-Digest\":\"sha1:6YY3LY3AG434EMBWWH6ISOBHK4J6JLC5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662545090.44_warc_CC-MAIN-20220522063657-20220522093657-00683.warc.gz\"}"}