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

How to get embeddings from BERTT2DAb? #1

Open
trashTian opened this issue Mar 12, 2024 · 1 comment
Open

How to get embeddings from BERTT2DAb? #1

trashTian opened this issue Mar 12, 2024 · 1 comment

Comments

@trashTian
Copy link

There is my code:

H_chain = 'QVQLVESGGGSVQAGGSLSLSCAASTYTDTVGWFRQAPGKEREGVAAIYRRTGYTYSADSVKGRFTLSQDNNKNTVYLQMNSLKPEDTGIYYCATGNSVRLASWEGYFYWGQGTQVTVSS'

# H_chain = 'QVQLLESGAELVKPGASVKLSCKASGYTFTSYWMHWVKQRPGRGLEWIGMIDPNSGGTKYNEKFKSKATLTVDKPSNTAYMQLSSLTSEDSAVYYCTRRDMDYWGAGTTVTVSSASTKGPSVFPLAPSSKSTSGGTAALGCLVKDYFPEPVTVSWNSGALTSGVHTFPAVLQSSGLYSLSSVVTVPSSSLGTQTYICNVNHKPSNTKVDKKIVPKS'

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer_H = BertTokenizer.from_pretrained("w139700701/BERT2DAb_H")
model_H = BertModel.from_pretrained("w139700701/BERT2DAb_H")
model_H.to(device)
encoded_input = tokenizer_H.encode_plus(
            H_chain,
            add_special_tokens=True,
            return_tensors="pt"
        )
input_ids = encoded_input["input_ids"].to(device)
attention_mask = encoded_input["attention_mask"].to(device)

with torch.no_grad():
    outputs = model_H(input_ids, attention_mask=attention_mask)

embeddings = outputs.last_hidden_state
print(embeddings)

But for different input sequences, the same embedding will be obtained

tensor([[[ 0.0577,  0.0189, -0.0028,  ...,  0.0071,  0.0055,  0.0153],
         [ 0.0191, -0.0732, -0.0640,  ..., -0.0157,  0.0195, -0.0091],
         [ 0.0577,  0.0189, -0.0028,  ...,  0.0071,  0.0055,  0.0153]]],
       device='cuda:0')

How should I modify the code to obtain the correct embeddings ?

@Xiaoxiao0606
Copy link
Owner

Hello,
Thank you for your interest in our work!
To begin, it's recommended to employ a secondary structure annotation tool,such as proteinUnet, for splitting the sequence. Subsequently, these segmented sequence should be processed using BERT2DAb to generate their embedding representations.

We appreciate your attention to these details!

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