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

Computing Embeddings from Transformer? #20

Closed
nickbhat opened this issue Sep 28, 2021 · 3 comments
Closed

Computing Embeddings from Transformer? #20

nickbhat opened this issue Sep 28, 2021 · 3 comments

Comments

@nickbhat
Copy link

Hello,

Is there any ability to create an API for producing embeddings from input sequences? Users could implement this themselves if #19 turns out to be true. If not, perhaps an embedding API could be exposed without having to make weights publicly available?

Thanks!

@prihoda
Copy link
Collaborator

prihoda commented Sep 29, 2021

Hi @nickbhat there's a function intended for this:

def sapiens_predict_seq(seq, chain_type, model_version='latest', return_all_hiddens=False):

However, looks like the return_all_hiddens arg is actually ignored :) Do you want to create a pull request by any chance? I'm always happy to get more contributors.

It would be a simple fix here:

Btw, this way we can only get the embeddings, if you also wanted the attention weights, that would require some changes to fairseq code.

@nickbhat
Copy link
Author

nickbhat commented Oct 8, 2021

I'll take a look at this and submit a PR! Always happy to contribute :) I'll get around to it in a couple of weeks, if that's okay.

@prihoda
Copy link
Collaborator

prihoda commented Jan 17, 2022

Fixed by #21

Example usage:

from biophi.humanization.methods.sapiens.predict import sapiens_predict_seq

pred, extra = sapiens_predict_seq(
    seq=seq, # seq should be the variable region sequence only
    chain_type='H', # chain type is H or L
    return_all_hiddens=True
)

embeddings_per_layer = extra['inner_states']

@prihoda prihoda closed this as completed Jan 17, 2022
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