<jupyter_start><jupyter_text>Word Embedding<jupyter_code>#import necessary libraries
from tensorflow.keras.preprocessing.text import one_hot
## Sentences
sent = ['the glass of the milk',
       'the glass of the juice',
       'the cup of tea',
       'I am a good boy',
       'I am a good developer',
       'understand the meaning of words',
       'your videos are good']
sent
#define the vocabulary size | dictionary 
voc_size = 10000<jupyter_output><empty_output><jupyter_text>One hot representation<jupyter_code>onehot_repr = [one_hot(words, voc_size) for words in sent]
print(onehot_repr)<jupyter_output>[[8839, 7985, 5387, 8839, 4054], [8839, 7985, 5387, 8839, 604], [8839, 2752, 5387, 1043], [7976, 2240, 7317, 9452, 5724], [7976, 2240, 7317, 9452, 3991], [3216, 8839, 1566, 5387, 6915], [7344, 6284, 132, 9452]]<jupyter_text>Word Embedding Representation<jupyter_code>from tensorflow.keras.layers import Embedding
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential
import numpy as np
sent_length = 8
embedded_docs = pad_sequences(onehot_repr, padding='pre', maxlen = sent_length)
print(embedded_docs)
dim=10
#build model
model = Sequential()
model.add(Embedding(voc_size, dim, input_length=sent_length))
model.compile('adam','mse')
model.summary()
print(model.predict(embedded_docs))
embedded_docs[0]
print(model.predict(embedded_docs)[0])<jupyter_output>[[-0.01600979  0.00312096 -0.04396638  0.03627886 -0.0349185  -0.02516865
  -0.03782571  0.02405502  0.02214814 -0.00281483  0.01507786  0.02916223
   0.03611392  0.00793301 -0.03033689]
 [-0.01600979  0.00312096 -0.04396638  0.03627886 -0.0349185  -0.02516865
  -0.03782571  0.02405502  0.02214814 -0.00281483  0.01507786  0.02916223
   0.03611392  0.00793301 -0.03033689]
 [-0.01600979  0.00312096 -0.04396638  0.03627886 -0.0349185  -0.02516865
  -0.03782571  0.02405502  0.02214814 -0.00281483  0.01507786  0.02916223
   0.03611392  0.00793301 -0.03033689]
 [-0.00394354 -0.02544268 -0.04179453  0.04624308 -0.04979689  0.0244992
   0.00635908 -0.04043717  0.00285687  0.0183841   0.00256523  0.00482646
   0.03445486  0.00141786 -0.00495438]
 [-0.00554899 -0.03667738 -0.02463427  0.03838489 -0.01730816  0.04947313
  -0.02067232  0.00905544 -0.04973225  0.02086634 -0.03241809 -0.00188866
   0.01878399  0.00016651  0.04241934]
 [ 0.01455828 -0.00399232  0.0053132  -0.00535119 -0.01887563 -0.0[...]
{'fraction_non_alphanumeric': 0.12494862309905466, 'fraction_numerical': 0.35182901767365393, 'mean_word_length': 4.156779661016949, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '281739', 'license': 'MIT', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1029, 'n_words': 210, 'path': 'Word Embedding using keras.ipynb', 'repo_name': 'iambalakrishnan/NLP', 'size': '2433'}