forked from facebookresearch/mmf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Add Late fusion model (facebookresearch#77)
Summary: Pull Request resolved: https://github.com/fairinternal/pythia-internal/pull/77 Reviewed By: apsdehal Differential Revision: D21107711 Pulled By: vedanuj fbshipit-source-id: bc1e7bda05ab6bdee8aaaafe95d878116d978d20
- Loading branch information
Showing
6 changed files
with
137 additions
and
9 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,52 @@ | ||
# Mostly same configs/models/mmbt/defaults.yaml config | ||
model_config: | ||
late_fusion: | ||
# Either pretraining or classification | ||
bert_model_name: bert-base-uncased | ||
direct_features_input: false | ||
freeze_text: false | ||
freeze_modal: false | ||
freeze_complete_base: false | ||
finetune_lr_multiplier: 1 | ||
# Dimension of the embedding finally returned by the modal encoder | ||
modal_hidden_size: 2048 | ||
# Dimension of the embedding finally returned by the text encoder | ||
text_hidden_size: 768 | ||
# Used when classification head is activated | ||
num_labels: 2 | ||
# Number of features extracted out per image | ||
num_features: 100 | ||
|
||
modal_encoder: | ||
type: resnet152 | ||
params: | ||
pretrained: true | ||
pool_type: avg | ||
num_output_features: 1 | ||
|
||
text_encoder: | ||
type: transformer | ||
params: | ||
bert_model_name: ${model_config.late_fusion.bert_model_name} | ||
hidden_size: 768 | ||
num_hidden_layers: 12 | ||
num_attention_heads: 12 | ||
output_attentions: false | ||
output_hidden_states: false | ||
|
||
modal_classifier: | ||
type: mlp | ||
params: | ||
in_dim: 2048 | ||
out_dim: 2 | ||
hidden_dim: 768 | ||
num_layers: 0 | ||
|
||
|
||
text_classifier: | ||
type: mlp | ||
params: | ||
in_dim: 768 | ||
out_dim: 2 | ||
hidden_dim: 768 | ||
num_layers: 0 |
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,29 @@ | ||
includes: | ||
- configs/datasets/hateful_memes/bert.yaml | ||
|
||
model_config: | ||
late_fusion: | ||
metrics: | ||
- accuracy | ||
losses: | ||
- type: cross_entropy | ||
|
||
scheduler: | ||
type: warmup_linear | ||
params: | ||
num_warmup_steps: 2000 | ||
num_training_steps: ${training.max_updates} | ||
|
||
optimizer: | ||
type: adam_w | ||
params: | ||
lr: 5e-5 | ||
eps: 1e-8 | ||
|
||
training: | ||
batch_size: 128 | ||
lr_scheduler: true | ||
max_updates: 22000 | ||
monitored_metric: hateful_memes/accuracy | ||
pretrained_mapping: | ||
base: base |