计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
embeddings-and-optimization【效率与协作】Routes Flair embedding-family selection, vector shape checks, language-model embedding reuse, storage/device behavior, and optional transformer optimization.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the task involves embedding choices, vector extraction, vector-shape debugging, embedding storage, language-model embedding reuse, or optional acceleration for the public, pip-installed flair package. The verified baseline is CPU PyTorch execution. CUDA, ONNX providers, TorchScript speedups, model downloads, SciSpaCy, pyab3p, OCR/image pipelines, and provider runtimes are optional unless the current environment proves them.
TokenEmbeddings and DocumentEmbeddings for taggers, classifiers, relation models, entity-linking indices, sentence similarity, or standalone vector export.TransformerEmbeddings, TransformerWordEmbeddings, TransformerDocumentEmbeddings, WordEmbeddings, FlairEmbeddings, PooledFlairEmbeddings, StackedEmbeddings, OneHotEmbeddings, or BytePairEmbeddings.DocumentPoolEmbeddings, DocumentRNNEmbeddings, DocumentCNNEmbeddings, or LM-backed document embeddings.LanguageModel training/fine-tuning and reusing a saved LM with FlairEmbeddings.Use sibling training/dataset guidance for corpus readers, label dictionaries, ModelTrainer.train, classifier construction, TARS, multitask, checkpoints, or multi-GPU launches. Use sibling tagging/annotation guidance for prediction labels, tokenization, sentence splitting, serialization, visualization, and regex tagging. Use biomedical guidance for HunFlair/HunFlair2 or biomedical entity linking.
FLAIR_DEVICE=cpu before importing flair when CPU determinism is required.FLAIR_CACHE_ROOT before importing flair when downloads are allowed and should be isolated to a caller-chosen cache.Transformer*, WordEmbeddings("glove"), BytePairEmbeddings("en"), and FlairEmbeddings("news-forward") may resolve remote resources.sentence.clear_embeddings() after standalone vector extraction or prediction unless the caller explicitly needs stored tensors later.embeddings_storage_mode="none" as the conservative default for transformer fine-tuning or memory-constrained prediction.| User need | Start with | Notes |
|---|---|---|
| Token-level tagging or token vectors | TransformerWordEmbeddings or TransformerEmbeddings(is_token_embedding=True) | Use layers="-1" for fine-tuning; more layers increase width when concatenated. |
| Document/sentence classification vectors | TransformerDocumentEmbeddings or DocumentPoolEmbeddings | Transformer documents are direct; pool/RNN/CNN build on token embeddings. |
| No-download smoke or unit fixtures | OneHotEmbeddings plus DocumentPoolEmbeddings | CPU-safe and in-memory; vectors are random until trained. |
| Frozen classic stack | StackedEmbeddings([WordEmbeddings(...), FlairEmbeddings(...), ...]) | Good for classic Flair workflows; named resources may download. |
| Small subword static baseline | BytePairEmbeddings(language="en") | Requires BPEmb resources from cache/download or local files. |
| Domain-specific contextual string embeddings | Train/reuse LanguageModel and pass best-lm.pt to FlairEmbeddings | Preserve LM direction and dictionary when fine-tuning or reusing. |
| Production transformer acceleration | ONNX or TorchScript after baseline comparison | Optional/unverified until dependencies, providers, and tensor comparisons pass. |
From this sub-skill directory, run:
python scripts/embedding_smoke.py --json
The default smoke uses in-memory dictionaries and tiny trainable embeddings. It imports flair, forces the CPU baseline unless the caller already set another policy, checks token/document vector widths, and does not download models. Optional transformer checks require explicit flags and still do not prove CUDA, ONNX, TorchScript, or provider acceleration.