gptmed 0.0.1__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {gptmed-0.0.1/gptmed.egg-info → gptmed-0.3.0}/PKG-INFO +155 -43
- {gptmed-0.0.1 → gptmed-0.3.0}/README.md +152 -19
- gptmed-0.3.0/gptmed/__init__.py +60 -0
- gptmed-0.3.0/gptmed/api.py +352 -0
- gptmed-0.3.0/gptmed/configs/config_loader.py +191 -0
- gptmed-0.3.0/gptmed/configs/training_config.yaml +64 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/inference/generator.py +5 -5
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/model/__init__.py +1 -1
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/model/configs/__init__.py +1 -1
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/tokenizer/__init__.py +1 -1
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/training/train.py +7 -8
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/training/trainer.py +4 -4
- {gptmed-0.0.1 → gptmed-0.3.0/gptmed.egg-info}/PKG-INFO +155 -43
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed.egg-info/SOURCES.txt +3 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed.egg-info/requires.txt +1 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/pyproject.toml +3 -3
- gptmed-0.0.1/gptmed/__init__.py +0 -37
- {gptmed-0.0.1 → gptmed-0.3.0}/LICENSE +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/MANIFEST.in +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/configs/__init__.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/configs/train_config.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/data/__init__.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/data/parsers/__init__.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/data/parsers/medquad_parser.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/data/parsers/text_formatter.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/inference/__init__.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/inference/decoding_utils.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/inference/generation_config.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/inference/sampling.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/model/architecture/__init__.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/model/architecture/attention.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/model/architecture/decoder_block.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/model/architecture/embeddings.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/model/architecture/feedforward.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/model/architecture/transformer.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/model/configs/model_config.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/tokenizer/tokenize_data.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/tokenizer/train_tokenizer.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/training/__init__.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/training/dataset.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/training/utils.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/utils/__init__.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/utils/checkpoints.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed/utils/logging.py +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed.egg-info/dependency_links.txt +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed.egg-info/entry_points.txt +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/gptmed.egg-info/top_level.txt +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/requirements.txt +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/setup.cfg +0 -0
- {gptmed-0.0.1 → gptmed-0.3.0}/setup.py +0 -0
|
@@ -1,31 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gptmed
|
|
3
|
-
Version: 0.0
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: A lightweight GPT-based language model framework for training custom question-answering models on any domain
|
|
5
5
|
Author-email: Sanjog Sigdel <sigdelsanjog@gmail.com>
|
|
6
6
|
Maintainer-email: Sanjog Sigdel <sigdelsanjog@gmail.com>
|
|
7
|
-
License: MIT
|
|
8
|
-
|
|
9
|
-
Copyright (c) 2026 Your Name
|
|
10
|
-
|
|
11
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
-
in the Software without restriction, including without limitation the rights
|
|
14
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
-
furnished to do so, subject to the following conditions:
|
|
17
|
-
|
|
18
|
-
The above copyright notice and this permission notice shall be included in all
|
|
19
|
-
copies or substantial portions of the Software.
|
|
20
|
-
|
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
-
SOFTWARE.
|
|
28
|
-
|
|
7
|
+
License-Expression: MIT
|
|
29
8
|
Project-URL: Homepage, https://github.com/sigdelsanjog/gptmed
|
|
30
9
|
Project-URL: Documentation, https://github.com/sigdelsanjog/gptmed#readme
|
|
31
10
|
Project-URL: Repository, https://github.com/sigdelsanjog/gptmed
|
|
@@ -37,7 +16,6 @@ Classifier: Intended Audience :: Science/Research
|
|
|
37
16
|
Classifier: Intended Audience :: Education
|
|
38
17
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
39
18
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
40
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
41
19
|
Classifier: Programming Language :: Python :: 3
|
|
42
20
|
Classifier: Programming Language :: Python :: 3.8
|
|
43
21
|
Classifier: Programming Language :: Python :: 3.9
|
|
@@ -51,6 +29,7 @@ Requires-Dist: torch>=2.0.0
|
|
|
51
29
|
Requires-Dist: sentencepiece>=0.1.99
|
|
52
30
|
Requires-Dist: numpy>=1.24.0
|
|
53
31
|
Requires-Dist: tqdm>=4.65.0
|
|
32
|
+
Requires-Dist: pyyaml>=6.0
|
|
54
33
|
Provides-Extra: dev
|
|
55
34
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
56
35
|
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
@@ -69,6 +48,10 @@ A lightweight GPT-based language model framework for training custom question-an
|
|
|
69
48
|
[](https://www.python.org/downloads/)
|
|
70
49
|
[](https://opensource.org/licenses/MIT)
|
|
71
50
|
|
|
51
|
+
## 📖 [Complete User Manual](USER_MANUAL.md) | [Quick Start](#quick-start)
|
|
52
|
+
|
|
53
|
+
> **New to GptMed?** Check out the [**step-by-step User Manual**](USER_MANUAL.md) for a complete guide on training your own model!
|
|
54
|
+
|
|
72
55
|
## Features
|
|
73
56
|
|
|
74
57
|
- 🧠 **Custom GPT Architecture**: Lightweight transformer model for any Q&A domain
|
|
@@ -78,6 +61,27 @@ A lightweight GPT-based language model framework for training custom question-an
|
|
|
78
61
|
- 📦 **Lightweight**: Small model size suitable for edge deployment
|
|
79
62
|
- 🛠️ **Complete Toolkit**: Includes tokenizer training, model training, and inference utilities
|
|
80
63
|
|
|
64
|
+
## Table of Contents
|
|
65
|
+
|
|
66
|
+
- [Features](#features)
|
|
67
|
+
- [Installation](#installation)
|
|
68
|
+
- [Quick Start](#quick-start)
|
|
69
|
+
- [Package Structure](#package-structure)
|
|
70
|
+
- [Core Modules](#core-modules)
|
|
71
|
+
- [Model Components](#model-components)
|
|
72
|
+
- [Training Components](#training-components)
|
|
73
|
+
- [Inference Components](#inference-components)
|
|
74
|
+
- [Data Processing](#data-processing)
|
|
75
|
+
- [Utilities](#utilities)
|
|
76
|
+
- [Model Architecture](#model-architecture)
|
|
77
|
+
- [Configuration](#configuration)
|
|
78
|
+
- [Documentation](#documentation)
|
|
79
|
+
- [Performance](#performance)
|
|
80
|
+
- [Examples](#examples)
|
|
81
|
+
- [Contributing](#contributing)
|
|
82
|
+
- [License](#license)
|
|
83
|
+
- [Support](#support)
|
|
84
|
+
|
|
81
85
|
## Installation
|
|
82
86
|
|
|
83
87
|
### From PyPI (Recommended)
|
|
@@ -204,27 +208,134 @@ config = TrainingConfig(
|
|
|
204
208
|
)
|
|
205
209
|
```
|
|
206
210
|
|
|
207
|
-
##
|
|
211
|
+
## Package Structure
|
|
212
|
+
|
|
213
|
+
### Core Modules
|
|
214
|
+
|
|
215
|
+
The `gptmed` package contains the following main modules:
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
gptmed/
|
|
219
|
+
├── model/ # Model architecture and configurations
|
|
220
|
+
├── inference/ # Text generation and sampling
|
|
221
|
+
├── training/ # Training loops and datasets
|
|
222
|
+
├── tokenizer/ # Tokenizer training and data processing
|
|
223
|
+
├── data/ # Data parsers and formatters
|
|
224
|
+
├── configs/ # Training configurations
|
|
225
|
+
└── utils/ # Utilities (checkpoints, logging)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Model Components
|
|
229
|
+
|
|
230
|
+
**`gptmed.model.architecture`** - GPT Transformer Implementation
|
|
231
|
+
|
|
232
|
+
- `GPTTransformer` - Main model class
|
|
233
|
+
- `TransformerBlock` - Individual transformer layers
|
|
234
|
+
- `MultiHeadAttention` - Attention mechanism
|
|
235
|
+
- `FeedForward` - Feed-forward networks
|
|
236
|
+
- `RoPEPositionalEncoding` - Rotary position embeddings
|
|
237
|
+
|
|
238
|
+
**`gptmed.model.configs`** - Model Configurations
|
|
239
|
+
|
|
240
|
+
- `get_tiny_config()` - ~2M parameters (testing)
|
|
241
|
+
- `get_small_config()` - ~10M parameters (recommended)
|
|
242
|
+
- `get_medium_config()` - ~50M parameters (high quality)
|
|
243
|
+
- `ModelConfig` - Custom configuration class
|
|
244
|
+
|
|
245
|
+
### Training Components
|
|
246
|
+
|
|
247
|
+
**`gptmed.training`** - Training Pipeline
|
|
248
|
+
|
|
249
|
+
- `train.py` - Main training script (CLI: `gptmed-train`)
|
|
250
|
+
- `Trainer` - Training loop with checkpointing
|
|
251
|
+
- `TokenizedDataset` - PyTorch dataset for tokenized data
|
|
252
|
+
- `create_dataloaders()` - DataLoader creation utilities
|
|
253
|
+
|
|
254
|
+
**`gptmed.configs`** - Training Configurations
|
|
255
|
+
|
|
256
|
+
- `TrainingConfig` - Training hyperparameters
|
|
257
|
+
- `get_default_config()` - Default training settings
|
|
258
|
+
- `get_quick_test_config()` - Fast testing configuration
|
|
259
|
+
|
|
260
|
+
### Inference Components
|
|
261
|
+
|
|
262
|
+
**`gptmed.inference`** - Text Generation
|
|
263
|
+
|
|
264
|
+
- `TextGenerator` - Main generation class
|
|
265
|
+
- `generator.py` - CLI command (CLI: `gptmed-generate`)
|
|
266
|
+
- `sampling.py` - Sampling strategies (top-k, top-p, temperature)
|
|
267
|
+
- `decoding_utils.py` - Decoding utilities
|
|
268
|
+
- `GenerationConfig` - Generation parameters
|
|
269
|
+
|
|
270
|
+
### Data Processing
|
|
271
|
+
|
|
272
|
+
**`gptmed.tokenizer`** - Tokenizer Training & Data Processing
|
|
273
|
+
|
|
274
|
+
- `train_tokenizer.py` - Train SentencePiece tokenizer
|
|
275
|
+
- `tokenize_data.py` - Convert text to token sequences
|
|
276
|
+
- SentencePiece BPE tokenizer support
|
|
277
|
+
|
|
278
|
+
**`gptmed.data.parsers`** - Data Parsing & Formatting
|
|
279
|
+
|
|
280
|
+
- `MedQuADParser` - XML Q&A parser (example)
|
|
281
|
+
- `CausalTextFormatter` - Format Q&A pairs for training
|
|
282
|
+
- `FormatConfig` - Formatting configuration
|
|
283
|
+
|
|
284
|
+
### Utilities
|
|
285
|
+
|
|
286
|
+
**`gptmed.utils`** - Helper Functions
|
|
287
|
+
|
|
288
|
+
- `checkpoints.py` - Model checkpoint management
|
|
289
|
+
- `logging.py` - Training metrics logging
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## Detailed Project Structure
|
|
208
294
|
|
|
209
295
|
```
|
|
210
296
|
gptmed/
|
|
211
297
|
├── model/
|
|
212
|
-
│ ├── architecture/
|
|
213
|
-
│
|
|
298
|
+
│ ├── architecture/
|
|
299
|
+
│ │ ├── gpt.py # GPT transformer model
|
|
300
|
+
│ │ ├── attention.py # Multi-head attention
|
|
301
|
+
│ │ ├── feedforward.py # Feed-forward networks
|
|
302
|
+
│ │ └── embeddings.py # Token + positional embeddings
|
|
303
|
+
│ └── configs/
|
|
304
|
+
│ └── model_config.py # Model size configurations
|
|
214
305
|
├── inference/
|
|
215
|
-
│ ├── generator.py
|
|
216
|
-
│
|
|
306
|
+
│ ├── generator.py # Text generation (CLI command)
|
|
307
|
+
│ ├── sampling.py # Sampling strategies
|
|
308
|
+
│ ├── decoding_utils.py # Decoding utilities
|
|
309
|
+
│ └── generation_config.py # Generation parameters
|
|
217
310
|
├── training/
|
|
218
|
-
│ ├── train.py
|
|
219
|
-
│ ├── trainer.py
|
|
220
|
-
│
|
|
311
|
+
│ ├── train.py # Main training script (CLI command)
|
|
312
|
+
│ ├── trainer.py # Training loop
|
|
313
|
+
│ ├── dataset.py # PyTorch dataset
|
|
314
|
+
│ └── utils.py # Training utilities
|
|
221
315
|
├── tokenizer/
|
|
222
|
-
│
|
|
316
|
+
│ ├── train_tokenizer.py # Train SentencePiece tokenizer
|
|
317
|
+
│ └── tokenize_data.py # Tokenize text data
|
|
318
|
+
├── data/
|
|
319
|
+
│ └── parsers/
|
|
320
|
+
│ ├── medquad_parser.py # Example XML parser
|
|
321
|
+
│ └── text_formatter.py # Q&A text formatter
|
|
223
322
|
├── configs/
|
|
224
|
-
│ └── train_config.py
|
|
323
|
+
│ └── train_config.py # Training configurations
|
|
225
324
|
└── utils/
|
|
226
|
-
├── checkpoints.py
|
|
227
|
-
└── logging.py
|
|
325
|
+
├── checkpoints.py # Model checkpointing
|
|
326
|
+
└── logging.py # Training logging
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Command-Line Interface
|
|
330
|
+
|
|
331
|
+
The package provides two main CLI commands:
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
# Train a model
|
|
335
|
+
gptmed-train --model-size small --num-epochs 10 --batch-size 16
|
|
336
|
+
|
|
337
|
+
# Generate text
|
|
338
|
+
gptmed-generate --prompt "Your question?" --max-length 100
|
|
228
339
|
```
|
|
229
340
|
|
|
230
341
|
## Requirements
|
|
@@ -237,14 +348,14 @@ gptmed/
|
|
|
237
348
|
|
|
238
349
|
## Documentation
|
|
239
350
|
|
|
240
|
-
|
|
351
|
+
📚 **[Complete User Manual](USER_MANUAL.md)** - Step-by-step guide for training your own model
|
|
241
352
|
|
|
242
|
-
###
|
|
353
|
+
### Quick Links
|
|
243
354
|
|
|
244
|
-
- [
|
|
245
|
-
- [
|
|
246
|
-
- [
|
|
247
|
-
- [
|
|
355
|
+
- [User Manual](USER_MANUAL.md) - **Start here!** Complete training pipeline guide
|
|
356
|
+
- [Architecture Guide](ARCHITECTURE_EXTENSION_GUIDE.md) - Understanding the model architecture
|
|
357
|
+
- [Deployment Guide](DEPLOYMENT_GUIDE.md) - Publishing to PyPI
|
|
358
|
+
- [Changelog](CHANGELOG.md) - Version history
|
|
248
359
|
|
|
249
360
|
## Performance
|
|
250
361
|
|
|
@@ -312,7 +423,8 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
312
423
|
|
|
313
424
|
## Support
|
|
314
425
|
|
|
315
|
-
-
|
|
426
|
+
- � **[User Manual](USER_MANUAL.md)** - Complete step-by-step training guide
|
|
427
|
+
- �📫 Issues: [GitHub Issues](https://github.com/sigdelsanjog/gptmed/issues)
|
|
316
428
|
- 💬 Discussions: [GitHub Discussions](https://github.com/sigdelsanjog/gptmed/discussions)
|
|
317
429
|
- 📧 Email: sanjog.sigdel@ku.edu.np
|
|
318
430
|
|
|
@@ -6,6 +6,10 @@ A lightweight GPT-based language model framework for training custom question-an
|
|
|
6
6
|
[](https://www.python.org/downloads/)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
|
|
9
|
+
## 📖 [Complete User Manual](USER_MANUAL.md) | [Quick Start](#quick-start)
|
|
10
|
+
|
|
11
|
+
> **New to GptMed?** Check out the [**step-by-step User Manual**](USER_MANUAL.md) for a complete guide on training your own model!
|
|
12
|
+
|
|
9
13
|
## Features
|
|
10
14
|
|
|
11
15
|
- 🧠 **Custom GPT Architecture**: Lightweight transformer model for any Q&A domain
|
|
@@ -15,6 +19,27 @@ A lightweight GPT-based language model framework for training custom question-an
|
|
|
15
19
|
- 📦 **Lightweight**: Small model size suitable for edge deployment
|
|
16
20
|
- 🛠️ **Complete Toolkit**: Includes tokenizer training, model training, and inference utilities
|
|
17
21
|
|
|
22
|
+
## Table of Contents
|
|
23
|
+
|
|
24
|
+
- [Features](#features)
|
|
25
|
+
- [Installation](#installation)
|
|
26
|
+
- [Quick Start](#quick-start)
|
|
27
|
+
- [Package Structure](#package-structure)
|
|
28
|
+
- [Core Modules](#core-modules)
|
|
29
|
+
- [Model Components](#model-components)
|
|
30
|
+
- [Training Components](#training-components)
|
|
31
|
+
- [Inference Components](#inference-components)
|
|
32
|
+
- [Data Processing](#data-processing)
|
|
33
|
+
- [Utilities](#utilities)
|
|
34
|
+
- [Model Architecture](#model-architecture)
|
|
35
|
+
- [Configuration](#configuration)
|
|
36
|
+
- [Documentation](#documentation)
|
|
37
|
+
- [Performance](#performance)
|
|
38
|
+
- [Examples](#examples)
|
|
39
|
+
- [Contributing](#contributing)
|
|
40
|
+
- [License](#license)
|
|
41
|
+
- [Support](#support)
|
|
42
|
+
|
|
18
43
|
## Installation
|
|
19
44
|
|
|
20
45
|
### From PyPI (Recommended)
|
|
@@ -141,27 +166,134 @@ config = TrainingConfig(
|
|
|
141
166
|
)
|
|
142
167
|
```
|
|
143
168
|
|
|
144
|
-
##
|
|
169
|
+
## Package Structure
|
|
170
|
+
|
|
171
|
+
### Core Modules
|
|
172
|
+
|
|
173
|
+
The `gptmed` package contains the following main modules:
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
gptmed/
|
|
177
|
+
├── model/ # Model architecture and configurations
|
|
178
|
+
├── inference/ # Text generation and sampling
|
|
179
|
+
├── training/ # Training loops and datasets
|
|
180
|
+
├── tokenizer/ # Tokenizer training and data processing
|
|
181
|
+
├── data/ # Data parsers and formatters
|
|
182
|
+
├── configs/ # Training configurations
|
|
183
|
+
└── utils/ # Utilities (checkpoints, logging)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Model Components
|
|
187
|
+
|
|
188
|
+
**`gptmed.model.architecture`** - GPT Transformer Implementation
|
|
189
|
+
|
|
190
|
+
- `GPTTransformer` - Main model class
|
|
191
|
+
- `TransformerBlock` - Individual transformer layers
|
|
192
|
+
- `MultiHeadAttention` - Attention mechanism
|
|
193
|
+
- `FeedForward` - Feed-forward networks
|
|
194
|
+
- `RoPEPositionalEncoding` - Rotary position embeddings
|
|
195
|
+
|
|
196
|
+
**`gptmed.model.configs`** - Model Configurations
|
|
197
|
+
|
|
198
|
+
- `get_tiny_config()` - ~2M parameters (testing)
|
|
199
|
+
- `get_small_config()` - ~10M parameters (recommended)
|
|
200
|
+
- `get_medium_config()` - ~50M parameters (high quality)
|
|
201
|
+
- `ModelConfig` - Custom configuration class
|
|
202
|
+
|
|
203
|
+
### Training Components
|
|
204
|
+
|
|
205
|
+
**`gptmed.training`** - Training Pipeline
|
|
206
|
+
|
|
207
|
+
- `train.py` - Main training script (CLI: `gptmed-train`)
|
|
208
|
+
- `Trainer` - Training loop with checkpointing
|
|
209
|
+
- `TokenizedDataset` - PyTorch dataset for tokenized data
|
|
210
|
+
- `create_dataloaders()` - DataLoader creation utilities
|
|
211
|
+
|
|
212
|
+
**`gptmed.configs`** - Training Configurations
|
|
213
|
+
|
|
214
|
+
- `TrainingConfig` - Training hyperparameters
|
|
215
|
+
- `get_default_config()` - Default training settings
|
|
216
|
+
- `get_quick_test_config()` - Fast testing configuration
|
|
217
|
+
|
|
218
|
+
### Inference Components
|
|
219
|
+
|
|
220
|
+
**`gptmed.inference`** - Text Generation
|
|
221
|
+
|
|
222
|
+
- `TextGenerator` - Main generation class
|
|
223
|
+
- `generator.py` - CLI command (CLI: `gptmed-generate`)
|
|
224
|
+
- `sampling.py` - Sampling strategies (top-k, top-p, temperature)
|
|
225
|
+
- `decoding_utils.py` - Decoding utilities
|
|
226
|
+
- `GenerationConfig` - Generation parameters
|
|
227
|
+
|
|
228
|
+
### Data Processing
|
|
229
|
+
|
|
230
|
+
**`gptmed.tokenizer`** - Tokenizer Training & Data Processing
|
|
231
|
+
|
|
232
|
+
- `train_tokenizer.py` - Train SentencePiece tokenizer
|
|
233
|
+
- `tokenize_data.py` - Convert text to token sequences
|
|
234
|
+
- SentencePiece BPE tokenizer support
|
|
235
|
+
|
|
236
|
+
**`gptmed.data.parsers`** - Data Parsing & Formatting
|
|
237
|
+
|
|
238
|
+
- `MedQuADParser` - XML Q&A parser (example)
|
|
239
|
+
- `CausalTextFormatter` - Format Q&A pairs for training
|
|
240
|
+
- `FormatConfig` - Formatting configuration
|
|
241
|
+
|
|
242
|
+
### Utilities
|
|
243
|
+
|
|
244
|
+
**`gptmed.utils`** - Helper Functions
|
|
245
|
+
|
|
246
|
+
- `checkpoints.py` - Model checkpoint management
|
|
247
|
+
- `logging.py` - Training metrics logging
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## Detailed Project Structure
|
|
145
252
|
|
|
146
253
|
```
|
|
147
254
|
gptmed/
|
|
148
255
|
├── model/
|
|
149
|
-
│ ├── architecture/
|
|
150
|
-
│
|
|
256
|
+
│ ├── architecture/
|
|
257
|
+
│ │ ├── gpt.py # GPT transformer model
|
|
258
|
+
│ │ ├── attention.py # Multi-head attention
|
|
259
|
+
│ │ ├── feedforward.py # Feed-forward networks
|
|
260
|
+
│ │ └── embeddings.py # Token + positional embeddings
|
|
261
|
+
│ └── configs/
|
|
262
|
+
│ └── model_config.py # Model size configurations
|
|
151
263
|
├── inference/
|
|
152
|
-
│ ├── generator.py
|
|
153
|
-
│
|
|
264
|
+
│ ├── generator.py # Text generation (CLI command)
|
|
265
|
+
│ ├── sampling.py # Sampling strategies
|
|
266
|
+
│ ├── decoding_utils.py # Decoding utilities
|
|
267
|
+
│ └── generation_config.py # Generation parameters
|
|
154
268
|
├── training/
|
|
155
|
-
│ ├── train.py
|
|
156
|
-
│ ├── trainer.py
|
|
157
|
-
│
|
|
269
|
+
│ ├── train.py # Main training script (CLI command)
|
|
270
|
+
│ ├── trainer.py # Training loop
|
|
271
|
+
│ ├── dataset.py # PyTorch dataset
|
|
272
|
+
│ └── utils.py # Training utilities
|
|
158
273
|
├── tokenizer/
|
|
159
|
-
│
|
|
274
|
+
│ ├── train_tokenizer.py # Train SentencePiece tokenizer
|
|
275
|
+
│ └── tokenize_data.py # Tokenize text data
|
|
276
|
+
├── data/
|
|
277
|
+
│ └── parsers/
|
|
278
|
+
│ ├── medquad_parser.py # Example XML parser
|
|
279
|
+
│ └── text_formatter.py # Q&A text formatter
|
|
160
280
|
├── configs/
|
|
161
|
-
│ └── train_config.py
|
|
281
|
+
│ └── train_config.py # Training configurations
|
|
162
282
|
└── utils/
|
|
163
|
-
├── checkpoints.py
|
|
164
|
-
└── logging.py
|
|
283
|
+
├── checkpoints.py # Model checkpointing
|
|
284
|
+
└── logging.py # Training logging
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Command-Line Interface
|
|
288
|
+
|
|
289
|
+
The package provides two main CLI commands:
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
# Train a model
|
|
293
|
+
gptmed-train --model-size small --num-epochs 10 --batch-size 16
|
|
294
|
+
|
|
295
|
+
# Generate text
|
|
296
|
+
gptmed-generate --prompt "Your question?" --max-length 100
|
|
165
297
|
```
|
|
166
298
|
|
|
167
299
|
## Requirements
|
|
@@ -174,14 +306,14 @@ gptmed/
|
|
|
174
306
|
|
|
175
307
|
## Documentation
|
|
176
308
|
|
|
177
|
-
|
|
309
|
+
📚 **[Complete User Manual](USER_MANUAL.md)** - Step-by-step guide for training your own model
|
|
178
310
|
|
|
179
|
-
###
|
|
311
|
+
### Quick Links
|
|
180
312
|
|
|
181
|
-
- [
|
|
182
|
-
- [
|
|
183
|
-
- [
|
|
184
|
-
- [
|
|
313
|
+
- [User Manual](USER_MANUAL.md) - **Start here!** Complete training pipeline guide
|
|
314
|
+
- [Architecture Guide](ARCHITECTURE_EXTENSION_GUIDE.md) - Understanding the model architecture
|
|
315
|
+
- [Deployment Guide](DEPLOYMENT_GUIDE.md) - Publishing to PyPI
|
|
316
|
+
- [Changelog](CHANGELOG.md) - Version history
|
|
185
317
|
|
|
186
318
|
## Performance
|
|
187
319
|
|
|
@@ -249,7 +381,8 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
249
381
|
|
|
250
382
|
## Support
|
|
251
383
|
|
|
252
|
-
-
|
|
384
|
+
- � **[User Manual](USER_MANUAL.md)** - Complete step-by-step training guide
|
|
385
|
+
- �📫 Issues: [GitHub Issues](https://github.com/sigdelsanjog/gptmed/issues)
|
|
253
386
|
- 💬 Discussions: [GitHub Discussions](https://github.com/sigdelsanjog/gptmed/discussions)
|
|
254
387
|
- 📧 Email: sanjog.sigdel@ku.edu.np
|
|
255
388
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""
|
|
2
|
+
GptMed: A lightweight GPT-based language model framework
|
|
3
|
+
|
|
4
|
+
A domain-agnostic framework for training custom question-answering models.
|
|
5
|
+
Train your own GPT model on any Q&A dataset - medical, technical support,
|
|
6
|
+
education, or any other domain.
|
|
7
|
+
|
|
8
|
+
Quick Start:
|
|
9
|
+
>>> import gptmed
|
|
10
|
+
>>>
|
|
11
|
+
>>> # 1. Create a config file
|
|
12
|
+
>>> gptmed.create_config('my_config.yaml')
|
|
13
|
+
>>>
|
|
14
|
+
>>> # 2. Edit my_config.yaml with your settings
|
|
15
|
+
>>>
|
|
16
|
+
>>> # 3. Train your model
|
|
17
|
+
>>> results = gptmed.train_from_config('my_config.yaml')
|
|
18
|
+
>>>
|
|
19
|
+
>>> # 4. Generate answers
|
|
20
|
+
>>> answer = gptmed.generate(
|
|
21
|
+
... checkpoint=results['best_checkpoint'],
|
|
22
|
+
... tokenizer='tokenizer/my_tokenizer.model',
|
|
23
|
+
... prompt='Your question here?'
|
|
24
|
+
... )
|
|
25
|
+
|
|
26
|
+
Advanced Usage:
|
|
27
|
+
>>> from gptmed.model.architecture import GPTTransformer
|
|
28
|
+
>>> from gptmed.model.configs.model_config import get_small_config
|
|
29
|
+
>>> from gptmed.inference.generator import TextGenerator
|
|
30
|
+
>>>
|
|
31
|
+
>>> config = get_small_config()
|
|
32
|
+
>>> model = GPTTransformer(config)
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
__version__ = "0.3.0"
|
|
36
|
+
__author__ = "Sanjog Sigdel"
|
|
37
|
+
__email__ = "sigdelsanjog@gmail.com"
|
|
38
|
+
|
|
39
|
+
# High-level API - Main user interface
|
|
40
|
+
from gptmed.api import (
|
|
41
|
+
create_config,
|
|
42
|
+
train_from_config,
|
|
43
|
+
generate,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# Expose main components at package level for convenience
|
|
47
|
+
from gptmed.model.architecture import GPTTransformer
|
|
48
|
+
from gptmed.model.configs.model_config import ModelConfig, get_small_config, get_tiny_config
|
|
49
|
+
|
|
50
|
+
__all__ = [
|
|
51
|
+
# Simple API
|
|
52
|
+
"create_config",
|
|
53
|
+
"train_from_config",
|
|
54
|
+
"generate",
|
|
55
|
+
# Advanced API
|
|
56
|
+
"GPTTransformer",
|
|
57
|
+
"ModelConfig",
|
|
58
|
+
"get_small_config",
|
|
59
|
+
"get_tiny_config",
|
|
60
|
+
]
|