micm-nlp 0.1.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.
Files changed (70) hide show
  1. micm_nlp-0.1.0/.env.example +6 -0
  2. micm_nlp-0.1.0/.gitignore +28 -0
  3. micm_nlp-0.1.0/CHANGELOG.md +13 -0
  4. micm_nlp-0.1.0/CLAUDE.md +131 -0
  5. micm_nlp-0.1.0/LICENSE +21 -0
  6. micm_nlp-0.1.0/PKG-INFO +208 -0
  7. micm_nlp-0.1.0/README.md +158 -0
  8. micm_nlp-0.1.0/dockerfile +25 -0
  9. micm_nlp-0.1.0/examples/configs/xsc_finetune.yml +191 -0
  10. micm_nlp-0.1.0/examples/configs/xsc_preprocess.yml +65 -0
  11. micm_nlp-0.1.0/examples/preprocess_dataset.py +19 -0
  12. micm_nlp-0.1.0/examples/run_model.py +20 -0
  13. micm_nlp-0.1.0/pyproject.toml +88 -0
  14. micm_nlp-0.1.0/src/micm_nlp/__init__.py +2 -0
  15. micm_nlp-0.1.0/src/micm_nlp/config.py +382 -0
  16. micm_nlp-0.1.0/src/micm_nlp/datasets/__init__.py +0 -0
  17. micm_nlp-0.1.0/src/micm_nlp/datasets/dataset.py +1292 -0
  18. micm_nlp-0.1.0/src/micm_nlp/enums.py +232 -0
  19. micm_nlp-0.1.0/src/micm_nlp/env.py +28 -0
  20. micm_nlp-0.1.0/src/micm_nlp/evals/__init__.py +0 -0
  21. micm_nlp-0.1.0/src/micm_nlp/evals/eval.py +342 -0
  22. micm_nlp-0.1.0/src/micm_nlp/evals/metrics/log_likelihood.py +41 -0
  23. micm_nlp-0.1.0/src/micm_nlp/evals/metrics/multirc.py +35 -0
  24. micm_nlp-0.1.0/src/micm_nlp/evals/metrics/string_f1/__init__.py +5 -0
  25. micm_nlp-0.1.0/src/micm_nlp/evals/metrics/string_f1/string_f1.py +59 -0
  26. micm_nlp-0.1.0/src/micm_nlp/evals/plot.py +20 -0
  27. micm_nlp-0.1.0/src/micm_nlp/models/__init__.py +0 -0
  28. micm_nlp-0.1.0/src/micm_nlp/models/architectures.py +259 -0
  29. micm_nlp-0.1.0/src/micm_nlp/models/model.py +307 -0
  30. micm_nlp-0.1.0/src/micm_nlp/models/peft.py +73 -0
  31. micm_nlp-0.1.0/src/micm_nlp/models/xpe/__init__.py +55 -0
  32. micm_nlp-0.1.0/src/micm_nlp/models/xpe/config.py +93 -0
  33. micm_nlp-0.1.0/src/micm_nlp/models/xpe/encoder.py +327 -0
  34. micm_nlp-0.1.0/src/micm_nlp/models/xpe/enums.py +10 -0
  35. micm_nlp-0.1.0/src/micm_nlp/models/xpe/factory.py +140 -0
  36. micm_nlp-0.1.0/src/micm_nlp/models/xpe/heads.py +94 -0
  37. micm_nlp-0.1.0/src/micm_nlp/models/xpe/peft_models.py +219 -0
  38. micm_nlp-0.1.0/src/micm_nlp/models/xpe/save_load.py +231 -0
  39. micm_nlp-0.1.0/src/micm_nlp/path.py +78 -0
  40. micm_nlp-0.1.0/src/micm_nlp/pipeline.py +44 -0
  41. micm_nlp-0.1.0/src/micm_nlp/setup.py +35 -0
  42. micm_nlp-0.1.0/src/micm_nlp/tokenizers/__init__.py +0 -0
  43. micm_nlp-0.1.0/src/micm_nlp/tokenizers/bert_byt5.py +40 -0
  44. micm_nlp-0.1.0/src/micm_nlp/tokenizers/decoding.py +12 -0
  45. micm_nlp-0.1.0/src/micm_nlp/tokenizers/lib/__init__.py +0 -0
  46. micm_nlp-0.1.0/src/micm_nlp/tokenizers/lib/sent/__init__.py +0 -0
  47. micm_nlp-0.1.0/src/micm_nlp/tokenizers/lib/sent/ka_sen_tok.py +76 -0
  48. micm_nlp-0.1.0/src/micm_nlp/tokenizers/tokenizer.py +542 -0
  49. micm_nlp-0.1.0/src/micm_nlp/tokenizers/xlm_roberta.py +20 -0
  50. micm_nlp-0.1.0/src/micm_nlp/training/__init__.py +1 -0
  51. micm_nlp-0.1.0/src/micm_nlp/training/callbacks.py +258 -0
  52. micm_nlp-0.1.0/src/micm_nlp/training/data_collators.py +319 -0
  53. micm_nlp-0.1.0/src/micm_nlp/training/logits_processors.py +48 -0
  54. micm_nlp-0.1.0/src/micm_nlp/training/runner.py +614 -0
  55. micm_nlp-0.1.0/src/micm_nlp/training/trainers.py +492 -0
  56. micm_nlp-0.1.0/src/micm_nlp/utils.py +471 -0
  57. micm_nlp-0.1.0/tests/__init__.py +0 -0
  58. micm_nlp-0.1.0/tests/golden/ratio0.0_headMLP.json +94 -0
  59. micm_nlp-0.1.0/tests/golden/ratio0.3_headMLP.json +161 -0
  60. micm_nlp-0.1.0/tests/golden/ratio0.5_headATTN.json +217 -0
  61. micm_nlp-0.1.0/tests/golden/ratio0.5_headLSTM.json +294 -0
  62. micm_nlp-0.1.0/tests/golden/ratio0.5_headMLP.json +161 -0
  63. micm_nlp-0.1.0/tests/golden/ratio0.7_headMLP.json +161 -0
  64. micm_nlp-0.1.0/tests/golden/ratio1.0_headATTN.json +207 -0
  65. micm_nlp-0.1.0/tests/golden/ratio1.0_headLSTM.json +284 -0
  66. micm_nlp-0.1.0/tests/golden/ratio1.0_headMLP.json +151 -0
  67. micm_nlp-0.1.0/tests/golden/ratio1.0_headNONE.json +94 -0
  68. micm_nlp-0.1.0/tests/test_causal_lm.py +145 -0
  69. micm_nlp-0.1.0/tests/test_load_parity.py +263 -0
  70. micm_nlp-0.1.0/tests/test_parity.py +210 -0
@@ -0,0 +1,6 @@
1
+ PACKAGE_NAME=nlpka
2
+ APP_NAME=${PACKAGE_NAME}
3
+ APP_ENV=local
4
+ SHOW_LOCALS=0
5
+ WANDB_API_KEY=
6
+ HF_TOKEN=
@@ -0,0 +1,28 @@
1
+ .env
2
+ .cursorignore
3
+ .venv/
4
+ .vscode/
5
+ .claude/
6
+
7
+ .DS_Store
8
+ *.DS_Store
9
+
10
+ __pycache__
11
+ .ipynb_checkpoints
12
+
13
+ !__init__.py
14
+
15
+ **cache*
16
+ !*cache.py
17
+
18
+ artefacts/
19
+ runtime/
20
+ exp/
21
+
22
+ dist/
23
+ build/
24
+ *.egg-info/
25
+ wandb/
26
+ logs/
27
+ docs/internal/
28
+ docs/superpowers/
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ All notable changes to micm-nlp will be documented here.
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
+
6
+ ## [0.1.0] - 2026-04-30
7
+
8
+ ### Added
9
+ - Initial public release of the micm-nlp toolkit.
10
+ - Config-driven pipeline (tokenization → preprocessing → training → evaluation).
11
+ - Example: HuggingFace Hub dataset loading + decoder-only tokenization (`examples/preprocess_dataset.py` + `examples/configs/xsc_preprocess.yml`).
12
+ - Example: PEFT fine-tuning + evaluation using Cross-Prompt Encoder (XPE) on a decoder-only LM (`examples/run_model.py` + `examples/configs/xsc_finetune.yml`).
13
+ - WandB experiment tracking integration.
@@ -0,0 +1,131 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ **nlpka** is an NLP research toolkit built on HuggingFace Transformers, supporting tokenization, pretraining, fine-tuning, and PEFT across encoder-only, decoder-only, and encoder-decoder architectures. It has been used in two peer-reviewed publications covering BERT-like pretraining/fine-tuning for text and token classification, and parameter-efficient soft prompt tuning across 200 languages (SIB-200 topic classification) with cross-prompt encoders on XLM-RoBERTa-large. The most recent work — **Cross-Prompt Encoder (XPE)** — is accepted at *Findings of IJCNLP–AACL 2025* ([arXiv:2508.10352](https://arxiv.org/abs/2508.10352)). The toolkit is expanding to decoder-only models and includes T5 encoder-decoder pipelines for fine-tuning and evaluation.
8
+
9
+ ## Setup
10
+
11
+ ```bash
12
+ cp .env.example .env # add WANDB_API_KEY to .env
13
+
14
+ # Docker (recommended)
15
+ docker build -t xpe .
16
+ docker run --gpus all -it --rm -v $(pwd):/xpe_runner -w /xpe_runner xpe bash
17
+
18
+ # Local
19
+ pip install -e ".[dev]"
20
+ ```
21
+
22
+ ## Common Commands
23
+
24
+ **Download dataset:**
25
+ ```bash
26
+ python -m micm_nlp.datasets.scripts.sib200.download_tokenized
27
+ ```
28
+
29
+ **Run experiment (main entrypoint):**
30
+ ```bash
31
+ python -m micm_nlp.models.scripts.peft.xpe.run \
32
+ --config xlmr/finetune/peft/sib200_hybrid.xpe \
33
+ --supervision_regime=<0|1> <source_dataset> <setup_id>
34
+ ```
35
+
36
+ - `--supervision_regime`: `0` = Zero-Shot XLT, `1` = Fully Supervised XLT
37
+ - `<source_dataset>`: `sib200_enarzho`, `sib200_joshi5`, `sib200_xlmr_seen` (zero-shot) or `sib200_joshi5_divers_24` (supervised)
38
+ - `<setup_id>`: `1`=SPT, `2`=D30 (30% XPE hybrid), `3`=D70 (70% XPE hybrid), `4`=XPE
39
+
40
+ **Collect hidden states:**
41
+ ```bash
42
+ python -m micm_nlp.models.scripts.peft.xpe.collect_hs_v
43
+ ```
44
+
45
+ **Evaluate AYA on Belebele:**
46
+ ```bash
47
+ python -m micm_nlp.evaluations.scripts.eval_aya_belebele
48
+ ```
49
+
50
+ **Visualize / quantitative analysis:**
51
+ ```bash
52
+ python -m micm_nlp.evaluations.scripts.plot
53
+ python -m micm_nlp.evaluations.scripts.quant
54
+ ```
55
+
56
+ **Lint & format:**
57
+ ```bash
58
+ ruff check src/
59
+ ruff format src/
60
+ ```
61
+
62
+ ## Project Structure
63
+
64
+ ```
65
+ ExpXPE/
66
+ ├── pyproject.toml # Package metadata, dependencies, ruff config
67
+ ├── dockerfile
68
+ ├── .env.example
69
+ ├── config/ # YAML experiment configs
70
+ ├── examples/ # Simple usage demos for the package API
71
+ ├── experiments/ # Research-specific code (XPE, SIB-200, evals)
72
+ │ ├── config/ # Experiment config utilities (xpe_utils, etc.)
73
+ │ ├── datasets/ # Dataset prep (SIB-200, Belebele, xStory, etc.)
74
+ │ ├── models/ # Experiment runners (XPE train, collect HS, etc.)
75
+ │ └── evals/ # Plots, quantitative analysis, eval scripts
76
+ ├── artefacts/ # Generated outputs
77
+ └── src/micm_nlp/ # Package source (standard src layout)
78
+ ├── pipeline.py # High-level wiring: load_dataset, load_model, run
79
+ ├── env.py # Loads .env, exposes os.environ as `env`
80
+ ├── setup.py # Runtime init (Rich pretty-printing + traceback)
81
+ ├── utils.py # Pure helpers, JSON/YAML/pickle I/O, SimpleNamespace utils
82
+ ├── path.py # Project path resolution, directory traversal
83
+ ├── enums.py # StrEnum definitions for all categorical choices
84
+ ├── config.py # Config loader (YAML → SimpleNamespace)
85
+ ├── datasets/ # Dataset loading/preprocessing
86
+ ├── tokenizers/ # Tokenizer factory (XLM-R, BERT, T5, etc.)
87
+ ├── models/ # Model, PEFT, XPE, trainers, callbacks
88
+ └── evals/ # Metrics, confusion matrices, plots
89
+ ```
90
+
91
+ ## Architecture
92
+
93
+ All core logic follows a class-based, config-driven pattern:
94
+
95
+ ```
96
+ CONFIG (YAML) → TOKENIZER → DATASET → MODEL → PEFT → Trainer → EVALUATE
97
+ ```
98
+
99
+ | Class | File | Role |
100
+ |-------|------|------|
101
+ | `CONFIG` | `src/nlpka/config/config.py` | Loads YAML configs from `config/language_model/` |
102
+ | `TOKENIZER` | `src/nlpka/tokenizers/tokenizer.py` | Tokenizer factory for XLM-R, BERT, T5, etc. |
103
+ | `DATASET` | `src/nlpka/datasets/dataset.py` | Loads/preprocesses HuggingFace, CSV, or TXT datasets |
104
+ | `MODEL` | `src/nlpka/models/model.py` | Wraps HuggingFace model + Trainer, WandB logging |
105
+ | `PEFT` | `src/nlpka/models/peft.py` | Attaches LoRA / Prefix / P-Tuning / XPE to base model |
106
+ | `CrossPromptEncoder` | `src/nlpka/models/xpe.py` | The XPE module (based on NeMo's prompt encoder) |
107
+ | `EVALUATE` | `src/nlpka/evals/eval.py` | Metrics (accuracy, F1), confusion matrices, t-SNE plots |
108
+
109
+ **PEFT dispatch**: `PEFT.setup_model()` checks `is_xpe_config()` to route between standard PEFT methods and the custom XPE path (`get_xpe_model()`, which instantiates `XPEPeftModelForSequenceClassification`). `PEFT.from_pretrained()` peeks at `adapter_config.json` via `is_xpe_adapter_dir()` and dispatches to `load_xpe_pretrained()` — this preserves loading of paper-era checkpoints saved with `peft_type='P_TUNING' + encoder_ratio`.
110
+
111
+ **Enums** in `src/nlpka/enums.py` define all categorical choices (`ModelArchSE`, `TaskCatSE`, etc.) using `StrEnum` — check here before adding new method/task types.
112
+
113
+ **Foundational modules** (no circular dependencies):
114
+
115
+ | Module | Role | Depends on |
116
+ |--------|------|------------|
117
+ | `env.py` | Loads `.env`, exposes `env` | stdlib only |
118
+ | `utils.py` | Pure helpers, file I/O | stdlib + numpy/rich/tqdm/yaml |
119
+ | `path.py` | Path resolution, directory ops | `env` |
120
+ | `setup.py` | Runtime init (`init()`): Rich pretty + traceback | stdlib + rich |
121
+ | `enums.py` | All `StrEnum` types | stdlib only |
122
+
123
+ **Runtime init**: Call `micm_nlp.setup.init()` at the top of entrypoint scripts to activate Rich pretty-printing and tracebacks. This is not triggered on import.
124
+
125
+ ## Key Conventions
126
+
127
+ - All experiments are tracked via **WandB** (`WANDB_API_KEY` in `.env`).
128
+ - HuggingFace token (`HF_TOKEN`) is needed for gated models/datasets.
129
+ - Model/dataset/tokenizer artifacts are cached under their respective `storage/` subdirectories.
130
+ - GPU training only (CPU supported for small-scale debugging); no non-NVIDIA GPU support.
131
+ - Package uses standard `src` layout — `pip install -e .` makes `from micm_nlp.X import Y` work.
micm_nlp-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Beso Mikaberidze
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: micm-nlp
3
+ Version: 0.1.0
4
+ Summary: NLP research toolkit built on HuggingFace Transformers
5
+ Project-URL: Homepage, https://github.com/bmikaberidze/micm-nlp
6
+ Project-URL: Repository, https://github.com/bmikaberidze/micm-nlp
7
+ Project-URL: Issues, https://github.com/bmikaberidze/micm-nlp/issues
8
+ Author-email: Beso Mikaberidze <beso.mikaberidze@gmail.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: accelerate
21
+ Requires-Dist: aenum
22
+ Requires-Dist: datasets
23
+ Requires-Dist: datasketch
24
+ Requires-Dist: evaluate
25
+ Requires-Dist: lightning
26
+ Requires-Dist: matplotlib
27
+ Requires-Dist: nltk
28
+ Requires-Dist: numpy
29
+ Requires-Dist: nvidia-ml-py3
30
+ Requires-Dist: opentsne
31
+ Requires-Dist: pandas
32
+ Requires-Dist: peft==0.14.0
33
+ Requires-Dist: pydantic-settings>=2.0
34
+ Requires-Dist: pydantic>=2.0
35
+ Requires-Dist: python-dotenv
36
+ Requires-Dist: pyyaml
37
+ Requires-Dist: requests
38
+ Requires-Dist: rich
39
+ Requires-Dist: scikit-learn
40
+ Requires-Dist: sentencepiece
41
+ Requires-Dist: seqeval
42
+ Requires-Dist: spacy
43
+ Requires-Dist: tqdm
44
+ Requires-Dist: transformers==4.49.0
45
+ Requires-Dist: wandb
46
+ Provides-Extra: dev
47
+ Requires-Dist: pytest; extra == 'dev'
48
+ Requires-Dist: ruff; extra == 'dev'
49
+ Description-Content-Type: text/markdown
50
+
51
+ # micm-nlp
52
+
53
+ [![PyPI](https://img.shields.io/pypi/v/micm-nlp.svg)](https://pypi.org/project/micm-nlp/)
54
+ [![Python](https://img.shields.io/pypi/pyversions/micm-nlp.svg)](https://pypi.org/project/micm-nlp/)
55
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
56
+
57
+ NLP research toolkit for tokenization, pretraining, fine-tuning, and PEFT across encoder-only, decoder-only, and encoder-decoder architectures. Built on top of HuggingFace `transformers`, `peft`, and `datasets`.
58
+
59
+ ## About
60
+
61
+ `micm-nlp` is a config-driven research toolkit for multilingual NLP work. It wraps the HuggingFace stack with a small set of high-level building blocks — `CONFIG`, `TOKENIZER`, `DATASET`, `MODEL`, and a unified `TRAINER` — that compose into reproducible training, fine-tuning, and evaluation pipelines.
62
+ The toolkit was used in the *Cross-Prompt Encoder for Low-Performing Languages* paper (Findings of IJCNLP–AACL 2025; [ACL Anthology](https://aclanthology.org/2025.findings-ijcnlp.144/)) and in *A Comparison of Different Tokenization Methods for the Georgian Language* (ICNLSP 2024; [ACL Anthology](https://aclanthology.org/2024.icnlsp-1.22/))
63
+
64
+ This v0.1.0 release ships **two examples** that exercise a single use case end-to-end: preprocessing and decoder-only PEFT fine-tuning (XPE) on an FTP-reframed multilingual dataset hosted on the HuggingFace Hub. The toolkit's underlying surface is broader than these two examples demonstrate.
65
+
66
+ Additional examples covering encoder-only text classification, encoder-decoder seq2seq, and MLM pretraining will land in subsequent releases. Contributions and issue reports are welcome.
67
+
68
+ ## Install
69
+
70
+ From PyPI:
71
+
72
+ ```bash
73
+ pip install micm-nlp
74
+ ```
75
+
76
+ From source (development):
77
+
78
+ ```bash
79
+ git clone https://github.com/bmikaberidze/micm-nlp.git
80
+ cd micm-nlp
81
+ pip install -e ".[dev]"
82
+ ```
83
+
84
+ Docker (recommended for reproducibility on GPU machines):
85
+
86
+ ```bash
87
+ docker build -t micm-nlp .
88
+ docker run --gpus all -it --rm -v $(pwd):/app -w /app micm-nlp bash
89
+ ```
90
+
91
+ You will also want a `.env` file for HuggingFace and Weights & Biases credentials:
92
+
93
+ ```bash
94
+ cp .env.example .env
95
+ # Then add WANDB_API_KEY and (if needed) HF_TOKEN.
96
+ ```
97
+
98
+ ## Quickstart
99
+
100
+ ```python
101
+ import micm_nlp
102
+ from micm_nlp.config import CONFIG
103
+ from micm_nlp.pipeline import run
104
+
105
+ micm_nlp.init() # Rich pretty-printing + traceback formatting
106
+
107
+ config = CONFIG.from_yaml("examples/configs/xsc_finetune.yml")
108
+ model, test_output = run(config)
109
+ ```
110
+
111
+ `run(config)` chains: load tokenizer → load and preprocess dataset → load model (with PEFT if configured) → train → evaluate. Every stage is configured by YAML; no plumbing code required.
112
+
113
+ ## Package tour
114
+
115
+ ```
116
+ micm_nlp/
117
+ ├── pipeline.py # Top-level wiring: load_dataset, preprocess_dataset, load_model, run
118
+ ├── config.py # CONFIG.from_yaml; resolves nested namespaces
119
+ ├── tokenizers/ # Tokenizer factory (XLM-R, BERT, BLOOM, T5, ...)
120
+ ├── datasets/ # DATASET class — local + HF Hub + HF saved + CSV/TXT/JSON
121
+ ├── models/ # MODEL wrapper, PEFT dispatch, XPE module, training callbacks
122
+ ├── training/ # TRAINER — wraps HF Trainer with custom callbacks + WandB
123
+ └── evals/ # Metrics, confusion matrices, plotting helpers
124
+ ```
125
+
126
+ The five-stage flow:
127
+
128
+ ```python
129
+ from micm_nlp.config import CONFIG
130
+ from micm_nlp.tokenizers.tokenizer import load as load_tokenizer
131
+ from micm_nlp.datasets.dataset import DATASET
132
+ from micm_nlp.models.model import MODEL
133
+ from micm_nlp.training.runner import TRAINER
134
+
135
+ config = CONFIG.from_yaml("path/to/config.yml")
136
+ tokenizer = load_tokenizer(config)
137
+ dataset = DATASET(config)
138
+ dataset.preprocess(tokenizer)
139
+ model = MODEL(config)
140
+ trainer = TRAINER(model, dataset, tokenizer)
141
+ test_output = trainer.run()
142
+ ```
143
+
144
+ ## Examples
145
+
146
+ | Example | Config | Description |
147
+ |---|---|---|
148
+ | `examples/preprocess_dataset.py` | `examples/configs/xsc_preprocess.yml` | Loads FTP-reframed XStoryCloze (English split) directly from the HuggingFace Hub and tokenizes it for BLOOM-560M; saves tokenized output locally. |
149
+ | `examples/run_model.py` | `examples/configs/xsc_finetune.yml` | Fine-tunes BLOOM-560M with XPE PEFT on the Arabic split of FTP-reframed XStoryCloze, then evaluates. |
150
+
151
+ More examples — encoder-only text classification, encoder-decoder seq2seq, MLM pretraining, additional PEFT methods (LoRA, Prefix, P-Tuning) — are planned for subsequent releases.
152
+
153
+ ## Supported architectures
154
+
155
+ | Architecture | Toolkit support | Demonstrated by example in v0.1.0 |
156
+ |---|---|---|
157
+ | Decoder-only (BLOOM, AYA) | ✅ | ✅ |
158
+ | Encoder-only (BERT, XLM-R) | ✅ | ⏳ planned |
159
+ | Encoder-decoder (T5) | ✅ | ⏳ planned |
160
+
161
+ PEFT methods supported by the toolkit: LoRA, Prefix Tuning, P-Tuning (SPT), Cross-Prompt Encoder (XPE). v0.1.0 examples demonstrate XPE only.
162
+
163
+ ## Development
164
+
165
+ ```bash
166
+ pip install -e ".[dev]"
167
+ ruff check src/
168
+ ruff format src/
169
+ pytest
170
+ ```
171
+
172
+ ## Contributing
173
+
174
+ Pull requests are welcome. For non-trivial changes, please open an issue first to discuss the proposed change. A `CONTRIBUTORS.md` will be added with the first external contribution.
175
+
176
+ ## Acknowledgements
177
+
178
+ `micm-nlp` was developed at the Muskhelishvili Institute of Computational Mathematics (MICM, Georgian Technical University), in close research collaboration with Teimuraz Saghinadze (MICM), Simon Ostermann (DFKI / CERTAIN), and Philipp Müller (Max Planck Institute for Intelligent Systems), whose joint work on the Cross-Prompt Encoder (XPE) drove much of the toolkit's design and validation.
179
+
180
+ This work was partially supported by the European Union under Horizon Europe project "GAIN" (GA #101078950) and by the German Federal Ministry of Research, Technology and Space (BMFTR) as part of the project TRAILS (01IW24005).
181
+
182
+ ## Citation
183
+
184
+ If you use `micm-nlp` in your research, please cite the package and (if relevant to your work) the XPE paper that drove its design:
185
+
186
+ ```bibtex
187
+ @software{micm_nlp,
188
+ author = {Mikaberidze, Beso},
189
+ title = {micm-nlp: NLP research toolkit for multilingual fine-tuning and PEFT},
190
+ url = {https://github.com/bmikaberidze/micm-nlp},
191
+ version = {0.1.0},
192
+ year = {2026},
193
+ }
194
+
195
+ @misc{mikaberidze2025crosspromptencoderlowperforminglanguages,
196
+ title = {Cross-Prompt Encoder for Low-Performing Languages},
197
+ author = {Beso Mikaberidze and Teimuraz Saghinadze and Simon Ostermann and Philipp Muller},
198
+ year = {2026},
199
+ eprint = {2508.10352},
200
+ archivePrefix = {arXiv},
201
+ primaryClass = {cs.CL},
202
+ url = {https://arxiv.org/abs/2508.10352},
203
+ }
204
+ ```
205
+
206
+ ## Contact
207
+
208
+ `beso.mikaberidze@gmail.com`
@@ -0,0 +1,158 @@
1
+ # micm-nlp
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/micm-nlp.svg)](https://pypi.org/project/micm-nlp/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/micm-nlp.svg)](https://pypi.org/project/micm-nlp/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ NLP research toolkit for tokenization, pretraining, fine-tuning, and PEFT across encoder-only, decoder-only, and encoder-decoder architectures. Built on top of HuggingFace `transformers`, `peft`, and `datasets`.
8
+
9
+ ## About
10
+
11
+ `micm-nlp` is a config-driven research toolkit for multilingual NLP work. It wraps the HuggingFace stack with a small set of high-level building blocks — `CONFIG`, `TOKENIZER`, `DATASET`, `MODEL`, and a unified `TRAINER` — that compose into reproducible training, fine-tuning, and evaluation pipelines.
12
+ The toolkit was used in the *Cross-Prompt Encoder for Low-Performing Languages* paper (Findings of IJCNLP–AACL 2025; [ACL Anthology](https://aclanthology.org/2025.findings-ijcnlp.144/)) and in *A Comparison of Different Tokenization Methods for the Georgian Language* (ICNLSP 2024; [ACL Anthology](https://aclanthology.org/2024.icnlsp-1.22/))
13
+
14
+ This v0.1.0 release ships **two examples** that exercise a single use case end-to-end: preprocessing and decoder-only PEFT fine-tuning (XPE) on an FTP-reframed multilingual dataset hosted on the HuggingFace Hub. The toolkit's underlying surface is broader than these two examples demonstrate.
15
+
16
+ Additional examples covering encoder-only text classification, encoder-decoder seq2seq, and MLM pretraining will land in subsequent releases. Contributions and issue reports are welcome.
17
+
18
+ ## Install
19
+
20
+ From PyPI:
21
+
22
+ ```bash
23
+ pip install micm-nlp
24
+ ```
25
+
26
+ From source (development):
27
+
28
+ ```bash
29
+ git clone https://github.com/bmikaberidze/micm-nlp.git
30
+ cd micm-nlp
31
+ pip install -e ".[dev]"
32
+ ```
33
+
34
+ Docker (recommended for reproducibility on GPU machines):
35
+
36
+ ```bash
37
+ docker build -t micm-nlp .
38
+ docker run --gpus all -it --rm -v $(pwd):/app -w /app micm-nlp bash
39
+ ```
40
+
41
+ You will also want a `.env` file for HuggingFace and Weights & Biases credentials:
42
+
43
+ ```bash
44
+ cp .env.example .env
45
+ # Then add WANDB_API_KEY and (if needed) HF_TOKEN.
46
+ ```
47
+
48
+ ## Quickstart
49
+
50
+ ```python
51
+ import micm_nlp
52
+ from micm_nlp.config import CONFIG
53
+ from micm_nlp.pipeline import run
54
+
55
+ micm_nlp.init() # Rich pretty-printing + traceback formatting
56
+
57
+ config = CONFIG.from_yaml("examples/configs/xsc_finetune.yml")
58
+ model, test_output = run(config)
59
+ ```
60
+
61
+ `run(config)` chains: load tokenizer → load and preprocess dataset → load model (with PEFT if configured) → train → evaluate. Every stage is configured by YAML; no plumbing code required.
62
+
63
+ ## Package tour
64
+
65
+ ```
66
+ micm_nlp/
67
+ ├── pipeline.py # Top-level wiring: load_dataset, preprocess_dataset, load_model, run
68
+ ├── config.py # CONFIG.from_yaml; resolves nested namespaces
69
+ ├── tokenizers/ # Tokenizer factory (XLM-R, BERT, BLOOM, T5, ...)
70
+ ├── datasets/ # DATASET class — local + HF Hub + HF saved + CSV/TXT/JSON
71
+ ├── models/ # MODEL wrapper, PEFT dispatch, XPE module, training callbacks
72
+ ├── training/ # TRAINER — wraps HF Trainer with custom callbacks + WandB
73
+ └── evals/ # Metrics, confusion matrices, plotting helpers
74
+ ```
75
+
76
+ The five-stage flow:
77
+
78
+ ```python
79
+ from micm_nlp.config import CONFIG
80
+ from micm_nlp.tokenizers.tokenizer import load as load_tokenizer
81
+ from micm_nlp.datasets.dataset import DATASET
82
+ from micm_nlp.models.model import MODEL
83
+ from micm_nlp.training.runner import TRAINER
84
+
85
+ config = CONFIG.from_yaml("path/to/config.yml")
86
+ tokenizer = load_tokenizer(config)
87
+ dataset = DATASET(config)
88
+ dataset.preprocess(tokenizer)
89
+ model = MODEL(config)
90
+ trainer = TRAINER(model, dataset, tokenizer)
91
+ test_output = trainer.run()
92
+ ```
93
+
94
+ ## Examples
95
+
96
+ | Example | Config | Description |
97
+ |---|---|---|
98
+ | `examples/preprocess_dataset.py` | `examples/configs/xsc_preprocess.yml` | Loads FTP-reframed XStoryCloze (English split) directly from the HuggingFace Hub and tokenizes it for BLOOM-560M; saves tokenized output locally. |
99
+ | `examples/run_model.py` | `examples/configs/xsc_finetune.yml` | Fine-tunes BLOOM-560M with XPE PEFT on the Arabic split of FTP-reframed XStoryCloze, then evaluates. |
100
+
101
+ More examples — encoder-only text classification, encoder-decoder seq2seq, MLM pretraining, additional PEFT methods (LoRA, Prefix, P-Tuning) — are planned for subsequent releases.
102
+
103
+ ## Supported architectures
104
+
105
+ | Architecture | Toolkit support | Demonstrated by example in v0.1.0 |
106
+ |---|---|---|
107
+ | Decoder-only (BLOOM, AYA) | ✅ | ✅ |
108
+ | Encoder-only (BERT, XLM-R) | ✅ | ⏳ planned |
109
+ | Encoder-decoder (T5) | ✅ | ⏳ planned |
110
+
111
+ PEFT methods supported by the toolkit: LoRA, Prefix Tuning, P-Tuning (SPT), Cross-Prompt Encoder (XPE). v0.1.0 examples demonstrate XPE only.
112
+
113
+ ## Development
114
+
115
+ ```bash
116
+ pip install -e ".[dev]"
117
+ ruff check src/
118
+ ruff format src/
119
+ pytest
120
+ ```
121
+
122
+ ## Contributing
123
+
124
+ Pull requests are welcome. For non-trivial changes, please open an issue first to discuss the proposed change. A `CONTRIBUTORS.md` will be added with the first external contribution.
125
+
126
+ ## Acknowledgements
127
+
128
+ `micm-nlp` was developed at the Muskhelishvili Institute of Computational Mathematics (MICM, Georgian Technical University), in close research collaboration with Teimuraz Saghinadze (MICM), Simon Ostermann (DFKI / CERTAIN), and Philipp Müller (Max Planck Institute for Intelligent Systems), whose joint work on the Cross-Prompt Encoder (XPE) drove much of the toolkit's design and validation.
129
+
130
+ This work was partially supported by the European Union under Horizon Europe project "GAIN" (GA #101078950) and by the German Federal Ministry of Research, Technology and Space (BMFTR) as part of the project TRAILS (01IW24005).
131
+
132
+ ## Citation
133
+
134
+ If you use `micm-nlp` in your research, please cite the package and (if relevant to your work) the XPE paper that drove its design:
135
+
136
+ ```bibtex
137
+ @software{micm_nlp,
138
+ author = {Mikaberidze, Beso},
139
+ title = {micm-nlp: NLP research toolkit for multilingual fine-tuning and PEFT},
140
+ url = {https://github.com/bmikaberidze/micm-nlp},
141
+ version = {0.1.0},
142
+ year = {2026},
143
+ }
144
+
145
+ @misc{mikaberidze2025crosspromptencoderlowperforminglanguages,
146
+ title = {Cross-Prompt Encoder for Low-Performing Languages},
147
+ author = {Beso Mikaberidze and Teimuraz Saghinadze and Simon Ostermann and Philipp Muller},
148
+ year = {2026},
149
+ eprint = {2508.10352},
150
+ archivePrefix = {arXiv},
151
+ primaryClass = {cs.CL},
152
+ url = {https://arxiv.org/abs/2508.10352},
153
+ }
154
+ ```
155
+
156
+ ## Contact
157
+
158
+ `beso.mikaberidze@gmail.com`
@@ -0,0 +1,25 @@
1
+ # nvidia-smi
2
+ # nvidia-container-toolkit --version
3
+ FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-devel
4
+
5
+ # Create working directory
6
+ ENV WORKDIR=/app
7
+ WORKDIR ${WORKDIR}
8
+
9
+ # Install system packages (git needed for GitPython; strace for debugging)
10
+ RUN apt-get update -y && \
11
+ apt-get install -y --no-install-recommends \
12
+ git \
13
+ strace \
14
+ apt-transport-https \
15
+ ca-certificates && \
16
+ apt-get clean && rm -rf /var/lib/apt/lists/*
17
+
18
+ # Install package
19
+ RUN pip install --upgrade pip
20
+ COPY pyproject.toml .
21
+ COPY src/ src/
22
+ RUN pip install -e ".[dev]"
23
+
24
+ # Check if CUDA is available:
25
+ CMD [ "/bin/bash", "-c", "python -c \"import torch; print(f'CUDA is available: {torch.cuda.is_available()}')\"" ]