Spaces:
Sleeping
Sleeping
Download models/transformer/module/embeddings.py from Songyou/LLM-fastAPI: direct link, hf CLI and curl.
- Browser
- Download file 358 Bytes
-
https://huggingface.co/spaces/Songyou/LLM-fastAPI/resolve/main/models/transformer/module/embeddings.py
- Command line
-
hf download hf://spaces/Songyou/LLM-fastAPI/models/transformer/module/embeddings.py
-
curl -L -o embeddings.py https://huggingface.co/spaces/Songyou/LLM-fastAPI/resolve/main/models/transformer/module/embeddings.py
358 Bytes
| import torch.nn as nn | |
| import math | |
| class Embeddings(nn.Module): | |
| def __init__(self, d_model, vocab): | |
| super(Embeddings, self).__init__() | |
| # weight matrix, each row present one word | |
| self.lut = nn.Embedding(vocab, d_model) | |
| self.d_model = d_model | |
| def forward(self, x): | |
| return self.lut(x) * math.sqrt(self.d_model) | |