RobBobin commited on
Commit
8608c67
·
verified ·
1 Parent(s): ed89a8e

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,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - sentence-transformers
4
+ - sentence-similarity
5
+ - feature-extraction
6
+ - mathematics
7
+ - scientific-papers
8
+ - retrieval
9
+ - matryoshka
10
+ base_model: allenai/specter2_base
11
+ library_name: sentence-transformers
12
+ pipeline_tag: sentence-similarity
13
+ language: en
14
+ license: apache-2.0
15
+ ---
16
+
17
+ # math-embed
18
+
19
+ A 768-dimensional embedding model fine-tuned for mathematical document retrieval, with a focus on **combinatorics** and related areas (representation theory, symmetric functions, algebraic combinatorics). Built on [SPECTER2](https://huggingface.co/allenai/specter2_base) and trained using knowledge-graph-guided contrastive learning.
20
+
21
+ ## Performance
22
+
23
+ Benchmarked on mathematical paper retrieval (108 queries, 4,794 paper chunks):
24
+
25
+ | Model | MRR | NDCG@10 |
26
+ |-------|-----|---------|
27
+ | **math-embed (this model)** | **0.816** | **0.736** |
28
+ | OpenAI text-embedding-3-small | 0.461 | 0.324 |
29
+ | SPECTER2 (proximity adapter) | 0.360 | 0.225 |
30
+ | SciNCL | 0.306 | 0.205 |
31
+
32
+ ## Usage
33
+
34
+ ```python
35
+ from sentence_transformers import SentenceTransformer
36
+
37
+ model = SentenceTransformer("RobBobin/math-embed")
38
+
39
+ # Embed queries and documents
40
+ queries = ["Kostka polynomials", "representation theory of symmetric groups"]
41
+ docs = ["We study the combinatorial properties of Kostka numbers..."]
42
+
43
+ query_embs = model.encode(queries)
44
+ doc_embs = model.encode(docs)
45
+ ```
46
+
47
+ ### Matryoshka dimensions
48
+
49
+ Trained with Matryoshka Representation Learning — you can truncate embeddings to smaller dimensions (512, 256, 128) with graceful degradation:
50
+
51
+ ```python
52
+ # Use 256-dim embeddings for faster retrieval
53
+ embs = model.encode(texts)
54
+ embs_256 = embs[:, :256]
55
+ ```
56
+
57
+ ## Training
58
+
59
+ ### Method
60
+ - **Loss**: MultipleNegativesRankingLoss + MatryoshkaLoss
61
+ - **Training data**: 22,609 (anchor, positive) pairs generated from a knowledge graph of mathematical concepts
62
+ - **Direct pairs**: concept name/description → chunks from that concept's source papers
63
+ - **Edge pairs**: cross-concept pairs from knowledge graph edges (e.g., "generalizes", "extends")
64
+ - **Base model**: `allenai/specter2_base` (SciBERT pre-trained on 6M citation triplets)
65
+
66
+ ### Configuration
67
+ - Epochs: 3
68
+ - Batch size: 8 (effective 32 with gradient accumulation)
69
+ - Learning rate: 2e-5
70
+ - Max sequence length: 256 tokens
71
+ - Matryoshka dims: [768, 512, 256, 128]
72
+
73
+ ### Model lineage
74
+ ```
75
+ BERT (Google, 110M params)
76
+ └─ SciBERT (Allen AI, retrained on scientific papers)
77
+ └─ SPECTER2 base (Allen AI, + 6M citation triplets)
78
+ └─ math-embed (this model, + KG-derived concept-chunk pairs)
79
+ ```
80
+
81
+ ## Approach
82
+
83
+ The knowledge graph was constructed by an LLM (GPT-4o-mini) from 75 mathematical research papers, identifying 559 concepts and 486 relationships. This graph provides structured ground truth: each concept maps to specific papers, and those papers' chunks serve as positive training examples.
84
+
85
+ This is a form of **knowledge distillation** — a large language model's understanding of mathematical relationships is distilled into a small, fast embedding model suitable for retrieval.
86
+
87
+ ## Limitations
88
+
89
+ - Trained specifically on combinatorics papers (symmetric functions, representation theory, partition identities, algebraic combinatorics)
90
+ - May not generalize well to other areas of mathematics or other scientific domains without additional fine-tuning
91
+ - 256-token context window (standard for BERT-based models)
92
+
93
+ ## Citation
94
+
95
+ See the accompanying paper: *Knowledge-Graph-Guided Fine-Tuning of Embedding Models for Mathematical Document Retrieval*
config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "adapters": {
3
+ "adapters": {},
4
+ "config_map": {},
5
+ "fusion_config_map": {},
6
+ "fusions": {}
7
+ },
8
+ "architectures": [
9
+ "BertModel"
10
+ ],
11
+ "attention_probs_dropout_prob": 0.1,
12
+ "classifier_dropout": null,
13
+ "hidden_act": "gelu",
14
+ "hidden_dropout_prob": 0.1,
15
+ "hidden_size": 768,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 3072,
18
+ "layer_norm_eps": 1e-12,
19
+ "max_position_embeddings": 512,
20
+ "model_type": "bert",
21
+ "num_attention_heads": 12,
22
+ "num_hidden_layers": 12,
23
+ "pad_token_id": 0,
24
+ "position_embedding_type": "absolute",
25
+ "torch_dtype": "float32",
26
+ "transformers_version": "4.51.3",
27
+ "type_vocab_size": 2,
28
+ "use_cache": true,
29
+ "vocab_size": 31090
30
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "SentenceTransformer",
3
+ "__version__": {
4
+ "sentence_transformers": "5.2.3",
5
+ "transformers": "4.51.3",
6
+ "pytorch": "2.9.1"
7
+ },
8
+ "prompts": {
9
+ "query": "",
10
+ "document": ""
11
+ },
12
+ "default_prompt_name": null,
13
+ "similarity_fn_name": "cosine"
14
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f49fba1357a7193677791c2ef52d8b989d5ce0f438dd8b7523b3790da99e6d8
3
+ size 439696224
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
+ ]
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,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "101": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "102": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "103": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "104": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": false,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 1000000000000000019884624838656,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "BertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff