Skip to content

Commit

Permalink
Print out embeddings for more illustrative learning (#481)
Browse files Browse the repository at this point in the history
* print out embeddings for illustrative learning

* suggestion print embeddingcontents

---------

Co-authored-by: rasbt <mail@sebastianraschka.com>
  • Loading branch information
henrythe9th and rasbt authored Jan 13, 2025
1 parent b524afe commit b3150ee
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ch02/01_main-chapter-code/ch02.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,10 @@
],
"source": [
"token_embeddings = token_embedding_layer(inputs)\n",
"print(token_embeddings.shape)"
"print(token_embeddings.shape)\n",
"\n",
"# uncomment & execute the following line to see how the embeddings look like\n",
"# print(token_embedding)"
]
},
{
Expand All @@ -1807,7 +1810,10 @@
"outputs": [],
"source": [
"context_length = max_length\n",
"pos_embedding_layer = torch.nn.Embedding(context_length, output_dim)"
"pos_embedding_layer = torch.nn.Embedding(context_length, output_dim)\n",
"\n",
"# uncomment & execute the following line to see how the embedding layer weights look like\n",
"# print(pos_embedding_layer.weight)"
]
},
{
Expand All @@ -1826,7 +1832,10 @@
],
"source": [
"pos_embeddings = pos_embedding_layer(torch.arange(max_length))\n",
"print(pos_embeddings.shape)"
"print(pos_embeddings.shape)\n",
"\n",
"# uncomment & execute the following line to see how the embeddings look like\n",
"# print(pos_embeddings)"
]
},
{
Expand All @@ -1853,7 +1862,10 @@
],
"source": [
"input_embeddings = token_embeddings + pos_embeddings\n",
"print(input_embeddings.shape)"
"print(input_embeddings.shape)\n",
"\n",
"# uncomment & execute the following line to see how the embeddings look like\n",
"# print(input_embeddings)"
]
},
{
Expand Down

0 comments on commit b3150ee

Please sign in to comment.