Hui97 commited on
Commit
f90701e
·
verified ·
1 Parent(s): 817fd61

Upload folder using huggingface_hub

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 768,
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
+ "pooling_mode_weightedmean_tokens": false,
8
+ "pooling_mode_lasttoken": false,
9
+ "include_prompt": true
10
+ }
README.md ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - ontology-embedding
4
+ - hyperbolic-space
5
+ - hierarchical-reasoning
6
+ - biomedical-ontology
7
+ - generated_from_trainer
8
+ - dataset_size:150000
9
+ - loss:HierarchyTransformerLoss
10
+ base_model: sentence-transformers/all-mpnet-base-v2
11
+ widget:
12
+ - source_sentence: cellular response to stimulus
13
+ sentences:
14
+ - response to stimulus
15
+ - medial transverse frontopolar gyrus
16
+ - biological regulation
17
+ - source_sentence: regulation of cell differentiation involved in embryonic placenta
18
+ development
19
+ sentences:
20
+ - thoracic wall
21
+ - ectoderm-derived structure
22
+ - regulation of cell differentiation
23
+ - source_sentence: regulation of hippocampal neuron apoptotic process
24
+ sentences:
25
+ - external genitalia morphogenesis
26
+ - compact layer of ventricle
27
+ - biological regulation
28
+ - source_sentence: transitional myocyte of internodal tract
29
+ sentences:
30
+ - secretory epithelial cell
31
+ - internodal tract myocyte
32
+ - insect haltere disc
33
+ - source_sentence: alveolar atrium
34
+ sentences:
35
+ - organ part
36
+ - superior recess of lesser sac
37
+ - foramen of skull
38
+ pipeline_tag: sentence-similarity
39
+ library_name: sentence-transformers
40
+ ---
41
+
42
+ # OnT: Language Models as Ontology Encoders
43
+
44
+ This is an OnT (Ontology Transformer) model trained on the GO dataset, based on [sentence-transformers/all-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-mpnet-base-v2). OnT is a language model-based framework for ontology embeddings, enabling effective representation of concepts as points in hyperbolic space and axioms as hierarchical relationships between concepts.
45
+
46
+ ## Model Details
47
+
48
+ ### Model Description
49
+ - **Model Type:** Ontology Transformer (OnT)
50
+ - **Base model:** [sentence-transformers/all-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-mpnet-base-v2)
51
+ - **Training Dataset:** GO
52
+ - **Maximum Sequence Length:** 384 tokens
53
+ - **Output Dimensionality:** 768 dimensions
54
+ - **Embedding Space:** Hyperbolic Space
55
+ - **Key Features:**
56
+ - Hyperbolic embeddings for ontology concept encoding
57
+ - Modeling of hierarchical relationships between concepts
58
+ - Support for role embeddings as rotations over hyperbolic spaces
59
+ - Concept rotation, transition, and existential quantifier representation
60
+
61
+ ### Model Sources
62
+
63
+ - **Repository:** [OnT on GitHub](https://github.com/HuiYang1997/OnT)
64
+ - **Paper:** [Language Models as Ontology Encoders](https://arxiv.org/abs/2507.14334)
65
+
66
+ ### Available Versions
67
+
68
+ This model is available in **4 versions** (Git branches) to suit different use cases:
69
+
70
+ | Branch | Training Type | Role Embedding | Use Case |
71
+ |--------|------------|----------------|----------|
72
+ | **`main`** (default) | Prediction Dataset | ✅ With role embedding | Default version: training on prediction dataset, support role embedding |
73
+ | **`role-free`** | Prediction Dataset | ❌ Without role embedding | Training on prediction dataset, without role embedding |
74
+ | **`inference-default`** | Inference Dataset | ✅ With role embedding | Training on inference dataset, with role support |
75
+ | **`inference-role-free`** | Inference Dataset | ❌ Without role embedding | Training on inference dataset, without role embeddings |
76
+
77
+ **How to use different versions:**
78
+
79
+ ```python
80
+ from OnT import OntologyTransformer
81
+
82
+ # Default version (main branch - OnTr with role embedding)
83
+ ont = OntologyTransformer.from_pretrained("Hui97/OnT-MPNet-go")
84
+
85
+ # Role-free version (without role embedding)
86
+ ont = OntologyTransformer.from_pretrained("Hui97/OnT-MPNet-go", revision="role-free")
87
+
88
+ # Inference version with role embedding
89
+ ont = OntologyTransformer.from_pretrained("Hui97/OnT-MPNet-go", revision="inference-default")
90
+
91
+ # Inference version without role embedding
92
+ ont = OntologyTransformer.from_pretrained("Hui97/OnT-MPNet-go", revision="inference-role-free")
93
+ ```
94
+
95
+ ### Full Model Architecture
96
+
97
+ ```
98
+ OntologyTransformer(
99
+ (0): Transformer({'max_seq_length': 384, 'do_lower_case': False}) with Transformer model: BertModel
100
+ (1): Pooling({'word_embedding_dimension': 768, '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})
101
+ )
102
+ ```
103
+
104
+ ## Usage
105
+
106
+ ### Installation
107
+
108
+ First, install the required dependencies:
109
+
110
+ ```bash
111
+ pip install sentence-transformers==3.4.0.dev0
112
+ ```
113
+
114
+ You also need to install [HierarchyTransformers](https://github.com/KRR-Oxford/HierarchyTransformers) following the instructions in their repository.
115
+
116
+ ### Direct Usage
117
+
118
+ Load the model and use it for ontology concept encoding:
119
+
120
+ ```python
121
+ import torch
122
+ from OnT import OntologyTransformer
123
+
124
+ # Load the OnT model
125
+ path = "Hui97/OnT-MPNet-go"
126
+ ont = OntologyTransformer.from_pretrained(path)
127
+
128
+ # Entity names to be encoded
129
+ entity_names = [
130
+ 'alveolar atrium',
131
+ 'organ part',
132
+ 'superior recess of lesser sac',
133
+ ]
134
+
135
+ # Get the entity embeddings in hyperbolic space
136
+ entity_embeddings = ont.encode_concept(entity_names)
137
+ print(entity_embeddings.shape)
138
+ # [3, 768]
139
+
140
+ # Role sentences to be encoded
141
+ role_sentences = [
142
+ "application attribute",
143
+ "attribute",
144
+ "chemical modifier"
145
+ ]
146
+
147
+ # Get the role embeddings (rotations and scalings)
148
+ role_rotations, role_scalings = ont.encode_roles(role_sentences)
149
+ ```
150
+
151
+ <!--
152
+ ### Direct Usage (Transformers)
153
+
154
+ <details><summary>Click to see the direct usage in Transformers</summary>
155
+
156
+ </details>
157
+ -->
158
+
159
+
160
+
161
+ ## Citation
162
+
163
+ ### BibTeX
164
+
165
+ If you use this model, please cite:
166
+
167
+ ```bibtex
168
+ @article{yang2025language,
169
+ title={Language Models as Ontology Encoders},
170
+ author={Yang, Hui and Chen, Jiaoyan and He, Yuan and Gao, Yongsheng and Horrocks, Ian},
171
+ journal={arXiv preprint arXiv:2507.14334},
172
+ year={2025}
173
+ }
174
+ ```
config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "sentence-transformers/all-mpnet-base-v2",
3
+ "architectures": [
4
+ "MPNetModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "eos_token_id": 2,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-05,
15
+ "max_position_embeddings": 514,
16
+ "model_type": "mpnet",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 1,
20
+ "relative_attention_num_buckets": 32,
21
+ "torch_dtype": "float32",
22
+ "transformers_version": "4.45.2",
23
+ "vocab_size": 30527
24
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "3.4.0.dev0",
4
+ "transformers": "4.45.2",
5
+ "pytorch": "2.5.1+cu124"
6
+ },
7
+ "prompts": {},
8
+ "default_prompt_name": null,
9
+ "similarity_fn_name": "cosine"
10
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37d583ab2805955adc75eaba6ac6cac412ba0ae9b1bf491acde94b64643d7d27
3
+ size 437967672
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
+ ]
role_model.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d986604b5ff3ba99ac133811cf84d2f3e6d033eb13d2205aaefdf640e00c84e2
3
+ size 1185770
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 256,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "<s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "</s>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "<mask>",
25
+ "lstrip": true,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "</s>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "[UNK]",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": true,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "104": {
36
+ "content": "[UNK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "30526": {
44
+ "content": "<mask>",
45
+ "lstrip": true,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ }
51
+ },
52
+ "bos_token": "<s>",
53
+ "clean_up_tokenization_spaces": false,
54
+ "cls_token": "<s>",
55
+ "do_lower_case": true,
56
+ "eos_token": "</s>",
57
+ "mask_token": "<mask>",
58
+ "max_length": 128,
59
+ "model_max_length": 256,
60
+ "pad_to_multiple_of": null,
61
+ "pad_token": "<pad>",
62
+ "pad_token_type_id": 0,
63
+ "padding_side": "right",
64
+ "sep_token": "</s>",
65
+ "stride": 0,
66
+ "strip_accents": null,
67
+ "tokenize_chinese_chars": true,
68
+ "tokenizer_class": "MPNetTokenizer",
69
+ "truncation_side": "right",
70
+ "truncation_strategy": "longest_first",
71
+ "unk_token": "[UNK]"
72
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
wrapper_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"role_emd_mode": "sentenceEmbedding", "role_model_mode": "rotation"}