title: How to conceptually think about relationship between tokenized words and word embeddings?
body: <p>I have been using JJ Allaire's guide to using word embeddings in neural network model for text processing (<a href="https://jjallaire.github.io/deep-learning-with-r-notebooks/notebooks/6.1-using-word-embeddings.nb.html" rel="noreferrer">https://jjallaire.github.io/deep-learning-with-r-notebooks/notebooks/6.1-using-word-embeddings.nb.html</a>). I am confused as to how the model relates the tokenized sequences of words (x_train) back to the word embeddings that are defined using the whole dataset (instead of just the training data). Is there a way to conceptualize how the word tokens are mapped to word embeddings? Otherwise, how does a word like 'king' map to the word embedding (obtained using Glove for example). I am speaking to the relation between these chunks of code:</p>
  
  <pre><code>#building model 
  history &lt;- model %&gt;% fit(
   x_train, y_train,
   epochs = 20,
   batch_size = 32,
   validation_data = list(x_val, y_val)
  )
  
  #relating model to word embeddings
  model &lt;- keras_model_sequential() %&gt;% 
  layer_embedding(input_dim = max_words, output_dim = embedding_dim, 
                input_length = maxlen) %&gt;% 
  layer_flatten() %&gt;% 
  layer_dense(units = 32, activation = "relu") %&gt;% 
  layer_dense(units = 1, activation = "sigmoid")
  
  get_layer(model, index = 1) %&gt;% 
   set_weights(list(embedding_matrix)) %&gt;% 
   freeze_weights()
  </code></pre>
  
  <p>How is a tokenized word from the x_train linked back to a word in the embedding_matrix (especially if the embedding layer is trained on all data)?</p>