Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get embeddings of language encoder and Object-Relationship Encoder? #94

Closed
yezhengli-Mr9 opened this issue Feb 3, 2021 · 2 comments
Closed

Comments

@yezhengli-Mr9
Copy link

yezhengli-Mr9 commented Feb 3, 2021

Any suggestion of getting embeddings of language encoder and Object-Relationship Encoder? I refers to output_hidden_state mentioned in this blog as well as the official tutorial.

@zhmd
Copy link

zhmd commented Feb 3, 2021

I'm not 100% sure, but if you refer to the encoded representation before the cross-modality interaction module, then probably you need to hack these two lines and save these intermediate representations:

lxmert/src/lxrt/modeling.py

Lines 554 to 559 in 0db1182

for layer_module in self.layer:
lang_feats = layer_module(lang_feats, lang_attention_mask)
# Run relational layers
for layer_module in self.r_layers:
visn_feats = layer_module(visn_feats, visn_attention_mask)

If you need the ones after the cross-modality interaction module, then just take these two:

return lang_feats, visn_feats

@yezhengli-Mr9
Copy link
Author

I'm not 100% sure, but if you refer to the encoded representation before the cross-modality interaction module, then probably you need to hack these two lines and save these intermediate representations:

lxmert/src/lxrt/modeling.py

Lines 554 to 559 in 0db1182

for layer_module in self.layer:
lang_feats = layer_module(lang_feats, lang_attention_mask)
# Run relational layers
for layer_module in self.r_layers:
visn_feats = layer_module(visn_feats, visn_attention_mask)

If you need the ones after the cross-modality interaction module, then just take these two:

return lang_feats, visn_feats

Sort of help, thanks! @zhmd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants