ko_lm_dataformat
-
한국어 언어모델용 학습 데이터를 저장, 로딩하기 위한 유틸리티
-
코드는 EleutherAI에서 사용하는 lm_dataformat를 참고하여 제작
- 일부 버그 수정
- 한국어에 맞게 기능 추가 및 수정 (sentence splitter, text cleaner)
Installation
0.3.1 이후의 버전은 Python 3.9 이상을 지원합니다.
pip3 install ko_lm_dataformat
Usage
1. Write Data
1.1. Archive
- kss v1 sentence splitter 사용 가능
import ko_lm_dataformat as kldf
ar = kldf.Archive("output_dir")
ar = kldf.Archive("output_dir", sentence_splitter=kldf.KssV1SentenceSplitter()) # Use sentence splitter
1.2. Adding data
meta데이터를 추가할 수 있음 (e.g. 제목, url)- 하나의 document가 들어온다고 가정 (
str이 아닌List[str]로 들어오게 되면 여러 개의 sentence가 들어오는 걸로 취급) split_sent=True이면 document를 여러 개의 문장으로 분리하여List[str]으로 저장clean_sent=True이면 NFC Normalize, control char 제거, whitespace cleanup 적용
for doc in doc_lst:
ar.add_data(
data=doc,
meta={
"source": "kowiki",
"meta_key_1": [othermetadata, otherrandomstuff],
"meta_key_2": True
},
split_sent=False,
clean_sent=False,
)
# remember to commit at the end!
ar.commit()
2. Read Data
rdr.stream_data(get_meta=True)로 할 시(doc, meta)의 튜플 형태로 반환
import ko_lm_dataformat as kldf
rdr = kldf.Reader("output_dir")
for data in rdr.stream_data(get_meta=False):
print(data)
# "간단하게 설명하면, 언어를 통해 인간의 삶을 미적(美的)으로 형상화한 것이라고 볼...."
for data in rdr.stream_data(get_meta=True):
print(data)
# ("간단하게 설명하면, 언어를 통해 인간의 삶을 미적(美的)으로 형상화한 것이라고 볼....", {"source": "kowiki", ...})
Release files for ko-lm-dataformat 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ko_lm_dataformat-0.3.1.tar.gz | 9.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ko_lm_dataformat-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.3 kB
Release files / ko_lm_dataformat-0.3.1.tar.gz
| Download URL | ko_lm_dataformat-0.3.1.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd7561a93e8f1fe3ff58233d6f2101175cd0ad4f0d1da6c9533d9b61c28cdece
|
|
BLAKE2b-256 checksum How to use checksums |
9d4b57320348d4da80afef5c64a0f71d5babd28266ac92d1d8bdc77fbdbe3e96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2025.
Transparency logRelease files / ko_lm_dataformat-0.3.1-py3-none-any.whl
| Download URL | ko_lm_dataformat-0.3.1-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2717a2f30e105ef2628667f849516319996d94367959a22dab67af350cc120fd
|
|
BLAKE2b-256 checksum How to use checksums |
7e36acf6b2dbacfd920e80d934de7dc6eba3f7bdf00fbf09a0c1397ac25f95aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2025.
Transparency log