Skip to content

Commit 6e47d77

Browse files
authored
Update Readme.md
1 parent bbc204d commit 6e47d77

File tree

1 file changed

+35
-1
lines changed
  • Chapter-wise code/Code - PyTorch/6. Natural-Language-Processing/6. Machine Translation/NMT-Basic

1 file changed

+35
-1
lines changed

Chapter-wise code/Code - PyTorch/6. Natural-Language-Processing/6. Machine Translation/NMT-Basic/Readme.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,39 @@
55
### Generate French and English Word Embedding
66

77
Here, we have 3 given parameters:
8-
1. `en_embeddings`: English words and their corresponding embeddings.
8+
1. `en_embeddings`: English words and their corresponding embeddings.<br>
99
<img src="./images/en_embeddings.png"></img>
10+
11+
2. `fr_embeddings`: French words and their corresponding embeddings.<br>
12+
<img src="./images/fr_embedding.png"></img>
13+
14+
3. `en_fr`: English to French dictionary.<br>
15+
<img src="./images/en_fr_train.png"></img>
16+
17+
Now, we have to create an English embedding matrix and French embedding matrix:<br>
18+
<img src="./images/en_fr_embeddings.png.png"></img><br>
19+
```python
20+
# loop through all english, french word pairs in the english french dictionary
21+
for en_word, fr_word in en_fr.items():
22+
23+
# check that the french word has an embedding and that the english word has an embedding
24+
if fr_word in french_set and en_word in english_set:
25+
26+
# get the english embedding
27+
en_vec = english_vecs[en_word]
28+
29+
# get the french embedding
30+
fr_vec = french_vecs[fr_word]
31+
32+
# add the english embedding to the list
33+
X_l.append(en_vec)
34+
35+
# add the french embedding to the list
36+
Y_l.append(fr_vec)
37+
38+
# stack the vectors of X_l into a matrix X
39+
X = np.vstack(X_l)
40+
41+
# stack the vectors of Y_l into a matrix Y
42+
Y = np.vstack(Y_l)
43+
```

0 commit comments

Comments
 (0)