Mahmoud Amiri commited on
Commit
f9a81fe
·
1 Parent(s): 5ef1185

add model files

Browse files
Files changed (6) hide show
  1. README.md +86 -1
  2. config.yaml +82 -0
  3. label_mapping.json +1 -0
  4. mlp_model.h5 +3 -0
  5. requirements.txt +7 -0
  6. training_history.json +1 -0
README.md CHANGED
@@ -1,3 +1,88 @@
1
  ---
2
- license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: cc-by-4.0
3
+ tags:
4
+ - multilabel-classification
5
+ - scientific-literature
6
+ - tensorflow
7
+ - mlp
8
+ - chemistry
9
+ datasets:
10
+ - Bocklitz-Lab/lit2vec-subfield-classifier-dataset
11
+ language:
12
+ - en
13
+ library_name: tensorflow
14
+ model-index:
15
+ - name: MLP Subfield Classifier (Lit2Vec)
16
+ results: []
17
  ---
18
+
19
+ # 🧪 MLP Multi-Label Classifier for Scientific Subfields
20
+
21
+ A lightweight **multi-layer perceptron (MLP)** model trained to predict **multiple chemistry subfields** from precomputed Lit2Vec embeddings of scientific abstracts.
22
+
23
+ Built using the [Lit2Vec Subfield Classifier Dataset](https://huggingface.co/datasets/Bocklitz-Lab/lit2vec-subfield-classifier-dataset), this model supports **multi-label classification** across 18 chemistry-related subfields.
24
+
25
+ ---
26
+
27
+ ## 📊 Subfields Predicted (18 labels)
28
+
29
+ - Catalysis
30
+ - Organic Chemistry
31
+ - Polymer Chemistry
32
+ - Inorganic Chemistry
33
+ - Materials Science
34
+ - Analytical Chemistry
35
+ - Physical Chemistry
36
+ - Biochemistry
37
+ - Environmental Chemistry
38
+ - Energy Chemistry
39
+ - Medicinal Chemistry
40
+ - Chemical Engineering
41
+ - Supramolecular Chemistry
42
+ - Radiochemistry & Nuclear Chemistry
43
+ - Forensic & Legal Chemistry
44
+ - Food Chemistry
45
+ - Chemical Education
46
+ - Others
47
+
48
+ Each prediction returns **probabilities** per class (using sigmoid), and labels with probabilities > 0.5 are returned as positives.
49
+
50
+ ---
51
+
52
+ ## 🧠 Model Architecture
53
+
54
+ - Input size: `768` (Lit2Vec embedding)
55
+ - Hidden layers: `[256, 256]`
56
+ - Activation: ReLU
57
+ - Dropout: `0.3`
58
+ - Output: 18 sigmoid units (multi-label)
59
+ - Loss: Weighted binary crossentropy
60
+ - Optimizer: Adam
61
+ - Framework: TensorFlow 2 / Keras
62
+
63
+ ---
64
+
65
+ ## 🔧 Usage Example
66
+
67
+ ```python
68
+ from huggingface_hub import hf_hub_download
69
+ import tensorflow as tf
70
+ import numpy as np
71
+ import json
72
+
73
+ # Load model
74
+ model_path = hf_hub_download("your-username/my-mlp-model", "mlp_model.h5")
75
+ model = tf.keras.models.load_model(model_path, compile=False)
76
+
77
+ # Load label mapping
78
+ label_map_path = hf_hub_download("your-username/my-mlp-model", "label_mapping.json")
79
+ with open(label_map_path) as f:
80
+ label_mapping = json.load(f)["index_to_label"]
81
+
82
+ # Predict on new embedding
83
+ embedding = np.random.rand(768).tolist() # or use Lit2Vec
84
+ pred = model.predict(np.array([embedding]))[0]
85
+
86
+ # Get labels with probability > 0.5
87
+ labels = [label_mapping[str(i)] for i, p in enumerate(pred) if p > 0.5]
88
+ print("Predicted labels:", labels)
config.yaml ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ seed: 42
2
+ mixed_precision: false
3
+
4
+ dataset:
5
+ name: Bocklitz-Lab/lit2vec-subfield-classifier-dataset
6
+ train_split: train
7
+ val_split: validation
8
+ test_split: test
9
+ cache_dir: null
10
+ sample_limit: null # e.g., 5000 for quick runs
11
+ shuffle_seed: 42
12
+
13
+ model:
14
+ hidden_layers: [256, 256]
15
+ activation: relu
16
+ dropout: 0.3
17
+ batch_norm: true
18
+ learning_rate: 0.001
19
+ optimizer: adam
20
+
21
+ training:
22
+ batch_size: 32
23
+ epochs: 50
24
+ threshold: 0.5
25
+ val_split_fraction: null # used only if dataset has no explicit validation split
26
+ early_stopping:
27
+ enabled: true
28
+ monitor: val_loss
29
+ patience: 5
30
+ min_delta: 0.0
31
+ reduce_lr:
32
+ enabled: true
33
+ monitor: val_loss
34
+ factor: 0.5
35
+ patience: 3
36
+
37
+ cross_validation:
38
+ enabled: true
39
+ n_folds: 5
40
+ shuffle: true
41
+ seed: 42
42
+
43
+ class_weights:
44
+ enabled: true
45
+
46
+ wandb:
47
+ enabled: true
48
+ project: mlp-multilabel-example
49
+ entity: null # or your team/org
50
+ run_name: final_model
51
+ tags: [mlp, multilabel, lit2vec]
52
+
53
+ io:
54
+ save_dir: saved_data
55
+ model_path: mlp_model.h5
56
+ history_path: training_history.json
57
+ test_x_path: test_embeddings.npy
58
+ test_y_path: test_labels.npy
59
+ label_mapping_path: label_mapping.json
60
+ f1_plot_path: f1_vs_freq.png
61
+
62
+ # Optional: provide human-readable label names; if omitted, names will be "Label 0", ...
63
+ labels:
64
+ label_to_index:
65
+ Catalysis: 0
66
+ Organic Chemistry: 1
67
+ Polymer Chemistry: 2
68
+ Inorganic Chemistry: 3
69
+ Materials Science: 4
70
+ Analytical Chemistry: 5
71
+ Physical Chemistry: 6
72
+ Biochemistry: 7
73
+ Environmental Chemistry: 8
74
+ Energy Chemistry: 9
75
+ Medicinal Chemistry: 10
76
+ Chemical Engineering: 11
77
+ Supramolecular Chemistry: 12
78
+ Radiochemistry & Nuclear Chemistry: 13
79
+ Forensic & Legal Chemistry: 14
80
+ Food Chemistry: 15
81
+ Chemical Education: 16
82
+ Others: 17
label_mapping.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"label_to_index": {"Catalysis": 0, "Organic Chemistry": 1, "Polymer Chemistry": 2, "Inorganic Chemistry": 3, "Materials Science": 4, "Analytical Chemistry": 5, "Physical Chemistry": 6, "Biochemistry": 7, "Environmental Chemistry": 8, "Energy Chemistry": 9, "Medicinal Chemistry": 10, "Chemical Engineering": 11, "Supramolecular Chemistry": 12, "Radiochemistry & Nuclear Chemistry": 13, "Forensic & Legal Chemistry": 14, "Food Chemistry": 15, "Chemical Education": 16, "Others": 17}, "index_to_label": {"0": "Catalysis", "1": "Organic Chemistry", "2": "Polymer Chemistry", "3": "Inorganic Chemistry", "4": "Materials Science", "5": "Analytical Chemistry", "6": "Physical Chemistry", "7": "Biochemistry", "8": "Environmental Chemistry", "9": "Energy Chemistry", "10": "Medicinal Chemistry", "11": "Chemical Engineering", "12": "Supramolecular Chemistry", "13": "Radiochemistry & Nuclear Chemistry", "14": "Forensic & Legal Chemistry", "15": "Food Chemistry", "16": "Chemical Education", "17": "Others"}}
mlp_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d9fa090a94bd995924cff439616bb2996e155372e5ed52214ef28f5d1f0e76d3
3
+ size 4061328
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ numpy==1.26
2
+ scikit-learn==1.2
3
+ tensorflow==2.15,<2.16
4
+ matplotlib==3.7
5
+ wandb==0.16
6
+ datasets==2.19
7
+ pyarrow==12
training_history.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"loss": [8.470060348510742, 1.7850418090820312, 1.5056606531143188, 1.3478214740753174, 1.2950140237808228, 1.1986502408981323, 1.1413774490356445, 1.151053786277771, 1.093340516090393, 1.0624538660049438, 1.0414057970046997, 1.0123454332351685, 1.0043306350708008, 1.0047874450683594, 0.9833027124404907, 0.9159265160560608, 0.8808308243751526], "binary_accuracy": [0.8970237970352173, 0.9494465589523315, 0.9531154036521912, 0.9546661972999573, 0.9551639556884766, 0.9562273621559143, 0.9565128087997437, 0.9568208456039429, 0.9571045637130737, 0.9575257301330566, 0.9576963186264038, 0.9576197266578674, 0.958272397518158, 0.958265483379364, 0.9586291909217834, 0.959234893321991, 0.9597082734107971], "ROC_AUC": [0.8316560387611389, 0.9453409910202026, 0.9560701847076416, 0.9598875045776367, 0.9619840979576111, 0.9646556377410889, 0.9665591716766357, 0.9664934873580933, 0.967963457107544, 0.9682399034500122, 0.9691439867019653, 0.9693467020988464, 0.9692378640174866, 0.9697430729866028, 0.9695724844932556, 0.9717855453491211, 0.9725377559661865], "PR_AUC": [0.2990269064903259, 0.671329140663147, 0.7382231950759888, 0.7759764194488525, 0.785939633846283, 0.8087033033370972, 0.8194859027862549, 0.818324089050293, 0.8289315700531006, 0.835086464881897, 0.8388688564300537, 0.845190703868866, 0.8463453054428101, 0.847578763961792, 0.8502194881439209, 0.8617655634880066, 0.8688318729400635], "val_loss": [1.5648810863494873, 1.3782635927200317, 1.209653377532959, 1.2201181650161743, 1.1328657865524292, 1.1017009019851685, 1.207519292831421, 1.1550023555755615, 1.0857306718826294, 1.1150307655334473, 1.1117751598358154, 1.0641820430755615, 1.0861045122146606, 1.1217414140701294, 1.1736891269683838, 1.0881339311599731, 1.111235499382019], "val_binary_accuracy": [0.9555695056915283, 0.9594541788101196, 0.9599693417549133, 0.9622806906700134, 0.9624477624893188, 0.9605123996734619, 0.9613338708877563, 0.9635616540908813, 0.9630882740020752, 0.9632553458213806, 0.9630464911460876, 0.963840126991272, 0.9638819098472595, 0.963687002658844, 0.9635756015777588, 0.9646338224411011, 0.9646338224411011], "val_ROC_AUC": [0.9607527852058411, 0.9613373279571533, 0.9686673283576965, 0.9714778065681458, 0.9708147048950195, 0.9694383144378662, 0.9686042070388794, 0.972355842590332, 0.9735656380653381, 0.9730936884880066, 0.9701546430587769, 0.9719104766845703, 0.9702484607696533, 0.9693979620933533, 0.9722999930381775, 0.9711511135101318, 0.9721179604530334], "val_PR_AUC": [0.7497867941856384, 0.7998697757720947, 0.8228471279144287, 0.8277607560157776, 0.8360421657562256, 0.8357876539230347, 0.8285924792289734, 0.8429878950119019, 0.8490172624588013, 0.8468226790428162, 0.8406122326850891, 0.853649377822876, 0.8513867259025574, 0.8475092649459839, 0.8441946506500244, 0.8563084602355957, 0.854196310043335], "lr": [0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0010000000474974513, 0.0005000000237487257, 0.0005000000237487257]}