MAE07 commited on
Commit
73b809c
Β·
verified Β·
1 Parent(s): b390414

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +193 -3
README.md CHANGED
@@ -1,3 +1,193 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ tags:
6
+ - text-classification
7
+ - abstract-classification
8
+ - science-mapping
9
+ - green-ai
10
+ - gru
11
+ - attention
12
+ - glove
13
+ library_name: pytorch
14
+ pipeline_tag: text-classification
15
+ datasets:
16
+ - web-of-science
17
+ metrics:
18
+ - f1
19
+ - accuracy
20
+ - precision
21
+ - recall
22
+ ---
23
+
24
+ # Attention-GRU for Cross-Disciplinary Abstract Classification 🌿
25
+
26
+ This study has been accepted for publication in Scientific Reports and is currently in the publication process (in press)
27
+
28
+ A resource-efficient **Attention-based Bidirectional GRU** with frozen **GloVe-300d** embeddings, trained on the **WOS-46985** benchmark to classify scientific abstracts into **134 fine-grained sub-disciplines (Web of Science Level-2)**.
29
+
30
+ The model achieves a **Macro-F1 of 0.920**, outperforming domain-specific Transformer baselines (BERT, BioBERT, SciBERT) while training in **~10 minutes** instead of hours and consuming a fraction of the energy.
31
+
32
+ ---
33
+
34
+ ## 🧠 Model Description
35
+
36
+ | Component | Configuration |
37
+ |-----------|---------------|
38
+ | Architecture | Bidirectional GRU + Soft Attention |
39
+ | Embeddings | Frozen GloVe-300d (Stanford, 6B tokens) |
40
+ | Vocabulary size | 14,541 |
41
+ | GRU hidden dim | 256 |
42
+ | GRU layers | 2 (bidirectional) |
43
+ | Classifier | Linear (dropout 0.5) |
44
+ | Output classes | 134 (WOS-46985 Level-2 sub-disciplines) |
45
+ | Trainable parameters | ~1.06 M |
46
+ | Max sequence length | 250 tokens |
47
+
48
+ The architecture leverages the **semantic stability of scientific terminology**, sidestepping the quadratic cost of full Transformer attention while preserving long-range dependency modeling through soft-attention over GRU hidden states.
49
+
50
+ ---
51
+
52
+ ## πŸ“Š Datasets
53
+
54
+ | Dataset | Abstracts | Classes | Used for |
55
+ |---------|-----------|---------|----------|
56
+ | arXiv | ~ | 3 (AI, Economics, Psychology) | Coarse-grained interdisciplinary baseline |
57
+ | WOS-11967 | 11,967 | 35 | Mid-grained sub-disciplines (L2) |
58
+ | **WOS-46985 (this checkpoint)** | **46,985** | **134** | **Fine-grained sub-disciplines (L2)** |
59
+
60
+ ---
61
+
62
+ ## πŸš€ Performance
63
+
64
+ ### State-of-the-Art Comparison on Web of Science
65
+
66
+ | Model | WOS-11967 (35 classes) F1 | WOS-46985 (134 classes) F1 | Training Time |
67
+ |-------|---------------------------|----------------------------|---------------|
68
+ | BERT-Base | 0.903 | 0.850 | ~ Hours |
69
+ | BioBERT | 0.903 | 0.856 | ~ Hours |
70
+ | SciBERT | 0.921 | 0.867 | ~ Hours |
71
+ | **Attention-GRU (this model)** | **0.953** | **0.920** | **~10 min** |
72
+
73
+ ### Efficiency Metrics (arXiv benchmark)
74
+
75
+ | Model | Val. Accuracy | Parameters (M) | Inference (ms) | Energy (kWh) |
76
+ |-------|---------------|----------------|----------------|--------------|
77
+ | **Attention-GRU** | **96.8%** | **1.06** | **0.36** | **0.15** |
78
+ | BERT (Base) | 94.4% | 109.5 | 7.22 | 0.50 |
79
+ | RoBERTa | 93.4% | 125.0 | 7.80 | 0.52 |
80
+
81
+ The Attention-GRU is **~14Γ— faster to train** and uses **~3Γ— less energy** than Transformer baselines while achieving higher accuracy on fine-grained taxonomies.
82
+
83
+ ---
84
+
85
+ ## πŸ“¦ Files
86
+
87
+ | File | Description |
88
+ |------|-------------|
89
+ | `attention_gru_wos.pth` | PyTorch checkpoint with `encoder_state_dict`, `classifier_state_dict`, and `hyperparameters` |
90
+ | `word2idx.json` | Vocabulary mapping (14,541 tokens) |
91
+ | `labels.json` | Class-id β†’ discipline-name mapping (134 entries; replace placeholders with real names if needed) |
92
+
93
+ ---
94
+
95
+ ## πŸ› οΈ How to Use
96
+
97
+ ```python
98
+ import json, re, torch, torch.nn as nn
99
+ from huggingface_hub import hf_hub_download
100
+
101
+ # --- Model definitions (must match training) ---
102
+ class Attention(nn.Module):
103
+ def __init__(self, hidden_dim):
104
+ super().__init__()
105
+ self.attention = nn.Linear(hidden_dim, 1, bias=False)
106
+ def forward(self, rnn_outputs):
107
+ w = torch.softmax(self.attention(rnn_outputs).squeeze(-1), dim=1)
108
+ return torch.bmm(w.unsqueeze(1), rnn_outputs).squeeze(1)
109
+
110
+ class GRUAttentionEncoder(nn.Module):
111
+ def __init__(self, vocab_size, embed_dim, hidden_dim, num_layers, bidirectional):
112
+ super().__init__()
113
+ self.embedding = nn.Embedding(vocab_size, embed_dim, padding_idx=0)
114
+ self.gru = nn.GRU(embed_dim, hidden_dim, num_layers=num_layers,
115
+ batch_first=True, bidirectional=bidirectional)
116
+ self.attention = Attention(hidden_dim * (2 if bidirectional else 1))
117
+ def forward(self, x):
118
+ out, _ = self.gru(self.embedding(x))
119
+ return self.attention(out)
120
+
121
+ class Classifier(nn.Module):
122
+ def __init__(self, input_dim, num_classes, dropout=0.5):
123
+ super().__init__()
124
+ self.dropout = nn.Dropout(dropout)
125
+ self.fc = nn.Linear(input_dim, num_classes)
126
+ def forward(self, x):
127
+ return self.fc(self.dropout(x))
128
+
129
+ # --- Load files from this repo ---
130
+ REPO = "MAE07/attention-gru-model"
131
+ ckpt = torch.load(hf_hub_download(REPO, "attention_gru_wos.pth"), map_location="cpu")
132
+ vocab = json.load(open(hf_hub_download(REPO, "word2idx.json")))
133
+ labels = {int(k): v for k, v in json.load(open(hf_hub_download(REPO, "labels.json"))).items()}
134
+
135
+ hp = ckpt["hyperparameters"]
136
+ encoder = GRUAttentionEncoder(hp["vocab_size"], hp["embed_dim"], hp["hidden_dim"],
137
+ hp["num_layers"], hp["bidirectional"])
138
+ clf = Classifier(hp["hidden_dim"] * (2 if hp["bidirectional"] else 1),
139
+ hp["num_classes"], hp["fc_dropout"])
140
+ encoder.load_state_dict(ckpt["encoder_state_dict"])
141
+ clf.load_state_dict(ckpt["classifier_state_dict"])
142
+ encoder.eval(); clf.eval()
143
+
144
+ # --- Inference ---
145
+ def predict(text, max_len=250, top_k=5):
146
+ ids = [vocab.get(t, vocab["<UNK>"]) for t in re.findall(r"\b\w+\b", text.lower())]
147
+ ids = (ids + [0] * max_len)[:max_len]
148
+ x = torch.tensor([ids], dtype=torch.long)
149
+ with torch.no_grad():
150
+ probs = torch.softmax(clf(encoder(x)), dim=1)[0]
151
+ conf, idx = torch.topk(probs, k=top_k)
152
+ return [(int(i), labels.get(int(i), f"Class {int(i)}"), float(c))
153
+ for c, i in zip(conf, idx)]
154
+
155
+ abstract = "The exponential growth of scholarly literature necessitates automated systems."
156
+ for cid, name, conf in predict(abstract):
157
+ print(f"{cid:3d} {name:<25s} {conf:.4f}")
158
+ ```
159
+
160
+ A ready-to-use **Gradio demo** is available at:
161
+ πŸ‘‰ https://huggingface.co/spaces/MAE07/abstract-submission
162
+
163
+ ---
164
+
165
+ ## πŸ§ͺ Training Details
166
+
167
+ - **Optimizer:** Adam, lr 8e-4, weight decay 1e-4
168
+ - **Scheduler:** ReduceLROnPlateau (factor 0.5, patience 2) on validation accuracy
169
+ - **Loss:** Class-weighted cross-entropy
170
+ - **Batch size:** 64
171
+ - **Epochs:** 20 (with best-model checkpointing on val accuracy)
172
+ - **Augmentation:** WordNet-synonym replacement (2 substitutions per sample), 2Γ— data expansion
173
+ - **Split:** 70 / 15 / 15 stratified train/val/test
174
+ - **Hardware:** Single GPU (training completed in ~10 minutes)
175
+
176
+ ---
177
+
178
+ ## ⚠️ Limitations
179
+
180
+ - Vocabulary is **frozen at 14,541 GloVe-covered tokens** β€” out-of-vocabulary scientific terms map to `<UNK>` and may degrade performance on highly specialized abstracts (e.g., niche biochemistry, novel CS subfields).
181
+ - Trained on **English abstracts only** β€” non-English text is not supported.
182
+ - The 134 class IDs follow the **WOS-46985 Level-2** ordering used during training; if you need human-readable discipline names you must replace the placeholder values in `labels.json` with the official WOS sub-discipline names.
183
+ - **Domain bias:** Web of Science indexes lean toward STEM and Anglophone publication venues. Abstracts from underrepresented humanities or non-Anglophone disciplines may be misclassified.
184
+ - Soft-attention over GRU outputs is not a direct substitute for self-attention in tasks requiring deep token-token interaction (e.g., NLI, QA).
185
+
186
+ ---
187
+
188
+ ## 🌱 Environmental Impact
189
+
190
+ This model was specifically designed under the **Green AI** paradigm. Compared to Transformer baselines on the same task, it consumes **~3Γ— less energy** during training and **~20Γ— less** during inference, while achieving higher accuracy on fine-grained taxonomies. Training a single full run requires only minutes on commodity hardware and produces a checkpoint of just **~26 MB**.
191
+
192
+ ---
193
+