Skip to content
Back to skills

Embeddings And Optimization

ASecurity

"Routes Flair embedding-family selection, vector shape checks,

  • 247 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 8, 2026
datapythongobashdebuggingapi

Works with

  • api

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add VectorSpaceLab/AREX-Skill --skill embeddings-and-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Embeddings And Optimization?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Embeddings And Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vectorspacelab-embeddings-and-optimization/badge)](https://www.skillsdirectory.com/skills/vectorspacelab-embeddings-and-optimization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: embeddings-and-optimization
description: "Routes Flair embedding-family selection, vector shape checks,
  language-model embedding reuse, storage/device behavior, and optional
  transformer optimization."
disable-model-invocation: true
metadata:
  disco-role: operating
license: NOASSERTION
---

# Flair Embeddings and Optimization

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.

## Route here for

- Choosing between `TokenEmbeddings` and `DocumentEmbeddings` for taggers, classifiers, relation models, entity-linking indices, sentence similarity, or standalone vector export.
- Configuring `TransformerEmbeddings`, `TransformerWordEmbeddings`, `TransformerDocumentEmbeddings`, `WordEmbeddings`, `FlairEmbeddings`, `PooledFlairEmbeddings`, `StackedEmbeddings`, `OneHotEmbeddings`, or `BytePairEmbeddings`.
- Building document vectors with `DocumentPoolEmbeddings`, `DocumentRNNEmbeddings`, `DocumentCNNEmbeddings`, or LM-backed document embeddings.
- Planning custom `LanguageModel` training/fine-tuning and reusing a saved LM with `FlairEmbeddings`.
- Debugging vector widths, stale embeddings, cache/download paths, device placement, storage modes, long sentences, context windows, OCR/layout metadata, ONNX, TorchScript, or execution-provider problems.

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.

## Start safely

1. Set `FLAIR_DEVICE=cpu` before importing `flair` when CPU determinism is required.
2. Set `FLAIR_CACHE_ROOT` before importing `flair` when downloads are allowed and should be isolated to a caller-chosen cache.
3. Avoid constructing named pretrained resources unless downloads are acceptable or the assets are already cached. `Transformer*`, `WordEmbeddings("glove")`, `BytePairEmbeddings("en")`, and `FlairEmbeddings("news-forward")` may resolve remote resources.
4. Prefer `sentence.clear_embeddings()` after standalone vector extraction or prediction unless the caller explicitly needs stored tensors later.
5. Treat `embeddings_storage_mode="none"` as the conservative default for transformer fine-tuning or memory-constrained prediction.

## Read these references

- [Embedding recipes](references/embedding-recipes.md): concrete API recipes, family-selection rules, shape/device checks, storage modes, and language-model reuse.
- [Transformer optimization](references/transformer-optimization.md): optional ONNX/TorchScript/provider paths, dependencies, export checks, and validation comparisons.
- [Troubleshooting](references/troubleshooting.md): cache/download, stale embeddings, static resources, long sentence/context, OCR/image metadata, LM training, and provider-runtime failures.
- [Embedding smoke script](scripts/embedding_smoke.py): safe no-download CPU smoke checks for token/document embeddings.

## Quick decision map

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

## Smoke check

From this sub-skill directory, run:

```bash
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.

Files in this skill

  • SKILL.md5.1 KB
  • references/embedding-recipes.md18.3 KB
  • references/transformer-optimization.md11 KB
  • references/troubleshooting.md10.6 KB
  • scripts/embedding_smoke.py9.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.