Upload README.md
Browse files
README.md
CHANGED
@@ -4,197 +4,109 @@ license: mit
|
|
4 |
pipeline_tag: sentence-similarity
|
5 |
---
|
6 |
|
7 |
-
#
|
8 |
|
9 |
-
|
10 |
|
|
|
11 |
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
### Model Description
|
16 |
-
|
17 |
-
<!-- Provide a longer summary of what this model is. -->
|
18 |
-
|
19 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
20 |
-
|
21 |
-
- **Developed by:** [More Information Needed]
|
22 |
-
- **Funded by [optional]:** [More Information Needed]
|
23 |
-
- **Shared by [optional]:** [More Information Needed]
|
24 |
-
- **Model type:** [More Information Needed]
|
25 |
-
- **Language(s) (NLP):** [More Information Needed]
|
26 |
-
- **License:** [More Information Needed]
|
27 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
28 |
-
|
29 |
-
### Model Sources [optional]
|
30 |
-
|
31 |
-
<!-- Provide the basic links for the model. -->
|
32 |
-
|
33 |
-
- **Repository:** [More Information Needed]
|
34 |
-
- **Paper [optional]:** [More Information Needed]
|
35 |
-
- **Demo [optional]:** [More Information Needed]
|
36 |
-
|
37 |
-
## Uses
|
38 |
-
|
39 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
40 |
-
|
41 |
-
### Direct Use
|
42 |
-
|
43 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
44 |
-
|
45 |
-
[More Information Needed]
|
46 |
-
|
47 |
-
### Downstream Use [optional]
|
48 |
-
|
49 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
50 |
-
|
51 |
-
[More Information Needed]
|
52 |
-
|
53 |
-
### Out-of-Scope Use
|
54 |
-
|
55 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
56 |
-
|
57 |
-
[More Information Needed]
|
58 |
-
|
59 |
-
## Bias, Risks, and Limitations
|
60 |
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
### Recommendations
|
66 |
-
|
67 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
68 |
-
|
69 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
70 |
-
|
71 |
-
## How to Get Started with the Model
|
72 |
-
|
73 |
-
Use the code below to get started with the model.
|
74 |
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
## Training Details
|
78 |
|
79 |
-
###
|
80 |
-
|
81 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
82 |
-
|
83 |
-
[More Information Needed]
|
84 |
|
85 |
### Training Procedure
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
[More Information Needed]
|
92 |
-
|
93 |
-
|
94 |
-
#### Training Hyperparameters
|
95 |
-
|
96 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
97 |
-
|
98 |
-
#### Speeds, Sizes, Times [optional]
|
99 |
-
|
100 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
101 |
-
|
102 |
-
[More Information Needed]
|
103 |
|
104 |
## Evaluation
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
#### Testing Data
|
111 |
-
|
112 |
-
<!-- This should link to a Dataset Card if possible. -->
|
113 |
-
|
114 |
-
[More Information Needed]
|
115 |
-
|
116 |
-
#### Factors
|
117 |
-
|
118 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
119 |
-
|
120 |
-
[More Information Needed]
|
121 |
-
|
122 |
-
#### Metrics
|
123 |
-
|
124 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
125 |
-
|
126 |
-
[More Information Needed]
|
127 |
-
|
128 |
-
### Results
|
129 |
-
|
130 |
-
[More Information Needed]
|
131 |
-
|
132 |
-
#### Summary
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
## Model Examination [optional]
|
137 |
-
|
138 |
-
<!-- Relevant interpretability work for the model goes here -->
|
139 |
-
|
140 |
-
[More Information Needed]
|
141 |
-
|
142 |
-
## Environmental Impact
|
143 |
-
|
144 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
145 |
-
|
146 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
147 |
-
|
148 |
-
- **Hardware Type:** [More Information Needed]
|
149 |
-
- **Hours used:** [More Information Needed]
|
150 |
-
- **Cloud Provider:** [More Information Needed]
|
151 |
-
- **Compute Region:** [More Information Needed]
|
152 |
-
- **Carbon Emitted:** [More Information Needed]
|
153 |
-
|
154 |
-
## Technical Specifications [optional]
|
155 |
-
|
156 |
-
### Model Architecture and Objective
|
157 |
-
|
158 |
-
[More Information Needed]
|
159 |
-
|
160 |
-
### Compute Infrastructure
|
161 |
-
|
162 |
-
[More Information Needed]
|
163 |
-
|
164 |
-
#### Hardware
|
165 |
-
|
166 |
-
[More Information Needed]
|
167 |
-
|
168 |
-
#### Software
|
169 |
-
|
170 |
-
[More Information Needed]
|
171 |
-
|
172 |
-
## Citation [optional]
|
173 |
-
|
174 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
175 |
-
|
176 |
-
**BibTeX:**
|
177 |
-
|
178 |
-
[More Information Needed]
|
179 |
-
|
180 |
-
**APA:**
|
181 |
-
|
182 |
-
[More Information Needed]
|
183 |
-
|
184 |
-
## Glossary [optional]
|
185 |
-
|
186 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
187 |
-
|
188 |
-
[More Information Needed]
|
189 |
-
|
190 |
-
## More Information [optional]
|
191 |
-
|
192 |
-
[More Information Needed]
|
193 |
|
194 |
-
##
|
195 |
|
196 |
-
|
197 |
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
-
[
|
|
|
4 |
pipeline_tag: sentence-similarity
|
5 |
---
|
6 |
|
7 |
+
# DNA2Vec: Transformer-Based DNA Sequence Embedding
|
8 |
|
9 |
+
This repository provides an implementation of `dna2vec`, a transformer-based model designed for DNA sequence embeddings. It includes both the Hugging Face (`hf_model`) and a locally trained model (`local_model`). The model can be used for DNA sequence alignment, classification, and other genomic applications.
|
10 |
|
11 |
+
## Model Overview
|
12 |
|
13 |
+
DNA sequence alignment is an essential genomic task that involves mapping short DNA reads to the most probable locations within a reference genome. Traditional methods rely on genome indexing and efficient search algorithms, while recent advances leverage transformer-based models to encode DNA sequences into vector representations.
|
14 |
|
15 |
+
The `dna2vec` framework introduces a **Reference-Free DNA Embedding (RDE) Transformer model**, which encodes DNA sequences into a shared vector space, allowing for efficient similarity search and sequence alignment.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
### Key Features:
|
18 |
+
- **Transformer-based architecture** trained on genomic data.
|
19 |
+
- **Reference-free embeddings** that enable efficient sequence retrieval.
|
20 |
+
- **Contrastive loss for self-supervised training**, ensuring robust sequence similarity learning.
|
21 |
+
- **Support for Hugging Face and custom-trained local models**.
|
22 |
+
- **Efficient search through a DNA vector store**, reducing genome-wide alignment to a local search.
|
23 |
|
24 |
+
## Model Details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
### Model Architecture
|
27 |
+
The transformer model consists of:
|
28 |
+
- **12 attention heads**
|
29 |
+
- **6 encoder layers**
|
30 |
+
- **Embedding dimension:** 1020
|
31 |
+
- **Vocabulary size:** 10,000
|
32 |
+
- **Cosine similarity-based sequence matching**
|
33 |
+
- **Dropout:** 0.1
|
34 |
+
- **Training: Cosine Annealing learning rate scheduling**
|
35 |
+
|
36 |
+
## Installation
|
37 |
+
|
38 |
+
To use the model, install the required dependencies:
|
39 |
+
|
40 |
+
```bash
|
41 |
+
pip install transformers torch
|
42 |
+
```
|
43 |
+
|
44 |
+
## Usage
|
45 |
+
|
46 |
+
### Load Hugging Face Model
|
47 |
+
|
48 |
+
```python
|
49 |
+
from transformers import AutoModel, AutoTokenizer
|
50 |
+
import torch
|
51 |
+
import torch.nn as nn
|
52 |
+
|
53 |
+
def load_hf_model():
|
54 |
+
hf_model = AutoModel.from_pretrained("roychowdhuryresearch/dna2vec", trust_remote_code=True)
|
55 |
+
hf_tokenizer = AutoTokenizer.from_pretrained("roychowdhuryresearch/dna2vec", trust_remote_code=True)
|
56 |
+
|
57 |
+
class AveragePooler(nn.Module):
|
58 |
+
def forward(self, last_hidden, attention_mask):
|
59 |
+
return (last_hidden * attention_mask.unsqueeze(-1)).sum(1) / attention_mask.sum(-1).unsqueeze(-1)
|
60 |
+
|
61 |
+
hf_model.pooler = AveragePooler()
|
62 |
+
return hf_model, hf_tokenizer, hf_model.pooler
|
63 |
+
```
|
64 |
+
###Using the Model
|
65 |
+
Once the model is loaded, you can use it to obtain embeddings for DNA sequences:
|
66 |
+
|
67 |
+
```python
|
68 |
+
def get_embedding(dna_sequence):
|
69 |
+
model, tokenizer, pooler = load_hf_model()
|
70 |
+
tokenized_input = tokenizer(dna_sequence, return_tensors="pt")
|
71 |
+
with torch.no_grad():
|
72 |
+
output = model(**tokenized_input)
|
73 |
+
embedding = pooler(output.last_hidden_state, tokenized_input.attention_mask)
|
74 |
+
return embedding.numpy()
|
75 |
+
|
76 |
+
# Example usage
|
77 |
+
dna_seq = "ATGCGTACGTAGCTAGCTAGC"
|
78 |
+
embedding = get_embedding(dna_seq)
|
79 |
+
print("Embedding shape:", embedding.shape)
|
80 |
+
```
|
81 |
|
82 |
## Training Details
|
83 |
|
84 |
+
### Dataset
|
85 |
+
The training data consists of DNA sequences sampled from various chromosomes across species. The dataset covers **approximately 2% of the human genome**, ensuring generalization across different sequences. Reads are generated using **ART MiSeq** simulation, with variations in insertion and deletion rates.
|
|
|
|
|
|
|
86 |
|
87 |
### Training Procedure
|
88 |
+
- **Self-Supervised Learning:** Contrastive loss-based training.
|
89 |
+
- **Dynamic Length Sequences:** DNA fragments of length 800-2000 with reads sampled in [150, 500].
|
90 |
+
- **Noise Augmentation:** 1-5% random base substitutions in 40% of training reads.
|
91 |
+
- **Batch Size:** 16 with gradient accumulation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
## Evaluation
|
94 |
|
95 |
+
The model was evaluated against traditional aligners (Bowtie-2) and other Transformer-based baselines (DNABERT-2, HyenaDNA). The evaluation metrics include:
|
96 |
+
- **Alignment Recall:** >99% for high-quality reads.
|
97 |
+
- **Cross-Species Transfer:** Successfully aligns sequences from different species, including *Thermus Aquaticus* and *Rattus Norvegicus*.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
## Citation
|
100 |
|
101 |
+
If you use this model, please cite:
|
102 |
|
103 |
+
```bibtex
|
104 |
+
@article{holur2023dna2vec,
|
105 |
+
title={Embed-Search-Align: DNA Sequence Alignment using Transformer models},
|
106 |
+
author={Holur, Pavan and others},
|
107 |
+
journal={Bioinformatics},
|
108 |
+
year={2023}
|
109 |
+
}
|
110 |
+
```
|
111 |
|
112 |
+
For more details, check the [full paper](https://arxiv.org/abs/2309.11087v6).
|