Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LEE-Transformers
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Ebert
LEE-Transformers
Commits
a0e0cbbf
Commit
a0e0cbbf
authored
1 year ago
by
Jan Ebert
Browse files
Options
Downloads
Patches
Plain Diff
Add "un-embedding" layer
A layer that uses the input embedding for obtaining output embeddings.
parent
3870da20
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lee_transformers/layers/utils.py
+30
-0
30 additions, 0 deletions
lee_transformers/layers/utils.py
with
30 additions
and
0 deletions
lee_transformers/layers/utils.py
+
30
−
0
View file @
a0e0cbbf
...
...
@@ -19,6 +19,36 @@ class ResidualConnection(th.nn.Module):
return
x
+
self
.
module
(
x
)
class
UnEmbedding
(
th
.
nn
.
Module
):
"""
An weight-tied
"
un-embedding
"
layer.
"
Un-embedding
"
means that a tensor of shape `(E,)` will be
transformed to a tensor of shape `(N,)`, where E is the embedding
size (number of features), N is the number of embeddings. This is is
contrast to the standard embedding function, which transforms a
tensor of shape `(N,)` to a tensor of shape `(E,)`.
"""
def
__init__
(
self
,
embedding
:
th
.
nn
.
Embedding
)
->
None
:
self
.
embedding
=
embedding
def
forward
(
self
,
x
:
torch
.
Tensor
)
->
torch
.
Tensor
:
""""
Un-embed
"
the given input tensor.
Args:
x: Tensor to un-embed.
Shape:
- x: `(..., E)`.
- output: `(..., N)`.
where E is the embedding size (number of features), N is the
number of embeddings.
"""
return
x
@
self
.
embedding
.
weight
.
t
()
class
ArgSelector
(
th
.
nn
.
Module
):
"""
Wraps a module to filter out a single arguments.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment