xushijie commited on
Commit
e7dce43
·
verified ·
1 Parent(s): c1df791

Mirror kuelumbus/polyBERT (original removed from Hub)

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 600,
3
+ "pooling_mode_cls_token": false,
4
+ "pooling_mode_mean_tokens": true,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false
7
+ }
README.md ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: sentence-similarity
3
+ tags:
4
+ - sentence-transformers
5
+ - feature-extraction
6
+ - sentence-similarity
7
+ - transformers
8
+
9
+ widget:
10
+ - source_sentence: "[*]CC[*]"
11
+ sentences:
12
+ - "[*]COC[*]"
13
+ - "[*]CC(C)C[*]"
14
+ ---
15
+
16
+ # kuelumbus/polyBERT
17
+
18
+ This is polyBERT: A chemical language model to enable fully machine-driven ultrafast polymer informatics. polyBERT maps PSMILES strings to 600 dimensional dense fingerprints. The fingerprints numerically represent polymer chemical structures. Please see the license agreement in the LICENSE file.
19
+
20
+ <!--- Describe your model here -->
21
+
22
+ ## Usage (Sentence-Transformers)
23
+
24
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
25
+
26
+ ```
27
+ pip install sentence-transformers
28
+ ```
29
+
30
+ Then you can use the model like this:
31
+
32
+ ```python
33
+ from sentence_transformers import SentenceTransformer
34
+ psmiles_strings = ["[*]CC[*]", "[*]COC[*]"]
35
+
36
+ polyBERT = SentenceTransformer('kuelumbus/polyBERT')
37
+ embeddings = polyBERT.encode(psmiles_strings)
38
+ print(embeddings)
39
+ ```
40
+
41
+
42
+
43
+ ## Usage (HuggingFace Transformers)
44
+ 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.
45
+
46
+ ```python
47
+ from transformers import AutoTokenizer, AutoModel
48
+ import torch
49
+
50
+
51
+ #Mean Pooling - Take attention mask into account for correct averaging
52
+ def mean_pooling(model_output, attention_mask):
53
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
54
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
55
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
56
+
57
+
58
+ # Sentences we want sentence embeddings for
59
+ psmiles_strings = ["[*]CC[*]", "[*]COC[*]"]
60
+
61
+ # Load model from HuggingFace Hub
62
+ tokenizer = AutoTokenizer.from_pretrained('kuelumbus/polyBERT')
63
+ polyBERT = AutoModel.from_pretrained('kuelumbus/polyBERT')
64
+
65
+ # Tokenize sentences
66
+ encoded_input = tokenizer(psmiles_strings, padding=True, truncation=True, return_tensors='pt')
67
+
68
+ # Compute token embeddings
69
+ with torch.no_grad():
70
+ model_output = polyBERT(**encoded_input)
71
+
72
+ # Perform pooling. In this case, mean pooling.
73
+ fingerprints = mean_pooling(model_output, encoded_input['attention_mask'])
74
+
75
+ print("Fingerprints:")
76
+ print(fingerprints)
77
+ ```
78
+
79
+
80
+
81
+ ## Evaluation Results
82
+
83
+ See https://github.com/Ramprasad-Group/polyBERT and paper on arXiv.
84
+
85
+ ## Full Model Architecture
86
+ ```
87
+ SentenceTransformer(
88
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: DebertaV2Model
89
+ (1): Pooling({'word_embedding_dimension': 600, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
90
+ )
91
+ ```
92
+
93
+ ## Citing & Authors
94
+
95
+ Kuenneth, C., Ramprasad, R. polyBERT: a chemical language model to enable fully machine-driven ultrafast polymer informatics. Nat Commun 14, 4099 (2023). https://doi.org/10.1038/s41467-023-39868-6
added_tokens.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "[CLS]": 265,
3
+ "[MASK]": 268,
4
+ "[PAD]": 267,
5
+ "[SEP]": 266,
6
+ "[UNK]": 269
7
+ }
config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "polyBERT_sentence_transformers/",
3
+ "architectures": [
4
+ "DebertaV2Model"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 600,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 512,
12
+ "layer_norm_eps": 1e-07,
13
+ "max_position_embeddings": 512,
14
+ "max_relative_positions": -1,
15
+ "model_type": "deberta-v2",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 12,
18
+ "pad_token_id": 3,
19
+ "pooler_dropout": 0,
20
+ "pooler_hidden_act": "gelu",
21
+ "pooler_hidden_size": 600,
22
+ "pos_att_type": null,
23
+ "position_biased_input": true,
24
+ "relative_attention": false,
25
+ "torch_dtype": "float32",
26
+ "transformers_version": "4.22.0",
27
+ "type_vocab_size": 0,
28
+ "vocab_size": 269
29
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.2.0",
4
+ "transformers": "4.18.0",
5
+ "pytorch": "1.10.2+cu102"
6
+ }
7
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:21cfab4a3b0599852fb8ef529a67e41632246b9256ed834938ba9b46cb24148f
3
+ size 100800352
modules.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Pooling",
12
+ "type": "sentence_transformers.models.Pooling"
13
+ }
14
+ ]
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:469d1928fe140f3d8d93f69e69a11aebf540e7a2043b38a9a6758cf0bb640a9c
3
+ size 100839543
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 512,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "[CLS]",
3
+ "cls_token": "[CLS]",
4
+ "eos_token": "[SEP]",
5
+ "mask_token": "[MASK]",
6
+ "pad_token": "[PAD]",
7
+ "sep_token": "[SEP]",
8
+ "unk_token": "[UNK]"
9
+ }
spm.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2285839ce5a54c35acd7a59c38e531c243a5c46476e1ba11080bf11d303618d5
3
+ size 242316
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "[CLS]",
3
+ "cls_token": "[CLS]",
4
+ "do_lower_case": false,
5
+ "eos_token": "[SEP]",
6
+ "mask_token": "[MASK]",
7
+ "name_or_path": "polyBERT_sentence_transformers/",
8
+ "pad_token": "[PAD]",
9
+ "sep_token": "[SEP]",
10
+ "sp_model_kwargs": {},
11
+ "special_tokens_map_file": null,
12
+ "split_by_punct": false,
13
+ "tokenizer_class": "DebertaV2Tokenizer",
14
+ "unk_token": "[UNK]"
15
+ }