Henry Kenlay commited on
Commit
c479b7e
·
verified ·
1 Parent(s): 99e9899

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +71 -0
README.md ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - antibody language model
4
+ - antibody
5
+ base_model: Rostlab/prot_t5_xl_uniref50
6
+ license: mit
7
+ ---
8
+
9
+ # IgT5 unpaired model
10
+
11
+ Pretrained model on protein and antibody sequences using a masked language modeling (MLM) objective. It was introduced in the paper [Large scale paired antibody language models](https://arxiv.org/abs/2403.17889).
12
+
13
+ The model is finetuned from ProtT5 using single chain antibody sequences from unpaired OAS.
14
+
15
+ # Use
16
+
17
+ The encoder part of the model and tokeniser can be loaded using the `transformers` library
18
+
19
+ ```python
20
+ from transformers import T5EncoderModel, T5Tokenizer
21
+
22
+ tokeniser = T5Tokenizer.from_pretrained("Exscientia/IgT5_unpaired", do_lower_case=False)
23
+ model = T5EncoderModel.from_pretrained("Exscientia/IgT5_unpaired")
24
+ ```
25
+
26
+ The tokeniser is used to prepare batch inputs
27
+ ```python
28
+ # single chain sequences
29
+ sequences = [
30
+ "EVVMTQSPASLSVSPGERATLSCRARASLGISTDLAWYQQRPGQAPRLLIYGASTRATGIPARFSGSGSGTEFTLTISSLQSEDSAVYYCQQYSNWPLTFGGGTKVEIK",
31
+ "ALTQPASVSGSPGQSITISCTGTSSDVGGYNYVSWYQQHPGKAPKLMIYDVSKRPSGVSNRFSGSKSGNTASLTISGLQSEDEADYYCNSLTSISTWVFGGGTKLTVL"
32
+ ]
33
+
34
+ # The tokeniser expects input of the form ["E V V M...", "A L T Q..."]
35
+ sequences = [' '.join(sequence) for sequence in sequences]
36
+
37
+ tokens = tokeniser.batch_encode_plus(
38
+ sequences,
39
+ add_special_tokens=True,
40
+ pad_to_max_length=True,
41
+ return_tensors="pt",
42
+ return_special_tokens_mask=True
43
+ )
44
+ ```
45
+
46
+ Note that the tokeniser adds a `</s>` token at the end of each sequence and pads using the `<pad>` token. For example a batch containing sequences `E V V M`, `A L` will be tokenised to `E V V M </s>` and `A L </s> <pad> <pad>`.
47
+
48
+ Sequence embeddings are generated by feeding tokens through the model
49
+
50
+ ```python
51
+ output = model(
52
+ input_ids=tokens['input_ids'],
53
+ attention_mask=tokens['attention_mask']
54
+ )
55
+
56
+ residue_embeddings = output.last_hidden_state
57
+ ```
58
+
59
+ To obtain a sequence representation, the residue tokens can be averaged over like so
60
+
61
+ ```python
62
+ import torch
63
+
64
+ # mask special tokens before summing over embeddings
65
+ residue_embeddings[tokens["special_tokens_mask"] == 1] = 0
66
+ sequence_embeddings_sum = residue_embeddings.sum(1)
67
+
68
+ # average embedding by dividing sum by sequence lengths
69
+ sequence_lengths = torch.sum(tokens["special_tokens_mask"] == 0, dim=1)
70
+ sequence_embeddings = sequence_embeddings_sum / sequence_lengths.unsqueeze(1)
71
+ ```