-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Self-Attentional Acoustic Model (#416)
* add self_attentional_am * PositionEmbedder * add nn.py * add unit test * initial fixes * fixed some type annotations * fixed PositionEmbedder * use add_serializable_component in SAAMMultiHeadedSelfAttention * use add_serializable_component for TransformerEncoderLayer * use add_serializable_component for TransformerSeqTransducer * add some missing add_serializable_component calls * rename to SAAMSeqTransducer * add some comments, and import sklearn only if needed
- Loading branch information
Showing
9 changed files
with
735 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
speech-self-att: !Experiment | ||
exp_global: !ExpGlobal | ||
model_file: examples/output/{EXP}.mod | ||
log_file: examples/output/{EXP}.log | ||
dropout: 0.2 | ||
preproc: !PreprocRunner | ||
overwrite: False | ||
tasks: | ||
- !PreprocExtract | ||
in_files: | ||
- examples/data/LDC94S13A.yaml | ||
out_files: | ||
- examples/data/LDC94S13A.h5 | ||
specs: !MelFiltExtractor {} | ||
model: !DefaultTranslator | ||
src_reader: !H5Reader | ||
transpose: True | ||
trg_reader: !PlainTextReader | ||
vocab: !Vocab {vocab_file: examples/data/head.en.vocab} | ||
src_embedder: !NoopEmbedder | ||
emb_dim: 40 | ||
encoder: !SAAMSeqTransducer | ||
layers: 2 | ||
input_dim: 40 | ||
hidden_dim: 32 | ||
downsample_factor: 2 | ||
ff_hidden_dim: 32 | ||
pos_encoding_type: embedding | ||
diag_gauss_mask: 3.0 | ||
ff_lstm: True | ||
attender: !MlpAttender | ||
state_dim: 32 | ||
hidden_dim: 32 | ||
input_dim: 32 | ||
trg_embedder: !SimpleWordEmbedder | ||
emb_dim: 32 | ||
train: !SimpleTrainingRegimen | ||
src_file: examples/data/LDC94S13A.h5 | ||
trg_file: examples/data/LDC94S13A.char | ||
run_for_epochs: 1 | ||
batcher: !SrcBatcher | ||
batch_size: 3 | ||
pad_src_to_multiple: 4 | ||
src_pad_token: ~ | ||
dev_tasks: | ||
- !LossEvalTask | ||
src_file: examples/data/LDC94S13A.h5 | ||
ref_file: examples/data/LDC94S13A.char |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
This module holds normalizers for neural networks. Currently implemented is layer norm, later batch norm etc. may be added. | ||
""" | ||
|
||
import dynet as dy | ||
|
||
from xnmt import param_collection | ||
from xnmt.persistence import Serializable, serializable_init | ||
|
||
|
||
class LayerNorm(Serializable): | ||
yaml_tag = "!LayerNorm" | ||
|
||
@serializable_init | ||
def __init__(self, d_hid): | ||
subcol = param_collection.ParamManager.my_params(self) | ||
self.p_g = subcol.add_parameters(dim=d_hid, init=dy.ConstInitializer(1.0)) | ||
self.p_b = subcol.add_parameters(dim=d_hid, init=dy.ConstInitializer(0.0)) | ||
|
||
def __call__(self, x): | ||
g = dy.parameter(self.p_g) | ||
b = dy.parameter(self.p_b) | ||
return dy.layer_norm(x, g, b) |
Empty file.
Oops, something went wrong.