Spaces:
Sleeping
Sleeping
Update pipeline.py
Browse files- pipeline.py +8 -19
pipeline.py
CHANGED
|
@@ -431,11 +431,7 @@ class FairseqStyleMultiheadAttention(nn.Module):
|
|
| 431 |
|
| 432 |
|
| 433 |
class TransformerSentenceEncoderLayer(nn.Module):
|
| 434 |
-
|
| 435 |
-
# BEFORE the residual add -- this specific pre-residual signal is what
|
| 436 |
-
# the fine-tuned layer_weights in LinearAdapter were trained to combine
|
| 437 |
-
# across all 12 layers. Using the post-residual hidden state instead
|
| 438 |
-
# would silently feed the adapter the wrong signal.
|
| 439 |
def __init__(self, embedding_dim, ffn_embedding_dim, num_attention_heads,
|
| 440 |
dropout=0.1, attention_dropout=0.1, activation_dropout=0.1,
|
| 441 |
layer_norm_first=False):
|
|
@@ -589,15 +585,12 @@ class LinearAdapter(nn.Module):
|
|
| 589 |
|
| 590 |
|
| 591 |
class SignLanguageByT5Encoder(nn.Module):
|
| 592 |
-
def __init__(self,
|
| 593 |
super().__init__()
|
| 594 |
self.adapter = LinearAdapter()
|
| 595 |
-
self.block = nn.ModuleList([
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
])
|
| 599 |
-
self.final_layer_norm = T5LayerNorm(t5_config.d_model, eps=t5_config.layer_norm_epsilon)
|
| 600 |
-
self.dropout = nn.Dropout(t5_config.dropout_rate)
|
| 601 |
|
| 602 |
def forward(self, face, left_hand, right_hand, body_posture):
|
| 603 |
inputs_embeds = self.adapter(face, left_hand, right_hand, body_posture)
|
|
@@ -611,7 +604,7 @@ class SignLanguageByT5Encoder(nn.Module):
|
|
| 611 |
for block in self.block:
|
| 612 |
layer_outputs = block(hidden_states, attention_mask=extended_attention_mask, position_bias=position_bias)
|
| 613 |
hidden_states = layer_outputs[0]
|
| 614 |
-
position_bias = layer_outputs[
|
| 615 |
|
| 616 |
hidden_states = self.final_layer_norm(hidden_states)
|
| 617 |
hidden_states = self.dropout(hidden_states)
|
|
@@ -621,15 +614,11 @@ class SignLanguageByT5Encoder(nn.Module):
|
|
| 621 |
class SignLanguageByT5(nn.Module):
|
| 622 |
def __init__(self, encoder_config, decoder_config):
|
| 623 |
super().__init__()
|
| 624 |
-
|
| 625 |
-
# and referencing a module-level variable instead (as in an earlier
|
| 626 |
-
# draft) breaks the moment this class is imported into a different
|
| 627 |
-
# file than wherever that variable happened to be defined.
|
| 628 |
self.decoder_config = decoder_config
|
| 629 |
self.decoder_emb = nn.Embedding(decoder_config.vocab_size, decoder_config.d_model)
|
| 630 |
self.encoder = SignLanguageByT5Encoder(encoder_config)
|
| 631 |
-
|
| 632 |
-
# embed_tokens as a constructor arg -- construct bare, then assign.
|
| 633 |
self.decoder = T5Stack(decoder_config)
|
| 634 |
self.decoder.embed_tokens = self.decoder_emb
|
| 635 |
self.lm_head = nn.Linear(decoder_config.d_model, decoder_config.vocab_size, bias=False)
|
|
|
|
| 431 |
|
| 432 |
|
| 433 |
class TransformerSentenceEncoderLayer(nn.Module):
|
| 434 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
def __init__(self, embedding_dim, ffn_embedding_dim, num_attention_heads,
|
| 436 |
dropout=0.1, attention_dropout=0.1, activation_dropout=0.1,
|
| 437 |
layer_norm_first=False):
|
|
|
|
| 585 |
|
| 586 |
|
| 587 |
class SignLanguageByT5Encoder(nn.Module):
|
| 588 |
+
def __init__(self, config):
|
| 589 |
super().__init__()
|
| 590 |
self.adapter = LinearAdapter()
|
| 591 |
+
self.block = nn.ModuleList([T5Block(config, has_relative_attention_bias=(i == 0)) for i in range(config.num_layers)])
|
| 592 |
+
self.final_layer_norm = T5LayerNorm(config.d_model, eps=config.layer_norm_epsilon)
|
| 593 |
+
self.dropout = nn.Dropout(config.dropout_rate)
|
|
|
|
|
|
|
|
|
|
| 594 |
|
| 595 |
def forward(self, face, left_hand, right_hand, body_posture):
|
| 596 |
inputs_embeds = self.adapter(face, left_hand, right_hand, body_posture)
|
|
|
|
| 604 |
for block in self.block:
|
| 605 |
layer_outputs = block(hidden_states, attention_mask=extended_attention_mask, position_bias=position_bias)
|
| 606 |
hidden_states = layer_outputs[0]
|
| 607 |
+
position_bias = layer_outputs[-1]
|
| 608 |
|
| 609 |
hidden_states = self.final_layer_norm(hidden_states)
|
| 610 |
hidden_states = self.dropout(hidden_states)
|
|
|
|
| 614 |
class SignLanguageByT5(nn.Module):
|
| 615 |
def __init__(self, encoder_config, decoder_config):
|
| 616 |
super().__init__()
|
| 617 |
+
|
|
|
|
|
|
|
|
|
|
| 618 |
self.decoder_config = decoder_config
|
| 619 |
self.decoder_emb = nn.Embedding(decoder_config.vocab_size, decoder_config.d_model)
|
| 620 |
self.encoder = SignLanguageByT5Encoder(encoder_config)
|
| 621 |
+
|
|
|
|
| 622 |
self.decoder = T5Stack(decoder_config)
|
| 623 |
self.decoder.embed_tokens = self.decoder_emb
|
| 624 |
self.lm_head = nn.Linear(decoder_config.d_model, decoder_config.vocab_size, bias=False)
|