radlab-data 0.0.4__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.
- radlab_data-0.0.4/.version +1 -0
- radlab_data-0.0.4/CHANGELOG.md +90 -0
- radlab_data-0.0.4/LICENSE +201 -0
- radlab_data-0.0.4/MANIFEST.in +10 -0
- radlab_data-0.0.4/PKG-INFO +290 -0
- radlab_data-0.0.4/README.md +232 -0
- radlab_data-0.0.4/pyproject.toml +84 -0
- radlab_data-0.0.4/radlab_data/__init__.py +9 -0
- radlab_data-0.0.4/radlab_data/datasets/__init__.py +0 -0
- radlab_data-0.0.4/radlab_data/datasets/dataset.py +509 -0
- radlab_data-0.0.4/radlab_data/datasets/dataset_loader.py +140 -0
- radlab_data-0.0.4/radlab_data/datasets/tokenization_handler.py +78 -0
- radlab_data-0.0.4/radlab_data/preprocessing/__init__.py +0 -0
- radlab_data-0.0.4/radlab_data/preprocessing/dataset.py +726 -0
- radlab_data-0.0.4/radlab_data/preprocessing/pipeline.py +38 -0
- radlab_data-0.0.4/radlab_data/preprocessing/pipeline_modules.py +342 -0
- radlab_data-0.0.4/radlab_data/text/__init__.py +0 -0
- radlab_data-0.0.4/radlab_data/text/document.py +136 -0
- radlab_data-0.0.4/radlab_data/text/loaders/__init__.py +0 -0
- radlab_data-0.0.4/radlab_data/text/loaders/base.py +65 -0
- radlab_data-0.0.4/radlab_data/text/loaders/config.py +4 -0
- radlab_data-0.0.4/radlab_data/text/loaders/docx.py +96 -0
- radlab_data-0.0.4/radlab_data/text/loaders/html.py +111 -0
- radlab_data-0.0.4/radlab_data/text/loaders/input_txt.py +30 -0
- radlab_data-0.0.4/radlab_data/text/loaders/loader_i.py +267 -0
- radlab_data-0.0.4/radlab_data/text/loaders/markdown.py +129 -0
- radlab_data-0.0.4/radlab_data/text/loaders/pdf.py +157 -0
- radlab_data-0.0.4/radlab_data/text/loaders/txt.py +44 -0
- radlab_data-0.0.4/radlab_data/text/pair_reader.py +241 -0
- radlab_data-0.0.4/radlab_data/text/processors/__init__.py +0 -0
- radlab_data-0.0.4/radlab_data/text/processors/base.py +23 -0
- radlab_data-0.0.4/radlab_data/text/processors/cleaner.py +338 -0
- radlab_data-0.0.4/radlab_data/text/processors/mappers.py +167 -0
- radlab_data-0.0.4/radlab_data/text/processors/regex_defs.py +58 -0
- radlab_data-0.0.4/radlab_data/text/processors/splitter.py +60 -0
- radlab_data-0.0.4/radlab_data/text/reader.py +198 -0
- radlab_data-0.0.4/radlab_data/text/utils.py +51 -0
- radlab_data-0.0.4/radlab_data/utils/__init__.py +0 -0
- radlab_data-0.0.4/radlab_data/utils/api_handler.py +83 -0
- radlab_data-0.0.4/radlab_data/utils/argument_parser.py +241 -0
- radlab_data-0.0.4/radlab_data/utils/hf_training_arguments.py +95 -0
- radlab_data-0.0.4/radlab_data/utils/metrics.py +43 -0
- radlab_data-0.0.4/radlab_data/utils/special_tokens_rules.py +330 -0
- radlab_data-0.0.4/radlab_data/utils/threads.py +61 -0
- radlab_data-0.0.4/radlab_data.egg-info/PKG-INFO +290 -0
- radlab_data-0.0.4/radlab_data.egg-info/SOURCES.txt +49 -0
- radlab_data-0.0.4/radlab_data.egg-info/dependency_links.txt +1 -0
- radlab_data-0.0.4/radlab_data.egg-info/requires.txt +39 -0
- radlab_data-0.0.4/radlab_data.egg-info/top_level.txt +1 -0
- radlab_data-0.0.4/requirements.txt +32 -0
- radlab_data-0.0.4/setup.cfg +4 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.4
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file. The format
|
|
4
|
+
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the
|
|
5
|
+
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
The released versions below are the git tags; everything that happened after
|
|
8
|
+
the last tag is the unreleased or current version. The `0.1.0` and `0.1.1`
|
|
9
|
+
numbers that appeared in `setup.py` along the way were never tagged and are
|
|
10
|
+
folded into `0.0.4`.
|
|
11
|
+
|
|
12
|
+
## [0.0.4] - 2026-11-22
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- LangChain is no longer a dependency. Loaders read documents directly:
|
|
17
|
+
`pypdf` for PDF, BeautifulSoup for HTML, `python-docx` for DOCX, and plain
|
|
18
|
+
file reading with encoding autodetection for TXT and Markdown.
|
|
19
|
+
- Every loader returns `DocumentPage` objects (`page_content` plus a
|
|
20
|
+
`metadata` dictionary), also for DOCX and input text, so no
|
|
21
|
+
document-loading framework is needed to use the library.
|
|
22
|
+
- Heavy dependencies are optional. `transformers`, `torch`, `datasets`,
|
|
23
|
+
`numpy`, `scikit-learn`, `scipy`, `matplotlib`, `spacy`,
|
|
24
|
+
`fasttext-langdetect`, `deepl`, `pandas` and `openpyxl` moved to the `ml`,
|
|
25
|
+
`spacy`, `lang` and `tables` extras (and `all`). The core installs `tqdm`,
|
|
26
|
+
`requests`, `beautifulsoup4`, `python-docx` and `pypdf` only.
|
|
27
|
+
- Heavy imports are lazy: `transformers` inside
|
|
28
|
+
`radlab_data.text.loaders.loader_i.get_tokenizer()` (first use of token
|
|
29
|
+
chunking), `spacy` inside `radlab_data.text.processors.splitter.get_nlp()`,
|
|
30
|
+
and `ftlangdetect` / `deepl` inside the `TextUtils` methods which use them.
|
|
31
|
+
Importing `Document`, `DirectoryFileReader`, the loaders or `TextUtils` no
|
|
32
|
+
longer pulls in the model stack.
|
|
33
|
+
- Packaging moved from `setup.py` to `pyproject.toml` (PEP 621), which also
|
|
34
|
+
fixes built distributions missing the top-level `radlab_data` package. The
|
|
35
|
+
distribution is named `radlab-data` (the import name stays `radlab_data`)
|
|
36
|
+
and its version is read from a `.version` file.
|
|
37
|
+
- `MANIFEST.in` controls the sdist contents: README, CHANGELOG, LICENSE,
|
|
38
|
+
`requirements.txt`, `pyproject.toml` and `.version` are included, `tests`
|
|
39
|
+
and build artefacts are excluded.
|
|
40
|
+
- `requirements.txt` is split into core, extras and a dev/packaging section,
|
|
41
|
+
and `Levenshtein` is gone.
|
|
42
|
+
- HF training arguments use `eval_strategy` instead of the deprecated
|
|
43
|
+
`evaluation_strategy`.
|
|
44
|
+
- Declared `python_requires=">=3.10"`.
|
|
45
|
+
|
|
46
|
+
### Added
|
|
47
|
+
|
|
48
|
+
- A `DocumentPage` model and text file reading helpers.
|
|
49
|
+
- `html` in the supported file extensions of the loader config.
|
|
50
|
+
- A test suite for the loaders, readers, datasets, preprocessing pipeline and
|
|
51
|
+
utilities, including a test that imports the document core in a subprocess
|
|
52
|
+
where `torch`, `transformers` and `spacy` raise `ImportError`.
|
|
53
|
+
- `pytest` as a development dependency, and packaging tests that keep
|
|
54
|
+
`requirements.txt`, `.version` and `MANIFEST.in` consistent with
|
|
55
|
+
`pyproject.toml`.
|
|
56
|
+
- Classifiers, a `Homepage` URL and a README rendered on PyPI.
|
|
57
|
+
|
|
58
|
+
### Fixed
|
|
59
|
+
|
|
60
|
+
- Loaders crashing when no `options` are given.
|
|
61
|
+
- Loader state mutation and directory reading issues.
|
|
62
|
+
- Document pairs and preprocessing dataset loading.
|
|
63
|
+
- Dataset loading and pipeline element edge cases.
|
|
64
|
+
- Errors in `radlab_data.utils`; the spaCy model now loads lazily.
|
|
65
|
+
- The label histogram with an empty list of labels.
|
|
66
|
+
- `tests/test_loaders.py::test_get_tokenizer_is_cached` patches
|
|
67
|
+
`transformers.AutoTokenizer` instead of the module-level name which no
|
|
68
|
+
longer exists in `loader_i`.
|
|
69
|
+
|
|
70
|
+
## [0.0.3] - 2026-10-14
|
|
71
|
+
|
|
72
|
+
### Added
|
|
73
|
+
|
|
74
|
+
- Markdown support: a `MarkdownLoader` (with an optional `strip_markdown`
|
|
75
|
+
option) and README updates.
|
|
76
|
+
|
|
77
|
+
## [0.0.2] - 2026-10-14
|
|
78
|
+
|
|
79
|
+
The state captured by the first tag.
|
|
80
|
+
|
|
81
|
+
### Added
|
|
82
|
+
|
|
83
|
+
- Text loading framework: the `LoaderI` base class, the PDF, TXT, DOCX and
|
|
84
|
+
input-text loaders, and the loader configuration.
|
|
85
|
+
- Text processing utilities: cleaner, splitter and mappers, plus regex
|
|
86
|
+
definitions.
|
|
87
|
+
- HTML loading and cleaning.
|
|
88
|
+
- Dataset classes for classification, sequence labelling and sequence to
|
|
89
|
+
sequence tasks, the preprocessing pipeline and the training utilities.
|
|
90
|
+
- Apache 2.0 license.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: radlab-data
|
|
3
|
+
Version: 0.0.4
|
|
4
|
+
Summary: Text processing and modelling
|
|
5
|
+
Author-email: RadLab <hello@radlab.dev>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://radlab.dev
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Classifier: Topic :: Text Processing
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: tqdm
|
|
24
|
+
Requires-Dist: requests
|
|
25
|
+
Requires-Dist: beautifulsoup4
|
|
26
|
+
Requires-Dist: python-docx
|
|
27
|
+
Requires-Dist: pypdf
|
|
28
|
+
Provides-Extra: ml
|
|
29
|
+
Requires-Dist: transformers; extra == "ml"
|
|
30
|
+
Requires-Dist: torch; extra == "ml"
|
|
31
|
+
Requires-Dist: datasets; extra == "ml"
|
|
32
|
+
Requires-Dist: numpy; extra == "ml"
|
|
33
|
+
Requires-Dist: scikit-learn; extra == "ml"
|
|
34
|
+
Requires-Dist: scipy; extra == "ml"
|
|
35
|
+
Requires-Dist: matplotlib; extra == "ml"
|
|
36
|
+
Provides-Extra: spacy
|
|
37
|
+
Requires-Dist: spacy; extra == "spacy"
|
|
38
|
+
Provides-Extra: lang
|
|
39
|
+
Requires-Dist: fasttext-langdetect; extra == "lang"
|
|
40
|
+
Requires-Dist: deepl; extra == "lang"
|
|
41
|
+
Provides-Extra: tables
|
|
42
|
+
Requires-Dist: pandas; extra == "tables"
|
|
43
|
+
Requires-Dist: openpyxl; extra == "tables"
|
|
44
|
+
Provides-Extra: all
|
|
45
|
+
Requires-Dist: transformers; extra == "all"
|
|
46
|
+
Requires-Dist: torch; extra == "all"
|
|
47
|
+
Requires-Dist: datasets; extra == "all"
|
|
48
|
+
Requires-Dist: numpy; extra == "all"
|
|
49
|
+
Requires-Dist: scikit-learn; extra == "all"
|
|
50
|
+
Requires-Dist: scipy; extra == "all"
|
|
51
|
+
Requires-Dist: matplotlib; extra == "all"
|
|
52
|
+
Requires-Dist: spacy; extra == "all"
|
|
53
|
+
Requires-Dist: fasttext-langdetect; extra == "all"
|
|
54
|
+
Requires-Dist: deepl; extra == "all"
|
|
55
|
+
Requires-Dist: pandas; extra == "all"
|
|
56
|
+
Requires-Dist: openpyxl; extra == "all"
|
|
57
|
+
Dynamic: license-file
|
|
58
|
+
|
|
59
|
+
# radlab‑data
|
|
60
|
+
|
|
61
|
+
A versatile Python library for loading, preprocessing, and handling a variety of textual data sources (PDF, DOCX, TXT, MD, HTML,
|
|
62
|
+
and raw strings) and preparing them for downstream machine‑learning tasks such as classification, sequence labeling, and
|
|
63
|
+
generative modeling.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Table of Contents
|
|
68
|
+
|
|
69
|
+
- [Overview](#overview)
|
|
70
|
+
- [Features](#features)
|
|
71
|
+
- [Installation](#installation)
|
|
72
|
+
- [Quick Start](#quick-start)
|
|
73
|
+
- [Core Concepts](#core-concepts)
|
|
74
|
+
- [Dataset Types](#dataset-types)
|
|
75
|
+
- [Text Loaders](#text-loaders)
|
|
76
|
+
- [Processing Pipeline](#processing-pipeline)
|
|
77
|
+
- [Command‑Line Utilities](#command-line-utilities)
|
|
78
|
+
- [Configuration](#configuration)
|
|
79
|
+
- [License](#license)
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Overview
|
|
84
|
+
|
|
85
|
+
`radlab-data` provides a unified interface for:
|
|
86
|
+
|
|
87
|
+
1. **Reading documents** from common file formats (PDF, DOCX, TXT, MD, HTML) as well as plain‑text strings.
|
|
88
|
+
2. **Cleaning and normalising** raw text using a chain of configurable processors.
|
|
89
|
+
3. **Splitting** text into sentences, paragraphs, or token‑level chunks.
|
|
90
|
+
4. **Mapping** raw annotations (e.g., NER spans) onto tokenised representations.
|
|
91
|
+
5. **Packaging** data into HuggingFace `datasets.Dataset` objects, ready for training with `transformers`.
|
|
92
|
+
|
|
93
|
+
The library is built with extensibility in mind – you can plug in your own tokenizers, preprocessing steps, or custom
|
|
94
|
+
dataset classes.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Features
|
|
99
|
+
|
|
100
|
+
- **Multi‑format document loading** – PDF, DOCX, TXT, MD, HTML, and custom “input_text”.
|
|
101
|
+
- **Automatic language detection** (via `ftlangdetect`).
|
|
102
|
+
- **Flexible text cleaning** – phrase removal, abbreviation normalisation, regex‑based sanitisation, etc.
|
|
103
|
+
- **Sentence‑level splitting** using spaCy’s Polish model (`pl_core_news_lg`).
|
|
104
|
+
- **Special token handling** – conditional insertion of tokens based on metadata rules.
|
|
105
|
+
- **Dataset abstractions** for:
|
|
106
|
+
- Text classification
|
|
107
|
+
- Sequence labeling (NER, IOB tagging)
|
|
108
|
+
- Sequence‑to‑sequence tasks (e.g., translation, summarisation)
|
|
109
|
+
- Semantic similarity and dialogue alternatives
|
|
110
|
+
- **Caching** of tokenised datasets for fast reloads.
|
|
111
|
+
- **Multiprocessing support** for loading large corpora.
|
|
112
|
+
- **Command‑line tools** for dataset conversion, preprocessing, and training argument handling.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Installation
|
|
117
|
+
|
|
118
|
+
```shell script
|
|
119
|
+
# Create a virtual environment (optional but recommended)
|
|
120
|
+
python -m venv .venv
|
|
121
|
+
source .venv/bin/activate # on Windows: .venv\Scripts\activate
|
|
122
|
+
|
|
123
|
+
# Core only: document loading, cleaning and small utilities
|
|
124
|
+
pip install -e .
|
|
125
|
+
|
|
126
|
+
# Everything, including the model stack
|
|
127
|
+
pip install -e ".[all]"
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
> **Note**: The library requires Python 3.10+.
|
|
131
|
+
|
|
132
|
+
### Dependency extras
|
|
133
|
+
|
|
134
|
+
The core installs only the light packages needed to read and clean documents
|
|
135
|
+
(`tqdm`, `requests`, `beautifulsoup4`, `python-docx`, `pypdf`). Importing the
|
|
136
|
+
document loaders, `Document`, `DirectoryFileReader` or `TextUtils` therefore
|
|
137
|
+
does **not** pull in `torch`, `transformers` or `spacy` — a query-only host
|
|
138
|
+
(for example the [Semantic Search Engine](https://dev.radlab.pl/semantic-search-engine) API)
|
|
139
|
+
can install the core alone.
|
|
140
|
+
|
|
141
|
+
| Extra | Installs | Needed for |
|
|
142
|
+
|------------|-------------------------------------------------------------------|------------------------------------------------------------------|
|
|
143
|
+
| `ml` | `transformers`, `torch`, `datasets`, `numpy`, `scikit-learn`, `scipy`, `matplotlib` | token-level chunking (`max_tokens_in_chunk`), HF datasets, metrics and training helpers |
|
|
144
|
+
| `spacy` | `spacy` | `SentenceSplitter` and `PairReader` (Polish model: `python -m spacy download pl_core_news_lg`) |
|
|
145
|
+
| `lang` | `fasttext-langdetect`, `deepl` | `TextUtils.text_language`, `TextUtils.translate_text_deepl` |
|
|
146
|
+
| `tables` | `pandas`, `openpyxl` | dataset preprocessing and spreadsheet input |
|
|
147
|
+
| `all` | all of the above | the full feature set |
|
|
148
|
+
|
|
149
|
+
Heavy imports are lazy: `transformers` is imported inside
|
|
150
|
+
`radlab_data.text.loaders.loader_i.get_tokenizer()` (so inside the first use of
|
|
151
|
+
token chunking), `spacy` inside
|
|
152
|
+
`radlab_data.text.processors.splitter.get_nlp()`, and `ftlangdetect`/`deepl`
|
|
153
|
+
inside the `TextUtils` methods which use them. `requirements.txt` lists every
|
|
154
|
+
extra for a full development environment.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Quick Start
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from radlab_data.text.document import Document
|
|
162
|
+
from radlab_data.datasets.dataset_loader import DatasetLoader
|
|
163
|
+
from transformers import AutoTokenizer
|
|
164
|
+
|
|
165
|
+
# 1️⃣ Load a document (PDF, DOCX, TXT, MD, HTML, or raw text)
|
|
166
|
+
doc = Document(
|
|
167
|
+
file_path="data/example.pdf",
|
|
168
|
+
prepare_proper_pages=True,
|
|
169
|
+
clear_texts=True,
|
|
170
|
+
use_text_denoiser=False,
|
|
171
|
+
)
|
|
172
|
+
pages = doc.load() # pages is a list of `DocumentPage` objects
|
|
173
|
+
|
|
174
|
+
# 2️⃣ Initialise a tokenizer
|
|
175
|
+
tokenizer = AutoTokenizer.from_pretrained("radlab/polish-fast-tokenizer")
|
|
176
|
+
|
|
177
|
+
# 3️⃣ Load a dataset (JSON or JSONL) and automatically cache tokenisation
|
|
178
|
+
loader = DatasetLoader(
|
|
179
|
+
dataset_path="data/my_dataset",
|
|
180
|
+
tokenizer=tokenizer,
|
|
181
|
+
split_train_valid_test="0.8:0.1", # 80 % train, 10 % validation, 10 % test
|
|
182
|
+
pre_shuffle=True,
|
|
183
|
+
)
|
|
184
|
+
dataset = loader.load()
|
|
185
|
+
|
|
186
|
+
# 4️⃣ Access train / validation / test splits
|
|
187
|
+
train = dataset.train_dataset
|
|
188
|
+
valid = dataset.valid_dataset
|
|
189
|
+
test = dataset.test_dataset
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The resulting `train`, `valid`, and `test` objects are HuggingFace `datasets.Dataset` instances, ready to be passed to a
|
|
193
|
+
`transformers` trainer.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Core Concepts
|
|
198
|
+
|
|
199
|
+
### Dataset Types
|
|
200
|
+
|
|
201
|
+
| Class | Typical Use‑Case | Key Characteristics |
|
|
202
|
+
|-------------------------------|-------------------------------------------------|-------------------------------------------------------------------|
|
|
203
|
+
| `TextClassificationDataset` | Single‑label classification | Stores `text` and a scalar `label`. |
|
|
204
|
+
| `SequenceLabellingDataset` | NER / token‑level tagging | Generates IOB tags aligned to tokenised inputs. |
|
|
205
|
+
| `SequenceToSequenceDataset` | Translation, summarisation, etc. | Handles source‑target pairs (`text` ↔ `label`). |
|
|
206
|
+
| `SemanticSimilarityDataset` | Pairwise similarity / ranking | Provides `sentence1`, `sentence2`, and a similarity `score`. |
|
|
207
|
+
| `DPODataset` | Preference‑based learning (chosen vs. rejected) | Keeps raw prompts and two possible completions. |
|
|
208
|
+
| `DialogueAlternativesDataset` | Multi‑choice dialogue generation | Stores a shared context and several possible endings with scores. |
|
|
209
|
+
|
|
210
|
+
All dataset classes inherit from `DatasetBaseClass`, which implements caching, optional shuffling, and split handling.
|
|
211
|
+
|
|
212
|
+
### Text Loaders
|
|
213
|
+
|
|
214
|
+
| Loader | Supported Extension | Behaviour |
|
|
215
|
+
|-------------------|---------------------|--------------------------------------------------------|
|
|
216
|
+
| `PDFLoader` | `.pdf` | One page per PDF page via `pypdf`. |
|
|
217
|
+
| `TXTLoader` | `.txt` | Whole file as one page, with encoding autodetection. |
|
|
218
|
+
| `MarkdownLoader` | `.md` | Reads like `TXTLoader`, optional markup stripping. |
|
|
219
|
+
| `DOCXLoader` | `.docx` | Parses paragraphs and tables via `python-docx`. |
|
|
220
|
+
| `HTMLLoader` | `.html` | Strips markup via BeautifulSoup, `split_by_paragraph`. |
|
|
221
|
+
| `InputTextLoader` | `.input_text` | Wraps a raw string supplied via options. |
|
|
222
|
+
|
|
223
|
+
Loaders share a common base (`LoaderI`) that handles:
|
|
224
|
+
|
|
225
|
+
- Tokeniser initialisation,
|
|
226
|
+
- Optional language detection,
|
|
227
|
+
- Text denoising,
|
|
228
|
+
- Chunking into token‑size windows.
|
|
229
|
+
|
|
230
|
+
Every loader returns `DocumentPage` objects (`page_content` plus a `metadata`
|
|
231
|
+
dictionary), so no document-loading framework is needed to use `radlab-data`.
|
|
232
|
+
|
|
233
|
+
Markdown files are read as plain text and every page is tagged with
|
|
234
|
+
`document_format: markdown`. Pass the `strip_markdown` option to remove markdown markup
|
|
235
|
+
(headings, emphasis, links, code fences, list markers) while keeping the underlying text:
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from radlab_data.text.loaders.markdown import MarkdownLoader
|
|
239
|
+
|
|
240
|
+
loader = MarkdownLoader("docs/README.md", options={"strip_markdown": True})
|
|
241
|
+
pages = loader.load()
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Processing Pipeline
|
|
245
|
+
|
|
246
|
+
`radlab-data` ships with a lightweight pipeline framework:
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
from radlab_data.preprocessing.pipeline import Pipeline
|
|
250
|
+
from radlab_data.preprocessing.pipeline_modules import SplitLabels, RemoveDuplicates
|
|
251
|
+
|
|
252
|
+
pipeline = Pipeline(modules=[
|
|
253
|
+
SplitLabels(),
|
|
254
|
+
RemoveDuplicates(),
|
|
255
|
+
# add your custom PipelineElementBase subclasses here
|
|
256
|
+
])
|
|
257
|
+
|
|
258
|
+
processed_dataset = pipeline(original_dataset)
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Each pipeline element inherits from `PipelineElementBase` and implements a `_process_data` method that receives a
|
|
262
|
+
dataset instance and returns the transformed instance. The framework automatically validates that the element supports
|
|
263
|
+
the dataset type.
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## Command‑Line Utilities
|
|
268
|
+
|
|
269
|
+
The package currently does not ship command‑line entry points; dataset
|
|
270
|
+
conversion and preprocessing are driven from Python through the classes
|
|
271
|
+
described above.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Configuration
|
|
276
|
+
|
|
277
|
+
All default settings live under `radlab_data/text/loaders/config.py`:
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
TOKENIZER_PATH = "radlab/polish-fast-tokenizer"
|
|
281
|
+
AVAILABLE_FILE_EXTENSIONS = ["txt", "md", "pdf", "docx", "html", "input_text"]
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
You can override these values at runtime by passing the appropriate arguments to `Document` or the loader classes.
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
`radlab-data` is released under the **Apache 2.0 License**. See the `LICENSE` file for full details.
|