Text preprocessing management system.
Project description
HojiChar
概要
HojiChar はテキストデータの前処理のためのPythonモジュールです. 言語モデル構築時などにコーパスを前処理する目的で開発されました。
hojichar.filters で定義された、あるいはユーザーが定義したテキスト前処理フィルタを束ね、ひとつの前処理パイプラインとして構成することができように作られています。
この前処理パイプラインは、torchvision.transforms に着想を得て開発されました。
使い方
インストール
pip install hojichar
Poetry によるローカルインストール
python >= 3.8, poetry >= 1.2
https://github.com/HojiChar/HojiChar.git
cd HojiChar
poetry install
Rocket start
Compose クラスを使ってフィルタを作成します.
from hojichar import Compose, document_filters
cleaner = Compose([
document_filters.JSONLoader(key="text"),
document_filters.AcceptJapanese(),
document_filters.DocumentLengthFilter(min_doc_len=0,max_doc_len=1000),
document_filters.ExampleHojiChar()
])
>>> cleaner('{"text": "こんにちは、"}')
'こんにちは、<hojichar>'
上記のフィルタでは 1. JSONから'text' キーの値を取得 2. 日本語文字列でなければ破棄, 3. 0字以上1000字以内の文章以外を破棄, 4. 文字列に <hojichar> を追加 の処理をしています.
定義済みのフィルタは、hojichar.filters の各フィルタです。
ユーザー定義フィルタ
Filter クラスを継承し, apply 関数内にフィルタの挙動を記述します.
from hojichar.core.filter_interface import Filter
class YourFilter(Filter):
def apply(self, document):
document.text = your_process(document.text)
return document
apply 関数は hojichar.core.models.Document 型を引数として受け取り,
返す関数です. Document は文字列をカプセル化したクラスです.
開発者向け
開発用のパッケージのインストールのために,
poetry install --with dev,lint,test
テスト
テスト実行
pytest --doctest-modules .
で mypy と pytest のテストが実行されます.
Lint
poetry run task lint
Format
poetry run task format
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hojichar-0.3.1.tar.gz.
File metadata
- Download URL: hojichar-0.3.1.tar.gz
- Upload date:
- Size: 32.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.9.16 Linux/5.15.0-1033-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
393a14e7545bcc2967e07f5785c8c22b88c0b9375ba53ab984a24b9d578b0182
|
|
| MD5 |
b903b2d4b77de7906bf1b85fd451d1e6
|
|
| BLAKE2b-256 |
1d9b3a36fc2cf2e4161b9a8b6b955e3243b3b092c30470f58c966b89d038b051
|
File details
Details for the file hojichar-0.3.1-py3-none-any.whl.
File metadata
- Download URL: hojichar-0.3.1-py3-none-any.whl
- Upload date:
- Size: 35.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.9.16 Linux/5.15.0-1033-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c782f4f422178258aad83fd333f915897632455588701e4926fb1a7be5fb51a2
|
|
| MD5 |
4f434fcc3df421a9e5bb270b894b2cde
|
|
| BLAKE2b-256 |
1c99573aaa55e2ea3d55c1432c5df7895d144ab8d162ffea9701bb9b520b52f3
|