Skip to content

Commit b3150ee

Browse files
henrythe9thrasbt
andauthored
Print out embeddings for more illustrative learning (#481)
* print out embeddings for illustrative learning * suggestion print embeddingcontents --------- Co-authored-by: rasbt <[email protected]>
1 parent b524afe commit b3150ee

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Diff for: ch02/01_main-chapter-code/ch02.ipynb

+16-4
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,10 @@
17881788
],
17891789
"source": [
17901790
"token_embeddings = token_embedding_layer(inputs)\n",
1791-
"print(token_embeddings.shape)"
1791+
"print(token_embeddings.shape)\n",
1792+
"\n",
1793+
"# uncomment & execute the following line to see how the embeddings look like\n",
1794+
"# print(token_embedding)"
17921795
]
17931796
},
17941797
{
@@ -1807,7 +1810,10 @@
18071810
"outputs": [],
18081811
"source": [
18091812
"context_length = max_length\n",
1810-
"pos_embedding_layer = torch.nn.Embedding(context_length, output_dim)"
1813+
"pos_embedding_layer = torch.nn.Embedding(context_length, output_dim)\n",
1814+
"\n",
1815+
"# uncomment & execute the following line to see how the embedding layer weights look like\n",
1816+
"# print(pos_embedding_layer.weight)"
18111817
]
18121818
},
18131819
{
@@ -1826,7 +1832,10 @@
18261832
],
18271833
"source": [
18281834
"pos_embeddings = pos_embedding_layer(torch.arange(max_length))\n",
1829-
"print(pos_embeddings.shape)"
1835+
"print(pos_embeddings.shape)\n",
1836+
"\n",
1837+
"# uncomment & execute the following line to see how the embeddings look like\n",
1838+
"# print(pos_embeddings)"
18301839
]
18311840
},
18321841
{
@@ -1853,7 +1862,10 @@
18531862
],
18541863
"source": [
18551864
"input_embeddings = token_embeddings + pos_embeddings\n",
1856-
"print(input_embeddings.shape)"
1865+
"print(input_embeddings.shape)\n",
1866+
"\n",
1867+
"# uncomment & execute the following line to see how the embeddings look like\n",
1868+
"# print(input_embeddings)"
18571869
]
18581870
},
18591871
{

0 commit comments

Comments
 (0)