serialization
Save, load, and share BERTopic models locally or on the Hugging Face Hub with safe format and dependency choices.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- serialization
- license
- MIT
- metadata
- { "package": "BERTopic", "disco-role": "operating", "parent-skill": "bertopic", "package-version": "0.17.4" }
- description
- Save, load, and share BERTopic models locally or on the Hugging Face Hub with safe format and dependency choices.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md7.5 KB
- 参考文档references/troubleshooting.md7.5 KB
- 参考文档references/workflows.md7.7 KB
- 脚本scripts/smoke_serialization.py10.3 KB
03 SKILL.md 正文
serialization
Use this sub-skill when the task is about persisting an already fitted BERTopic model, reloading it locally, or publishing/loading it through the Hugging Face Hub.
Route here for
BERTopic.save(...)andBERTopic.load(...)workflows.- Choosing among
serialization="safetensors",serialization="pytorch", andserialization="pickle". - Deciding whether to include
save_ctfidf=Truefor topic-term inspection after reload. - Deciding how to use
save_embedding_model: a lightweight model pointer, omitting the backend, or reinjecting a backend at load time. - Local save/load from a pickle file or from a lightweight model directory.
- Hub upload with
BERTopic.push_to_hf_hub(...)and Hub loading withBERTopic.load("namespace/repo"). - Serialization-side failures from
BERTopic.merge_models(...), such as missingtorchorsafetensors; route the model-combination decision itself to topic-modeling.
Route elsewhere
- Training, fitting, transforming, partial fitting, topic reduction, topic merging, or outlier workflows: use the topic-modeling sub-skill.
- Embedding backend selection, custom backend implementation, API-client setup, or precomputed embedding construction: use the embeddings-backends sub-skill.
- c-TF-IDF or vectorizer tuning before saving: use the vectorizers-ctfidf sub-skill.
- Representation models, custom labels, or multi-aspect labels: use the representations-labeling sub-skill.
- Plotting, visualization, hierarchy dashboards, or figure export: use the analysis-visualization sub-skill.
Operating references
- Start with
references/api-reference.mdfor save/load/push signatures, format behavior, local file layout, and load-path resolution. - Use
references/workflows.mdfor local exact round trips, portable lightweight saves, embedding-model restoration, Hub upload/load, and local-vs-Hub decisions. - Use
references/troubleshooting.mdfor import failures, optional dependency errors, invalid paths, credential issues, embedding-backend gaps, and version/security warnings. - Run
scripts/smoke_serialization.pyfor a tiny local-only smoke check of pickle plus a lightweight format when the BERTopic runtime dependencies are available.
Minimal decision flow
- If the file will only be loaded in the same trusted Python and dependency environment,
pickleis the most complete format because it stores the full BERTopic object, including dimensionality-reduction and clustering sub-models. - If the model should be small, safer to share, production-oriented, or Hub-friendly, prefer
safetensorswithsave_ctfidf=Truewhen topic-term inspection after reload matters. - If
safetensorsis unavailable buttorchis already an accepted dependency, usepytorch; it creates the same lightweight directory style with.binweights. - If future
transform(...)calls should work without passingembeddings=, save a SentenceTransformer-compatible model id withsave_embedding_model="sentence-transformers/..."or pass a freshly constructed backend toBERTopic.load(..., embedding_model=...). - If the backend is custom or uses external API credentials, do not expect lightweight serialization to store it; reconstruct that backend separately and inject it at load time.
- If uploading to the Hub, use
push_to_hf_hub(...)only after confirminghuggingface_hubis installed and the process is authenticated or has a token. - If loading locally, pass an existing file or directory. If a missing path contains
/, BERTopic treats it as a Hub repo id.
Verification anchors
- Local no-network save/reload: fit or reuse a tiny synthetic model with precomputed embeddings, save as pickle and at least one lightweight format, reload from local file/directory, and assert topic counts plus representative topic metadata survive.
- Local-vs-Hub guidance: confirm local round trips do not require Hugging Face credentials, while
push_to_hf_hub(...)andBERTopic.load("namespace/repo")require Hub-oriented dependencies and network/auth conditions. - Embedding restoration edge case: load a lightweight model once without an embedding backend and once with an explicit backend or precomputed embeddings, then document the difference in future
transform(...)behavior.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).