

{"id":16817,"date":"2018-06-05T05:40:09","date_gmt":"2018-06-05T05:40:09","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=16817"},"modified":"2021-05-14T11:00:14","modified_gmt":"2021-05-14T05:30:14","slug":"tensorflow-word2vec","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/","title":{"rendered":"Word2Vec: TensorFlow Vector Representation Of Words"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">In this <strong>TensorFlow<\/strong> article &#8220;Word2Vec: TensorFlow Vector Representation Of Words&#8221;, we\u2019ll be looking at a convenient method of representing words as vectors, also known as word embeddings. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Moreover, in this TensorFlow word embedding tutorial, we will be looking at scaling with noise-induced training &amp; Word2Vec skip gram model, Along with this, we will discuss how to build graph and training for TensorFlow Word2Vec and also examples of Word2Vec in TensorFlow.<\/span><\/p>\n<p>So, let&#8217;s start Word2Vec in TensorFlow.<\/p>\n<h2><span style=\"font-weight: 400;\">Vector Representation of Words<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Most of the models that you\u2019ll work with will have high-dimensional vectors of datasets ranging from pixel values in raw images to power densities in audio tracks. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now, all the useful information that your <strong>image<\/strong> and <strong>audio recognition models<\/strong> will need is in this raw data whereas, in the case of working with natural language processing, words are treated as symbols, a Word2Vec example being &#8216;cat&#8217; that is taken as\u00a0<\/span><span style=\"font-weight: 400;\">Id537<\/span><span style=\"font-weight: 400;\">\u00a0and &#8216;dog&#8217; as\u00a0<\/span><span style=\"font-weight: 400;\">Id143<\/span><span style=\"font-weight: 400;\">. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">This allotment is random and provides no information if the data is interrelated. Therefore, representing words as individual identities may lead to sparsity in the dataset, which increases the need for more data for your model. Vector representation of data can, therefore, let you tackle these problems.<\/span><\/p>\n<div id=\"attachment_16824\" style=\"width: 1573px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/image-27.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-16824\" class=\"wp-image-16824 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/image-27.png\" alt=\"Word2vec- (Word Embedding)\" width=\"1563\" height=\"574\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/image-27.png 1563w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/image-27-150x55.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/image-27-300x110.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/image-27-768x282.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/image-27-1024x376.png 1024w\" sizes=\"auto, (max-width: 1563px) 100vw, 1563px\" \/><\/a><p id=\"caption-attachment-16824\" class=\"wp-caption-text\">Word2vec- (Word Embedding)<\/p><\/div>\n<div><\/div>\n<div id=\":ef.ma\" class=\"Mu SP\"><span id=\":ef.co\" class=\"tL8wMe EMoHub\" dir=\"ltr\">VSMs or Vector Space Models embed nearby these words in a vector space.\u00a0<\/span><\/div>\n<div id=\":eg.ma\" class=\"Mu SP\" title=\"September 15, 2018 at 2:34:45 PM UTC+5:30\">\n<div id=\":eg.at\" class=\"xH\">We typically use VSMs with natural language processing but it is also possible to use them elsewhere as per the need.<\/div>\n<\/div>\n<p><span style=\"font-weight: 400;\">The distribution hypothesis, tells that the choice of words in the same context share a common meaning and this can be used by dividing the approach into two categories:\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Count-Based Methods<\/span><span style=\"font-weight: 400;\">\u00a0(e.g.\u00a0<\/span><strong>Latent Semantic Analysis<\/strong><span style=\"font-weight: 400;\">), and\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Predictive Methods<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">To say it in simple terms, the former calculates the frequency with which the word occurs repeatedly with its neighbors and then maps this count to a dense vector for every input. On the other hand, the latter tries to predict the word from its neighbors using dense vectors which are the parameters of the model.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Scaling with Noise-Induced Training<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The maximum likelihood principle in TensorFlow Word2Vec can be used to maximize the predictability of the next word\u00a0with a conditional probability where the previous words are given using a softmax regression,<\/span><\/p>\n<div id=\"attachment_16825\" style=\"width: 383px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Capture-1-2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-16825\" class=\"wp-image-16825 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Capture-1-2.png\" alt=\"Word2vec\" width=\"373\" height=\"89\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Capture-1-2.png 373w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Capture-1-2-150x36.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Capture-1-2-300x72.png 300w\" sizes=\"auto, (max-width: 373px) 100vw, 373px\" \/><\/a><p id=\"caption-attachment-16825\" class=\"wp-caption-text\">Scaling with Noise-Induced Training<\/p><\/div>\n<p>We train the model by maximizing its\u00a0log-likelihood,<\/p>\n<div id=\"attachment_16826\" style=\"width: 484px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Capture2-2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-16826\" class=\"wp-image-16826 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Capture2-2.png\" alt=\"Word2vec\" width=\"474\" height=\"102\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Capture2-2.png 474w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Capture2-2-150x32.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Capture2-2-300x65.png 300w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><p id=\"caption-attachment-16826\" class=\"wp-caption-text\">Word2vec<\/p><\/div>\n<p><span style=\"font-weight: 400;\">This results in a normalized model but turns out to be costly, since you need to calculate and normalize each probability using the score for all words, at every step of the training.<\/span><\/p>\n<div id=\"attachment_16827\" style=\"width: 885px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/embeddings.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-16827\" class=\"wp-image-16827 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/embeddings.png\" alt=\"Word2vec\" width=\"875\" height=\"643\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/embeddings.png 875w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/embeddings-150x110.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/embeddings-300x220.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/embeddings-768x564.png 768w\" sizes=\"auto, (max-width: 875px) 100vw, 875px\" \/><\/a><p id=\"caption-attachment-16827\" class=\"wp-caption-text\">Vector Representation Of Words &#8211; Normalised model<\/p><\/div>\n<p><span style=\"font-weight: 400;\">The good thing is that for feature learning we do not need a full probabilistic model in Word2Vec. The two models, CBOW and skip-gram, are rather trained by binary classification technique to differentiate the target words\u00a0from\u00a0the\u00a0noise. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">The figure given below shows the same for the CBOW model and it can be inverted for the skip-gram model.<\/span><\/p>\n<div id=\"attachment_16828\" style=\"width: 847px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/noise-classifier.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-16828\" class=\"wp-image-16828 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/noise-classifier.png\" alt=\"Word2vec\" width=\"837\" height=\"520\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/noise-classifier.png 837w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/noise-classifier-150x93.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/noise-classifier-300x186.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/noise-classifier-768x477.png 768w\" sizes=\"auto, (max-width: 837px) 100vw, 837px\" \/><\/a><p id=\"caption-attachment-16828\" class=\"wp-caption-text\">Word2vec CBOW Model &#8211; Binary Classification Technique<\/p><\/div>\n<p><span style=\"font-weight: 400;\">You can use the\u00a0<\/span><span style=\"font-weight: 400;\">estimation<\/span><span style=\"font-weight: 400;\">\u00a0loss for noise, with the function\u00a0<\/span><span style=\"font-weight: 400;\">tf.nn.nce_loss()<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Word2Vec Skip Gram Model<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Consider the dataset<\/span><br \/>\n<em>The quick brown fox jumped over the lazy dog<\/em><\/p>\n<p><span style=\"font-weight: 400;\">Context, here in the scope of this TensorFlow Word2Vec tutorial is defined as the words that fall right at the adjacent sides of a target word. <\/span><\/p>\n<p><em><span style=\"font-weight: 400;\">([the, brown], quick), ([quick, fox], brown), ([brown, jumped], fox), &#8230;<\/span><\/em><\/p>\n<p><span style=\"font-weight: 400;\">As you are already aware skip-gram model does the inverting and tries to predict from the target word, so the prediction goes like &#8216;the&#8217; and &#8216;brown&#8217; from &#8216;quick&#8217;, &#8216;quick&#8217; and &#8216;fox&#8217; from &#8216;brown&#8217;, etc.<\/span><\/p>\n<p><em><span style=\"font-weight: 400;\">(quick, the), (quick, brown), (brown, quick), (brown, fox), &#8230;<\/span><\/em><\/p>\n<p><span style=\"font-weight: 400;\">Let&#8217;s do the training, where the aim is to predict\u00a0<\/span><span style=\"font-weight: 400;\">the<\/span><span style=\"font-weight: 400;\">\u00a0form\u00a0<\/span><span style=\"font-weight: 400;\">quick<\/span><span style=\"font-weight: 400;\">. You can draw a noise distribution,\u00a0P(w) using the function initialized with\u00a0<\/span><strong>num_noise=1<\/strong><span style=\"font-weight: 400;\">\u00a0and let us say that you select\u00a0<\/span><span style=\"font-weight: 400;\">sheep<\/span><span style=\"font-weight: 400;\">\u00a0as the noisy example.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now it\u2019s time to update the word embedding parameters to improve the main function by calculating the gradient with respect to the parameters\u00a0<\/span><span style=\"font-weight: 400;\">\u03b8.<\/span><span style=\"font-weight: 400;\"> You take small steps towards the gradient and thus updating the embeddings.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The visualization is done by projecting the vectors to 2D using\u00a0a dimensionality reduction technique. If you look at these visualizations, you will notice that these vectors possess some useful information about words and they&#8217;re interconnectedness. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, pairs of male-female,\u00a0verb tense\u00a0or\u00a0country-capital\u00a0relationships.<\/span><\/p>\n<div id=\"attachment_16829\" style=\"width: 1515px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/visuals.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-16829\" class=\"wp-image-16829 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/visuals.png\" alt=\"Word2vec\" width=\"1505\" height=\"527\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/visuals.png 1505w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/visuals-150x53.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/visuals-300x105.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/visuals-768x269.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/visuals-1024x359.png 1024w\" sizes=\"auto, (max-width: 1505px) 100vw, 1505px\" \/><\/a><p id=\"caption-attachment-16829\" class=\"wp-caption-text\">Vector Representation Of Words<\/p><\/div>\n<h2><span style=\"font-weight: 400;\">Building the Graph of Word2Vec in TensorFlow<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">You should start with defining the embedded matrix which is really random as shown below.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">embeddings = tf.Variable(\r\n    tf.random_uniform([vocabulary_size, embedding_size], -1.0, 1.0))<\/pre>\n<p><span style=\"font-weight: 400;\">We use a logistic regression model in the vector representation of words to define the estimation loss. Therefore, defining the weights and biases, the code looks like:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">nce_weights = tf.Variable(\r\n  tf.truncated_normal([vocabulary_size, embedding_size],\r\n                      stddev=1.0 \/ math.sqrt(embedding_size)))\r\nnce_biases = tf.Variable(tf.zeros([vocabulary_size]))<\/pre>\n<p><span style=\"font-weight: 400;\">You can now define skip-gram model graph which will take two inputs, the first one is a group of discrete integers representing the context words and the other input for the target words. Creating the placeholders, the code looks like the following:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">train_inputs = tf.placeholder(tf.int32, shape=[batch_size])\r\ntrain_labels = tf.placeholder(tf.int32, shape=[batch_size, 1])\r\nembed = tf.nn.embedding_lookup(embeddings, train_inputs)<\/pre>\n<p>By now, you\u2019ll be having the embeddings for each word and you can now predict the target word.<\/p>\n<pre class=\"EnlighterJSRAW\">loss = tf.reduce_mean(\r\n  tf.nn.nce_loss(weights=nce_weights,\r\n                 biases=nce_biases,\r\n                 labels=train_labels,\r\n                 inputs=embed,\r\n                 num_sampled=num_sampled,\r\n                 num_classes=vocabulary_size))<\/pre>\n<p><span style=\"font-weight: 400;\">This will create a loss node, and add more nodes for gradient computation and parameter updation. You should use stochastic gradient descent to help you out.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\"># Using stochastic gradient descent:\r\noptimizer = tf.train.GradientDescentOptimizer(learning_rate=1.0).minimize(loss)<\/pre>\n<h2><span style=\"font-weight: 400;\">Training for Word2Vec With TensorFlow<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Use\u00a0<\/span><span style=\"font-weight: 400;\">feed_dict<\/span><span style=\"font-weight: 400;\">\u00a0to put data into the placeholders and call the session <\/span><strong>tf.Session.run<\/strong><span style=\"font-weight: 400;\">\u00a0with the data in a loop:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">for inputs, labels in generate_batch(...):\r\n  feed_dict = {train_inputs: inputs, train_labels: labels}\r\n  _, cur_loss = session.run([optimizer, loss], feed_dict=feed_dict)<\/pre>\n<h2><span style=\"font-family: Georgia, Georgia, serif;\">Visualizing the Learned Embeddings<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The visualization is as shown below using t-SNE.<\/span><\/p>\n<div id=\"attachment_16830\" style=\"width: 893px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/graph.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-16830\" class=\"wp-image-16830 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/graph.png\" alt=\"Word2vec\" width=\"883\" height=\"873\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/graph.png 883w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/graph-150x148.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/graph-300x297.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/graph-768x759.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/graph-100x100.png 100w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/a><p id=\"caption-attachment-16830\" class=\"wp-caption-text\">Visualizing the Learned Embeddings<\/p><\/div>\n<p><span style=\"font-weight: 400;\">If you look at it closely you will notice that words that are similar cluster near each other as expected.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Evaluating Embeddings<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">A simple way to evaluate embeddings is to use them to predict semantical and syntactical relationship giving a kind of analogy and thus called an analogical reasoning. A dataset is available for download from <\/span><strong>\u00a0<a href=\"http:\/\/download.tensorflow.org\/data\/questions-words.txt\">download.tensorflow.org<\/a><\/strong>.<\/p>\n<p><strong>build_eval_graph()\u00a0and\u00a0<\/strong><span style=\"font-weight: 400;\"><strong>eval()<\/strong><\/span><span style=\"font-weight: 400;\">\u00a0functions are used to look at the evaluations. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">The accuracy affects the choice of hyperparameters. Achieving a good performance requires training over a huge dataset, and you can use properties such as subsampling to get better results.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Optimization in TensorFlow<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Tensorflow offers code flexibility and you can create your own loss function by writing an expression for the new objective after which the optimizer will compute the derivatives for you. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Optimization needs to make your work faster and better and you should take a look at the previous article of Tensorflow Optimization for more details.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"> The code used in this tutorial is simple and the speed is compromised because we use <strong>Python<\/strong> for reading and feeding data items. If you find your model has serious complications, we recommend implementing a custom data reader for your problem. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the case of Skip-Gram modelling, you can take a look at\u00a0model\/tutorials\/embeddings\/word2vec.py, where it has already been done as an example.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can always benchmark the results against each other to analyze performance improvements at each stage.<\/span><\/p>\n<p>So, this was all about Word2Vec tutorial in TensorFlow. Hope you like our explanation of vector representation as words.<\/p>\n<h2><span style=\"font-weight: 400;\">Conclusion<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Hence, you saw what word embeddings are, why they are so useful and how to create a simple Word2Vec model. Also, we saw computing the word embeddings efficiently. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Moreover, TensorFlow offers the users flexibility for the users to experiment with their models and optimize the implementation. Lastly, we discussed Word2Vec example. Next up, is the tutorial on improving <strong>linear models using external kernel method<\/strong>. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Furthermore, if you have any doubt regarding Word2Vec in TensorFlow, feel free to ask through the comment section.\u00a0<\/span><span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1925,&quot;href&quot;:&quot;http:\\\/\\\/download.tensorflow.org\\\/data\\\/questions-words.txt&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251210104332\\\/http:\\\/\\\/download.tensorflow.org\\\/data\\\/questions-words.txt&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-01-23 02:06:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-20 13:47:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-04 16:09:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-12 16:28:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-23 04:44:08&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-05 10:41:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-15 13:17:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-20 11:54:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-24 12:04:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-30 01:01:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-05 07:15:04&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-07-05 07:15:04&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this TensorFlow article &#8220;Word2Vec: TensorFlow Vector Representation Of Words&#8221;, we\u2019ll be looking at a convenient method of representing words as vectors, also known as word embeddings. Moreover, in this TensorFlow word embedding tutorial,&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":16823,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[9296,12944,14612,15358,16222,16223,16224,16225],"class_list":["post-16817","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tensorflow","tag-optimization","tag-skip-gram-model","tag-tensorflow-word2vec","tag-vector-representation-of-words","tag-word-embedding","tag-word2vec","tag-word2vec-example","tag-word2vec-skip-gram-model"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Word2Vec: TensorFlow Vector Representation Of Words - DataFlair<\/title>\n<meta name=\"description\" content=\"TensorFlow vector representation as words, Scaling with Noise-Induced Training, skip gram model, Training for Word2Vec, word embedding visualizing, graph\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Word2Vec: TensorFlow Vector Representation Of Words - DataFlair\" \/>\n<meta property=\"og:description\" content=\"TensorFlow vector representation as words, Scaling with Noise-Induced Training, skip gram model, Training for Word2Vec, word embedding visualizing, graph\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-05T05:40:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-14T05:30:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Vector-Representation-of-Words-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Word2Vec: TensorFlow Vector Representation Of Words - DataFlair","description":"TensorFlow vector representation as words, Scaling with Noise-Induced Training, skip gram model, Training for Word2Vec, word embedding visualizing, graph","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/","og_locale":"en_US","og_type":"article","og_title":"Word2Vec: TensorFlow Vector Representation Of Words - DataFlair","og_description":"TensorFlow vector representation as words, Scaling with Noise-Induced Training, skip gram model, Training for Word2Vec, word embedding visualizing, graph","og_url":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-06-05T05:40:09+00:00","article_modified_time":"2021-05-14T05:30:14+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Vector-Representation-of-Words-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Word2Vec: TensorFlow Vector Representation Of Words","datePublished":"2018-06-05T05:40:09+00:00","dateModified":"2021-05-14T05:30:14+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/"},"wordCount":1327,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Vector-Representation-of-Words-01.jpg","keywords":["optimization","Skip Gram Model","TensorFlow Word2vec","vector representation of words","word embedding","Word2Vec","Word2Vec example","Word2Vec skip gram model"],"articleSection":["Tensorflow Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/","url":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/","name":"Word2Vec: TensorFlow Vector Representation Of Words - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Vector-Representation-of-Words-01.jpg","datePublished":"2018-06-05T05:40:09+00:00","dateModified":"2021-05-14T05:30:14+00:00","description":"TensorFlow vector representation as words, Scaling with Noise-Induced Training, skip gram model, Training for Word2Vec, word embedding visualizing, graph","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Vector-Representation-of-Words-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Vector-Representation-of-Words-01.jpg","width":1200,"height":628,"caption":"Word2vec"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/tensorflow-word2vec\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Tensorflow Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/tensorflow\/"},{"@type":"ListItem","position":3,"name":"Word2Vec: TensorFlow Vector Representation Of Words"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/16817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=16817"}],"version-history":[{"count":7,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/16817\/revisions"}],"predecessor-version":[{"id":94569,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/16817\/revisions\/94569"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/16823"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=16817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=16817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=16817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}