Views
No views yet
pip install transformers1
2import torch
3from transformers import PreTrainedTokenizerFast
4from plantgfm.modeling_plantgfm import PlantGFMForCausalLM
5from plantgfm.configuration_plantgfm import PlantGFMConfig
6
7config = PlantGFMConfig.from_pretrained("hu-lab/PlantGFM")
8tokenizer = PreTrainedTokenizerFast.from_pretrained("hu-lab/PlantGFM")
9model = PlantGFMForCausalLM.from_pretrained("hu-lab/PlantGFM", config=config)
10
11
12sequences = ["CCCTAAACCCTAAACCCTAAA", "ATGGCGTGGCTG"]
13
14# get single-nucleotide sequences with space between each base
15single_nucleotide_sequences = list(map(lambda seq: " ".join(list(seq)), sequences))
16
17
18tokenized_sequences = tokenizer(single_nucleotide_sequences, padding="longest")["input_ids"]
19input_ids = torch.LongTensor(tokenized_sequences)
20
21embd = model(input_ids=input_ids, output_hidden_states=True)["hidden_states"][0]
22print(embd)