File size: 3,711 Bytes
fece0b4
 
2b56a9b
 
 
fece0b4
 
 
 
300511b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fece0b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
library_name: transformers.js
pipeline_tag: zero-shot-classification
tags:
 - text-classification
---

https://huggingface.co/AmelieSchreiber/esm2_t6_8M_UR50D_sequence_classifier_v1 with ONNX weights to be compatible with Transformers.js.



## Usage (Transformers.js)

If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@xenova/transformers) using:
```bash
npm i @xenova/transformers
```

**Example:** Protein sequence classification w/ `Xenova/esm2_t6_8M_UR50D_sequence_classifier_v1`.
```js
import { pipeline } from '@xenova/transformers';

// Create text classification pipeline
const classifier = await pipeline('text-classification', 'Xenova/esm2_t6_8M_UR50D_sequence_classifier_v1');

// Suppose these are your new sequences that you want to classify
// Additional Family 0: Enzymes
const new_sequences_0 = [
    'ACGYLKTPKLADPPVLRGDSSVTKAICKPDPVLEK',
    'GVALDECKALDYLPGKPLPMDGKVCQCGSKTPLRP',
    'VLPGYTCGELDCKPGKPLPKCGADKTQVATPFLRG',
    'TCGALVQYPSCADPPVLRGSDSSVKACKKLDPQDK',
    'GALCEECKLCPGADYKPMDGDRLPAAATSKTRPVG',
    'PAVDCKKALVYLPKPLPMDGKVCRGSKTPKTRPYG',
    'VLGYTCGALDCKPGKPLPKCGADKTQVATPFLRGA',
    'CGALVQYPSCADPPVLRGSDSSVKACKKLDPQDKT',
    'ALCEECKLCPGADYKPMDGDRLPAAATSKTRPVGK',
    'AVDCKKALVYLPKPLPMDGKVCRGSKTPKTRPYGR',
]

// Additional Family 1: Receptor Proteins
const new_sequences_1 = [
    'VGQRFYGGRQKNRHCELSPLPSACRGSVQGALYTD',
    'KDQVLTVPTYACRCCPKMDSKGRVPSTLRVKSARS',
    'PLAGVACGRGLDYRCPRKMVPGDLQVTPATQRPYG',
    'CGVRLGYPGCADVPLRGRSSFAPRACMKKDPRVTR',
    'RKGVAYLYECRKLRCRADYKPRGMDGRRLPKASTT',
    'RPTGAVNCKQAKVYRGLPLPMMGKVPRVCRSRRPY',
    'RLDGGYTCGQALDCKPGRKPPKMGCADLKSTVATP',
    'LGTCRKLVRYPQCADPPVMGRSSFRPKACCRQDPV',
    'RVGYAMCSPKLCSCRADYKPPMGDGDRLPKAATSK',
    'QPKAVNCRKAMVYRPKPLPMDKGVPVCRSKRPRPY',
]

// Additional Family 2: Structural Proteins
const new_sequences_2 = [
    'VGKGFRYGSSQKRYLHCQKSALPPSCRRGKGQGSAT',
    'KDPTVMTVGTYSCQCPKQDSRGSVQPTSRVKTSRSK',
    'PLVGKACGRSSDYKCPGQMVSGGSKQTPASQRPSYD',
    'CGKKLVGYPSSKADVPLQGRSSFSPKACKKDPQMTS',
    'RKGVASLYCSSKLSCKAQYSKGMSDGRSPKASSTTS',
    'RPKSAASCEQAKSYRSLSLPSMKGKVPSKCSRSKRP',
    'RSDVSYTSCSQSKDCKPSKPPKMSGSKDSSTVATPS',
    'LSTCSKKVAYPSSKADPPSSGRSSFSMKACKKQDPPV',
    'RVGSASSEPKSSCSVQSYSKPSMSGDSSPKASSTSK',
    'QPSASNCEKMSSYRPSLPSMSKGVPSSRSKSSPPYQ',
]

// Merge all sequences
const new_sequences = [...new_sequences_0, ...new_sequences_1, ...new_sequences_2];

// Get the predicted class for each sequence
const predictions = await classifier(new_sequences);

// Output the predicted class for each sequence
for (let i = 0; i < predictions.length; ++i) {
    console.log(`Sequence: ${new_sequences[i]}, Predicted class: '${predictions[i].label}'`)
}
// Sequence: ACGYLKTPKLADPPVLRGDSSVTKAICKPDPVLEK, Predicted class: 'Enzymes'
// ... (truncated)
// Sequence: AVDCKKALVYLPKPLPMDGKVCRGSKTPKTRPYGR, Predicted class: 'Enzymes'
// Sequence: VGQRFYGGRQKNRHCELSPLPSACRGSVQGALYTD, Predicted class: 'Receptor Proteins'
// ... (truncated)
// Sequence: QPKAVNCRKAMVYRPKPLPMDKGVPVCRSKRPRPY, Predicted class: 'Receptor Proteins'
// Sequence: VGKGFRYGSSQKRYLHCQKSALPPSCRRGKGQGSAT, Predicted class: 'Structural Proteins'
// ... (truncated)
// Sequence: QPSASNCEKMSSYRPSLPSMSKGVPSSRSKSSPPYQ, Predicted class: 'Structural Proteins'
```


Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).