yurakuratov commited on
Commit
29cf2ee
1 Parent(s): 8141469

docs: update usage example

Browse files
Files changed (1) hide show
  1. README.md +32 -8
README.md CHANGED
@@ -4,13 +4,13 @@ tags:
4
  - human_genome
5
  ---
6
 
7
- # GENA-LM (gena-lm-bert-base-lastln-t2t)
8
 
9
  GENA-LM is a Family of Open-Source Foundational Models for Long DNA Sequences.
10
 
11
  GENA-LM models are transformer masked language models trained on human DNA sequence.
12
 
13
- Differences between GENA-LM (`gena-lm-bert-base-lastln-t2t`) and DNABERT:
14
  - BPE tokenization instead of k-mers;
15
  - input sequence size is about 4500 nucleotides (512 BPE tokens) compared to 512 nucleotides of DNABERT
16
  - pre-training on T2T vs. GRCh38.p13 human genome assembly.
@@ -21,32 +21,56 @@ Paper: https://www.biorxiv.org/content/10.1101/2023.06.12.544594v1
21
 
22
  ## Examples
23
 
24
- ### Load pre-trained model
25
  ```python
26
  from transformers import AutoTokenizer, AutoModel
27
 
28
  tokenizer = AutoTokenizer.from_pretrained('AIRI-Institute/gena-lm-bert-base-lastln-t2t')
29
- model = AutoModel.from_pretrained('AIRI-Institute/gena-lm-bert-base-lastln-t2t')
 
 
 
 
 
 
 
30
  ```
31
 
32
- ### How to load the model to fine-tune it on classification task
33
  ```python
34
- from src.gena_lm.modeling_bert import BertForSequenceClassification
35
  from transformers import AutoTokenizer
36
 
37
  tokenizer = AutoTokenizer.from_pretrained('AIRI-Institute/gena-lm-bert-base-lastln-t2t')
38
  model = BertForSequenceClassification.from_pretrained('AIRI-Institute/gena-lm-bert-base-lastln-t2t')
39
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  ## Model description
42
- GENA-LM (`gena-lm-bert-base-lastln-t2t`) model is trained in a masked language model (MLM) fashion, following the methods proposed in the BigBird paper by masking 15% of tokens. Model config for `gena-lm-bert-base-lastln-t2t` is similar to the bert-base:
43
 
44
  - 512 Maximum sequence length
45
  - 12 Layers, 12 Attention heads
46
  - 768 Hidden size
47
  - 32k Vocabulary size
48
 
49
- We pre-trained `gena-lm-bert-base-lastln-t2t` using the latest T2T human genome assembly (https://www.ncbi.nlm.nih.gov/assembly/GCA_009914755.3/). The data was augmented by sampling mutations from 1000-genome SNPs (gnomAD dataset). Pre-training was performed for 2,100,000 iterations with batch size 256 and sequence length was equal to 512 tokens. We modified Transformer with [Pre-Layer normalization](https://arxiv.org/abs/2002.04745).
50
 
51
  ## Evaluation
52
  For evaluation results, see our paper: https://www.biorxiv.org/content/10.1101/2023.06.12.544594v1
 
4
  - human_genome
5
  ---
6
 
7
+ # GENA-LM (gena-lm-bert-base-lastln-t2t-lastln-t2t)
8
 
9
  GENA-LM is a Family of Open-Source Foundational Models for Long DNA Sequences.
10
 
11
  GENA-LM models are transformer masked language models trained on human DNA sequence.
12
 
13
+ Differences between GENA-LM (`gena-lm-bert-base-lastln-t2t-lastln-t2t`) and DNABERT:
14
  - BPE tokenization instead of k-mers;
15
  - input sequence size is about 4500 nucleotides (512 BPE tokens) compared to 512 nucleotides of DNABERT
16
  - pre-training on T2T vs. GRCh38.p13 human genome assembly.
 
21
 
22
  ## Examples
23
 
24
+ ### How to load pre-trained model for Masked Language Modeling
25
  ```python
26
  from transformers import AutoTokenizer, AutoModel
27
 
28
  tokenizer = AutoTokenizer.from_pretrained('AIRI-Institute/gena-lm-bert-base-lastln-t2t')
29
+ model = AutoModel.from_pretrained('AIRI-Institute/gena-lm-bert-base-lastln-t2t', trust_remote_code=True)
30
+
31
+ ```
32
+
33
+ ### How to load pre-trained model to fine-tune it on classification task
34
+ Get model class from GENA-LM repository:
35
+ ```bash
36
+ git clone https://github.com/AIRI-Institute/GENA_LM.git
37
  ```
38
 
 
39
  ```python
40
+ from GENA_LM.src.gena_lm.modeling_bert import BertForSequenceClassification
41
  from transformers import AutoTokenizer
42
 
43
  tokenizer = AutoTokenizer.from_pretrained('AIRI-Institute/gena-lm-bert-base-lastln-t2t')
44
  model = BertForSequenceClassification.from_pretrained('AIRI-Institute/gena-lm-bert-base-lastln-t2t')
45
  ```
46
+ or you can just download [modeling_bert.py](https://github.com/AIRI-Institute/GENA_LM/tree/main/src/gena_lm) and put it close to your code.
47
+
48
+ OR you can get model class from HuggingFace AutoModel:
49
+ ```python
50
+ from transformers import AutoTokenizer, AutoModel
51
+ model = AutoModel.from_pretrained('AIRI-Institute/gena-lm-bert-base-lastln-t2t', trust_remote_code=True)
52
+ gena_module_name = model.__class__.__module__
53
+ print(gena_module_name)
54
+ import importlib
55
+ # available class names:
56
+ # - BertModel, BertForPreTraining, BertForMaskedLM, BertForNextSentencePrediction,
57
+ # - BertForSequenceClassification, BertForMultipleChoice, BertForTokenClassification,
58
+ # - BertForQuestionAnswering
59
+ # check https://huggingface.co/docs/transformers/model_doc/bert
60
+ cls = getattr(importlib.import_module(gena_module_name), 'BertForSequenceClassification')
61
+ print(cls)
62
+ model = cls.from_pretrained('AIRI-Institute/gena-lm-bert-base-lastln-t2t', num_labels=2)
63
+ ```
64
 
65
  ## Model description
66
+ GENA-LM (`gena-lm-bert-base-lastln-t2t-lastln-t2t`) model is trained in a masked language model (MLM) fashion, following the methods proposed in the BigBird paper by masking 15% of tokens. Model config for `gena-lm-bert-base-lastln-t2t-lastln-t2t` is similar to the bert-base:
67
 
68
  - 512 Maximum sequence length
69
  - 12 Layers, 12 Attention heads
70
  - 768 Hidden size
71
  - 32k Vocabulary size
72
 
73
+ We pre-trained `gena-lm-bert-base-lastln-t2t-lastln-t2t` using the latest T2T human genome assembly (https://www.ncbi.nlm.nih.gov/assembly/GCA_009914755.3/). The data was augmented by sampling mutations from 1000-genome SNPs (gnomAD dataset). Pre-training was performed for 2,100,000 iterations with batch size 256 and sequence length was equal to 512 tokens. We modified Transformer with [Pre-Layer normalization](https://arxiv.org/abs/2002.04745).
74
 
75
  ## Evaluation
76
  For evaluation results, see our paper: https://www.biorxiv.org/content/10.1101/2023.06.12.544594v1