monsoon-nlp commited on
Commit
40d542a
1 Parent(s): b55364a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -94
README.md CHANGED
@@ -3,31 +3,40 @@ library_name: sentence-transformers
3
  pipeline_tag: sentence-similarity
4
  tags:
5
  - sentence-transformers
6
- - feature-extraction
7
  - sentence-similarity
8
  - transformers
 
9
 
10
  ---
11
 
12
- # monsoon-nlp/protein-matryoshka-embeddings
13
 
14
- This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 1024 dimensional dense vector space and can be used for tasks like clustering or semantic search.
 
15
 
16
- <!--- Describe your model here -->
17
 
18
- ## Usage (Sentence-Transformers)
19
 
20
- Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
 
 
 
 
 
 
 
 
21
 
22
  ```
23
- pip install -U sentence-transformers
24
  ```
25
 
26
- Then you can use the model like this:
27
 
28
  ```python
29
  from sentence_transformers import SentenceTransformer
30
- sentences = ["This is an example sentence", "Each sentence is converted"]
31
 
32
  model = SentenceTransformer('monsoon-nlp/protein-matryoshka-embeddings')
33
  embeddings = model.encode(sentences)
@@ -35,96 +44,29 @@ print(embeddings)
35
  ```
36
 
37
 
 
38
 
39
- ## Usage (HuggingFace Transformers)
40
- Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
41
-
42
- ```python
43
- from transformers import AutoTokenizer, AutoModel
44
- import torch
45
-
46
-
47
- #Mean Pooling - Take attention mask into account for correct averaging
48
- def mean_pooling(model_output, attention_mask):
49
- token_embeddings = model_output[0] #First element of model_output contains all token embeddings
50
- input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
51
- return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
52
-
53
-
54
- # Sentences we want sentence embeddings for
55
- sentences = ['This is an example sentence', 'Each sentence is converted']
56
-
57
- # Load model from HuggingFace Hub
58
- tokenizer = AutoTokenizer.from_pretrained('monsoon-nlp/protein-matryoshka-embeddings')
59
- model = AutoModel.from_pretrained('monsoon-nlp/protein-matryoshka-embeddings')
60
-
61
- # Tokenize sentences
62
- encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
63
-
64
- # Compute token embeddings
65
- with torch.no_grad():
66
- model_output = model(**encoded_input)
67
-
68
- # Perform pooling. In this case, mean pooling.
69
- sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
70
-
71
- print("Sentence embeddings:")
72
- print(sentence_embeddings)
73
- ```
74
-
75
-
76
-
77
- ## Evaluation Results
78
-
79
- <!--- Describe how your model was evaluated -->
80
-
81
- For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name=monsoon-nlp/protein-matryoshka-embeddings)
82
-
83
-
84
- ## Training
85
- The model was trained with the parameters:
86
-
87
- **DataLoader**:
88
 
89
- `sentence_transformers.datasets.NoDuplicatesDataLoader.NoDuplicatesDataLoader` of length 30000 with parameters:
90
  ```
91
- {'batch_size': 10}
 
 
 
 
 
 
 
 
 
 
 
92
  ```
93
 
94
- **Loss**:
95
 
96
- `sentence_transformers.losses.MatryoshkaLoss.MatryoshkaLoss` with parameters:
97
- ```
98
- {'loss': 'CoSENTLoss', 'matryoshka_dims': [768, 256, 128, 64], 'matryoshka_weights': [1, 1, 1, 1], 'n_dims_per_step': -1}
99
- ```
100
-
101
- Parameters of the fit()-Method:
102
- ```
103
- {
104
- "epochs": 1,
105
- "evaluation_steps": 3000,
106
- "evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
107
- "max_grad_norm": 1,
108
- "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
109
- "optimizer_params": {
110
- "lr": 2e-05
111
- },
112
- "scheduler": "WarmupLinear",
113
- "steps_per_epoch": null,
114
- "warmup_steps": 3000,
115
- "weight_decay": 0.01
116
- }
117
- ```
118
-
119
-
120
- ## Full Model Architecture
121
- ```
122
- SentenceTransformer(
123
- (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
124
- (1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
125
- )
126
- ```
127
 
128
- ## Citing & Authors
129
 
130
- <!--- Describe where people can find more information -->
 
3
  pipeline_tag: sentence-similarity
4
  tags:
5
  - sentence-transformers
 
6
  - sentence-similarity
7
  - transformers
8
+ - biology
9
 
10
  ---
11
 
12
+ # Protein Matryoshka Embeddings
13
 
14
+ The model generates an embedding for input proteins. It was trained using [Matryoshka loss](https://huggingface.co/blog/matryoshka),
15
+ so shortened embeddings can be used for faster search and other tasks.
16
 
17
+ Inputs use [IUPAC-IUB codes](https://en.wikipedia.org/wiki/FASTA_format#Sequence_representation) where letters A-Z map to amino acids. For example:
18
 
19
+ "M A R N W S F R V"
20
 
21
+ The base model was [Rostlab/prot_bert_bfd](https://huggingface.co/Rostlab/prot_bert_bfd).
22
+ A [sentence-transformers](https://github.com/UKPLab/sentence-transformers) model was trained on cosine-similarity of embeddings
23
+ from [UniProt](https://www.uniprot.org/help/downloads#embeddings).
24
+ For train/test/validation datasets of embeddings and distances, see: https://huggingface.co/datasets/monsoon-nlp/protein-pairs-uniprot-swissprot
25
+
26
+
27
+ ## Usage
28
+
29
+ Install these dependencies:
30
 
31
  ```
32
+ pip install -U sentence-transformers datasets
33
  ```
34
 
35
+ Generating embeddings:
36
 
37
  ```python
38
  from sentence_transformers import SentenceTransformer
39
+ sequences = ["M S L E Q K...", "M A R N W S F R V..."]
40
 
41
  model = SentenceTransformer('monsoon-nlp/protein-matryoshka-embeddings')
42
  embeddings = model.encode(sentences)
 
44
  ```
45
 
46
 
47
+ ## Validation Results
48
 
49
+ On 1,000 protein pairs from the validation dataset:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
 
51
  ```
52
+ |steps|cosine_pearson|cosine_spearman|
53
+ |-----|--------------|---------------|
54
+ |3000|0.8598688660086558|0.8666855900999677|
55
+ |6000|0.8692703523988448|0.8615673651584274|
56
+ |9000|0.8779733537629968|0.8754158959780602|
57
+ |12000|0.8877422045031667|0.8881492475969834|
58
+ |15000|0.9027359688395733|0.899106724739699|
59
+ |18000|0.9046675789738002|0.9044183600191271|
60
+ |21000|0.9165801536390973|0.9061381997421003|
61
+ |24000|0.9128046401341833|0.9076748537082228|
62
+ |27000|0.918547416546341|0.9127677526055185|
63
+ |30000|0.9239429677657788|0.9187051589781693|
64
  ```
65
 
66
+ ## Future
67
 
68
+ This model will be updated when I have examples using it on protein classification tasks.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
+ I'm interested in whether [embedding quantization](https://huggingface.co/blog/embedding-quantization) could improve these better.
71
 
72
+ If you want to collaborate on future projects / have resources to train longer on more embeddings, please get in touch.