Views
No views yet
1from transformers import AutoTokenizer, AutoModel
2
3model_name = "CompBioDSA/MutBERT-Multi"
4tokenizer = AutoTokenizer.from_pretrained(model_name)
5model = AutoModel.from_pretrained(model_name, trust_remote_code=True)1import torch
2import torch.nn.functional as F
3
4from transformers import AutoTokenizer, AutoModel
5
6model_name = "CompBioDSA/MutBERT-Multi"
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
9
10dna = "ATCGGGGCCCATTA"
11inputs = tokenizer(dna, return_tensors='pt')["input_ids"]
12
13mut_inputs = F.one_hot(inputs, num_classes=len(tokenizer)).float().to("cpu") # len(tokenizer) is vocab size
14last_hidden_state = model(mut_inputs).last_hidden_state # [1, sequence_length, 768]
15# or: last_hidden_state = model(mut_inputs)[0] # [1, sequence_length, 768]
16
17# embedding with mean pooling
18embedding_mean = torch.mean(last_hidden_state[0], dim=0)
19print(embedding_mean.shape) # expect to be 768
20
21# embedding with max pooling
22embedding_max = torch.max(last_hidden_state[0], dim=0)[0]
23print(embedding_max.shape) # expect to be 768
241from transformers import AutoModelForSequenceClassification
2
3model_name = "CompBioDSA/MutBERT-Multi"
4model = AutoModelForSequenceClassification.from_pretrained(model_name, trust_remote_code=True, num_labels=2)linear and dynamic. To extend the model's context window you need to add rope_scaling parameter.1model_name = "CompBioDSA/MutBERT-Multi"
2model = AutoModel.from_pretrained(model_name,
3 trust_remote_code=True,
4 rope_scaling={'type': 'dynamic','factor': 2.0}
5 ) # 2.0 for x2 scaling, 4.0 for x4, etc..