Update README.md
Browse files
README.md
CHANGED
|
@@ -3,4 +3,42 @@ library_name: transformers
|
|
| 3 |
tags: []
|
| 4 |
---
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
tags: []
|
| 4 |
---
|
| 5 |
|
| 6 |
+
### How to use
|
| 7 |
+
|
| 8 |
+
Until its next release, the transformers library needs to be installed from source with the following command in order to use the models.
|
| 9 |
+
PyTorch should also be installed.
|
| 10 |
+
|
| 11 |
+
```
|
| 12 |
+
pip install --upgrade git+https://github.com/huggingface/transformers.git
|
| 13 |
+
pip install torch
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
A small snippet of code is given here in order to infer with the model from a given input.
|
| 17 |
+
|
| 18 |
+
```
|
| 19 |
+
import numpy as np
|
| 20 |
+
from transformers import AutoModel, AutoTokenizer
|
| 21 |
+
|
| 22 |
+
# Load model and tokenizers
|
| 23 |
+
model = AutoModel.from_pretrained("InstaDeepAI/ChatNT", trust_remote_code=True)
|
| 24 |
+
english_tokenizer = AutoTokenizer.from_pretrained("InstaDeepAI/ChatNT", subfolder="english_tokenizer")
|
| 25 |
+
bio_tokenizer = AutoTokenizer.from_pretrained("InstaDeepAI/ChatNT", subfolder="bio_tokenizer")
|
| 26 |
+
|
| 27 |
+
# Define custom inputs (note that the number of <DNA> token in the english sequence must be equal to len(dna_sequences))
|
| 28 |
+
english_sequence = "A chat between a curious user and an artificial intelligence assistant that can handle bio sequences. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: Is there any evidence of an acceptor splice site in this sequence <DNA> ?"
|
| 29 |
+
dna_sequences = ["ATCGGAAAAAGATCCAGAAAGTTATACCAGGCCAATGGGAATCACCTATTACGTGGATAATAGCGATAGTATGTTACCTATAAATTTAACTACGTGGATATCAGGCAGTTACGTTACCAGTCAAGGAGCACCCAAAACTGTCCAGCAACAAGTTAATTTACCCATGAAGATGTACTGCAAGCCTTGCCAACCAGTTAAAGTAGCTACTCATAAGGTAATAAACAGTAATATCGACTTTTTATCCATTTTGATAATTGATTTATAACAGTCTATAACTGATCGCTCTACATAATCTCTATCAGATTACTATTGACACAAACAGAAACCCCGTTAATTTGTATGATATATTTCCCGGTAAGCTTCGATTTTTAATCCTATCGTGACAATTTGGAATGTAACTTATTTCGTATAGGATAAACTAATTTACACGTTTGAATTCCTAGAATATGGAGAATCTAAAGGTCCTGGCAATGCCATCGGCTTTCAATATTATAATGGACCAAAAGTTACTCTATTAGCTTCCAAAACTTCGCGTGAGTACATTAGAACAGAAGAATAACCTTCAATATCGAGAGAGTTACTATCACTAACTATCCTATG"]
|
| 30 |
+
|
| 31 |
+
# Tokenize
|
| 32 |
+
english_tokenized_sequence_length = 512
|
| 33 |
+
bio_tokenized_sequence_length = 512
|
| 34 |
+
english_tokens = english_tokenizer(english_sequence, return_tensors="pt", padding="max_length", truncation=True, max_length=english_tokenized_sequence_length).input_ids
|
| 35 |
+
bio_tokens = bio_tokenizer(dna_sequences, return_tensors="pt", padding="max_length", max_length=bio_tokenized_sequence_length, truncation=True).input_ids
|
| 36 |
+
bio_tokens = bio_tokens.unsqueeze(0) # to simulate batch_size = 1
|
| 37 |
+
|
| 38 |
+
# Predict
|
| 39 |
+
outs = model(
|
| 40 |
+
multi_omics_tokens_ids=(english_tokens, bio_tokens),
|
| 41 |
+
projection_english_tokens_ids=english_tokens,
|
| 42 |
+
projected_bio_embeddings=None,
|
| 43 |
+
)
|
| 44 |
+
```
|