bertopic-ja
日本語の文書から、どんなトピックが話されているかを探索するなら BERTopic です。埋め込み、UMAP、HDBSCAN、c-TF-IDF という今の探索的トピックモデルの手順を、日本語のトピック語が単語になる状態で始められます。
公式のトークナイザは空白で区切るため、分かち書きしない日本語では機能しません。トピック名が単語ではなく、文のかたまりになります。このパッケージはそこを Sudachi に置き換えた入口です。公式 BERTopic のサブプロジェクトではありません。手法と実装の本体は Maarten Grootendorst の BERTopic(論文: arXiv:2203.05794)です。
インストール
uv add bertopic-ja
pip install bertopic-ja
使い方
from bertopic_ja import BERTopic
topic_model = BERTopic()
topics, probs = topic_model.fit_transform(docs)
topic_model.get_topic_info()
何も指定しないときの埋め込みは、BERTopic の language="multilingual"(paraphrase-multilingual-MiniLM-L12-v2)です。トピック語は Sudachi(分割モード C)の名詞です。1文字の名詞、代名詞、数詞は出しません。「えー」「まあ」のようなフィラーはトピック語から外し、本文には残します。「あの本」の「あの」は消しません。
トピックの粗さは min_topic_size です。UMAP と HDBSCAN は自分で組みません。
topic_model = BERTopic(min_topic_size=8)
出てきた語を調整する
トピック語から外すだけなら、埋め込みはやり直しません。
topic_model.exclude("天気", "気温")
topic_model.suggest()
topic_model.explain("このレシピって作ったことあります?")
topic_model.preview_exclude(["天気"])
クラスタの数や粗さを変えるときは、保存してある埋め込みで学習し直します。
topic_model.refit(min_topic_size=8)
topic_model.refit(nr_topics=15)
本文からフィラーを消すとクラスタが変わるので、初期値では消しません。消すときだけ fillers= を渡します。
topic_model = BERTopic(fillers=["えー", "あのー"])
別の埋め込みモデルにするときは、名前を一つ渡します。
topic_model = BERTopic(embedding_model="cl-nagoya/ruri-v3-310m")
設定ファイル
引数と YAML は同じ項目です。両方あるときは引数が優先されます。
min_topic_size: 10
nr_topics: auto
reduce_outliers: true
embedding_model: null
exclude:
- 天気
protect:
- レシピ
fillers: []
topic_model = BERTopic.from_yaml("config.yaml", min_topic_size=8)
topic_model.to_yaml("config.yaml")
公式との違い
公式の BERTopic(language="multilingual") は日本語の文をベクトルにできます。トピック語を作るトークナイザは英語向けの空白区切りのままで、日本語では単語に切れません。このパッケージはそのトークナイザを Sudachi に置き換え、語の除外とクラスタの再調整をメソッドにしています。
分類器でも、特定の業界向けの分析パイプラインでもありません。ラベルの付いていない文書から話題を探すためのものです。
公開
ローカルでのビルドは次です。
uv build
PyPI へ出すときは、PyPI の Trusted Publishing に GitHub リポジトリを登録してからタグを切ります。このリポジトリのワークフローはテストの実行までです。
Metadata
Release files for bertopic-ja 0.1.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 |
|---|---|---|---|---|
| bertopic_ja-0.1.2.tar.gz | 174.3 kB | Without provenance | Details for bertopic_ja-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bertopic_ja-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for bertopic_ja-0.1.2-py3-none-any.whl |
Total release size: 185.9 kB
Release files / bertopic_ja-0.1.2.tar.gz
| Download URL | bertopic_ja-0.1.2.tar.gz |
|---|---|
| Size | 174.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
18af12611f5b2143e36c4498305fd8b5821ec6bc3d932cefa048a617ed30e1e7
|
|
BLAKE2b-256 checksum How to use checksums |
20763610b70206c23909030f0ba08ec7d2f1bc10e5dbe516fdf26981031f0fcb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.29
|
Release files / bertopic_ja-0.1.2-py3-none-any.whl
| Download URL | bertopic_ja-0.1.2-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02f91f7633fd1886716f1713ec7e8de9fcfdd83ca78c2421bf9dff3fc69c739a
|
|
BLAKE2b-256 checksum How to use checksums |
52fbbb90883c349c888b61c728cab662331828b5452ec06cdd584271565f77df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.29
|
Security for bertopic-ja 0.1.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.