AGENT SKILL

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

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(...) and BERTopic.load(...) workflows.
  • Choosing among serialization="safetensors", serialization="pytorch", and serialization="pickle".
  • Deciding whether to include save_ctfidf=True for 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 with BERTopic.load("namespace/repo").
  • Serialization-side failures from BERTopic.merge_models(...), such as missing torch or safetensors; 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

  1. Start with references/api-reference.md for save/load/push signatures, format behavior, local file layout, and load-path resolution.
  2. Use references/workflows.md for local exact round trips, portable lightweight saves, embedding-model restoration, Hub upload/load, and local-vs-Hub decisions.
  3. Use references/troubleshooting.md for import failures, optional dependency errors, invalid paths, credential issues, embedding-backend gaps, and version/security warnings.
  4. Run scripts/smoke_serialization.py for 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, pickle is 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 safetensors with save_ctfidf=True when topic-term inspection after reload matters.
  • If safetensors is unavailable but torch is already an accepted dependency, use pytorch; it creates the same lightweight directory style with .bin weights.
  • If future transform(...) calls should work without passing embeddings=, save a SentenceTransformer-compatible model id with save_embedding_model="sentence-transformers/..." or pass a freshly constructed backend to BERTopic.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 confirming huggingface_hub is 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(...) and BERTopic.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

VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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).

★ 351