sumire
形態素解析器などの事前インストールなしで使える, CPUベースの日本語自然言語処理のための, Scikit-learn互換の日本語の単語分割器と, テキストのベクトル化ツール.
Table of Contents
Installation
pre-requirements
- Tested OS: ubuntu 22.04.
- python >=3.9
- make
- cmake
- git
# Jumanpp dependencies.
sudo apt update -y;
sudo apt install -y cmake libeigen3-dev libprotobuf-dev protobuf-c-compiler;
pip install sumireだけで, MeCabもJumanppも, インストールなしで使えます.
MeCabやJumanppの実行バイナリや各種辞書がなければ, $HOME/.local/sumire/にTokenizerをインスタンス化した時にインストールされます.
Usage
Tokenizer usage
from sumire.tokenizer import MecabTokenizer, JumanppTokenizer
text = "これはテスト文です。"
texts = ["これはテスト文です。", "別のテキストもトークン化します。"]
mecab = MecabTokenizer("unidic-lite")
text_mecab_tokenized = mecab.tokenize(text)
texts_mecab_tokenized = mecab.tokenize(texts)
jumanpp = JumanppTokenizer()
jumanpp.tokenize(text)
text_jumanpp_tokenized = jumanpp.tokenize(text)
texts_jumanpp_tokenized = jumanpp.tokenize(texts)
Vectorizer usage
from sumire.tokenizer.mecab import MecabTokenizer
from sumire.vectorizer.count import CountVectorizer
from sumire.vectorizer.swem import W2VSWEMVectorizer
from sumire.vectorizer.transformer_emb import TransformerEmbeddingVectorizer
texts = ["これはテスト文です。", "別のテキストもトークン化します。"]
count_vectorizer = CountVectorizer() # this automatically use MecabTokenizer()
swem_vectorizer = W2VSWEMVectorizer()
bert_cls_vectorizer = TransformerEmbeddingVectorizer()
# fit and transform at the same time. (Of course, you can .fit() and .transform() separately!)
count_vectorized = count_vectorizer.fit_transform(texts)
swem_vectorized = swem_vectorizer.fit_transform(texts)
bert_cls_vectorized = bert_cls_vectorizer.fit_transform(texts)
# save and load vectorizer.
count_vectorizer.save_pretrained("path/to/count_vectorizer")
count_vectorizer = CountVectorizer.from_pretrained("path/to/count_vectorizer")
swem_vectorizer.save_pretrained("path/to/swem_vectorizer")
swem_vectorizer = W2VSWEMVectorizer.from_pretrained("path/to/swem_vectorizer")
bert_cls_vectorizer.save_pretrained("path/to/bert_cls_vectorizer")
bert_cls_vectorizer = TransformerEmbeddingVectorizer.from_pretrained("path/to/beert_cls_vectorizer")
各単語分割器や文分散表現モジュールの詳細なドキュメントはドキュメントページを参照してください.
また, Transformersやgensimの動作済みmodelの情報は, /sumire/resources/model_cardを参照してください.
Development background
LLMの隆盛に伴い, 検索, 感情分析, その他テキスト分類・回帰などの日本語のNLPの実用タスクへの注目も高まりつつあります. これらの基本的なタスクにおいて, 日本語のテキストを単語分割や, 単語や文の分散表現を得ることは, 最も基礎的な処理の一つです. LLMの時代において, BERTなどの事前訓練済みTransformerモデルや, Open AI APIによるEmbeddingsは, テキスト分散表現技術において最も重要な技術であることはいうまでもなく, また, 簡単に実装できるといえば実装できます.
しかし, 実用の現場において, BERTや, OpenAI APIなどの,
高価なGPUが必要な手法や, 1 Queryごとに費用が発生するAPIを用いた最先端の手法を使うことは, 計算量・運用コストの両面から負荷が軽いとはいえません.
また, データセット構築段階などのプロジェクトの初期段階での概念実証 (PoC) において,
辞書データや形態素解析器のめんどくさいインストール作業や,
それぞれやや異なるAPIのメソッドやプロパティを調べながら作業を行うのは少しばかり手間です.
これらの点を踏まえて, GPUがあるとは限らない手元環境で, PoCにおけるモデリング・分析部分へ速やかに注力できように, Scikit-learnのように, 機能ごとに統一的なAPIインターフェースで, テキストを与えればとりあえず色々な文の分散表現を取得できるライブラリを開発しました.
Unmotivated development tasks (at this moment.)
- Open-AI Embedding modelを使うこと. (高い.)
- 事前訓練済みTransformerモデルによるEmbeddingについて, GPUが必要なチューニング機能を実装すること. (手元にGPUがない.)
- 実行速度のためにライブラリ内部の可読性を大きく下げること.
- 小規模なPoCにおいて, コードの実行速度より, 実装速度のほうが重要だと考えています.
- PoC後の大規模な運用にて, 速度やディスク容量が問題になった場合があれば, 本ライブラリ中の不要な処理をそれぞれの開発者が削除したりカスタマイズしやすいように, 可読性を維持したいです.
Roadmap (motivated development tasks)
- vectorizer inputsのdecode().
- Google colabでの動作環境検証.
Coding rule
https://pep8-ja.readthedocs.io/ja/latest/
License
sumire is distributed under the terms of the MIT License.
Acknowledgements (Dependent libraries, data, and models.)
See dependent_licenses.csv.
Metadata
Release files for sumire 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sumire-1.0.2.tar.gz | 24.7 kB | Without provenance | Details for sumire-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sumire-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for sumire-1.0.2-py3-none-any.whl |
Total release size: 79.0 kB
Release files / sumire-1.0.2.tar.gz
| Download URL | sumire-1.0.2.tar.gz |
|---|---|
| Size | 24.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e3f024534cf3d76f55f219805784e2c88906cb5125f10244b97e0d63b02846a
|
|
BLAKE2b-256 checksum How to use checksums |
7973f6ac3c93d52d844388ffaf2827718b60edc550b00e1d4a613a60c26ac8bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Release files / sumire-1.0.2-py3-none-any.whl
| Download URL | sumire-1.0.2-py3-none-any.whl |
|---|---|
| Size | 54.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d679fbc08104d603d8a8882e62119150eea6433f2980b3bf9b7184dd913c1224
|
|
BLAKE2b-256 checksum How to use checksums |
65d7df6560c5c1250144978d1dc3615a600a50657ac027186f8758a1f30dfd14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Security for sumire 1.0.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.