技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
embedding-analysis【数据与研究】Guides agents using textgenrnn encode_text_vectors, attention-layer vectors, PCA/t-SNE, and similarity nearest-text analysis.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the task is to turn text strings into vectors with textgenrnn's attention layer, reduce those vectors with PCA or t-SNE, or rank candidate strings by cosine similarity.
encode_text_vectors on one string or a list of strings.pca_dims, tsne_dims, tsne_seed, return_pca, and
return_tsne safely.similarity(text, texts, use_pca=...) for nearest-text ranking.max_length/representation capacity: use
training.pkg_resources, or package-version problems: use
root compatibility guidance.pkg_resources available. If imports fail, route to
installation and compatibility.pca_dims=None.return_pca=True while fitting candidate vectors, then transform new raw
query vectors with that PCA object.For small or unknown text counts, prefer raw vectors first:
from textgenrnn import textgenrnn
textgen = textgenrnn()
texts = ["short example", "another example"]
vectors = textgen.encode_text_vectors(texts, pca_dims=None)
print(vectors.shape)
Then apply PCA only when the sample count supports the chosen dimension:
candidate_vectors, pca = textgen.encode_text_vectors(
texts,
pca_dims=min(10, len(texts)),
return_pca=True,
)
query_raw = textgen.encode_text_vectors("query text", pca_dims=None)
query_vector = pca.transform(query_raw)
For nearest-text ranking, avoid the library's PCA default unless there are enough candidate texts for it:
pairs = textgen.similarity("query text", texts, use_pca=False)
for candidate, score in pairs[:5]:
print(score, candidate)
pca_dims=None: safest for one text or small candidate lists; returns raw
attention vectors.pca_dims=N: use only when N <= min(number_of_texts, raw_vector_width).
In modern scikit-learn, pca_dims=50 can fail on fewer than 50 texts.return_pca=True: valid only when PCA is actually fitted; do not combine it
with pca_dims=None.tsne_dims=N: intended for visualization coordinates, usually 2 or 3;
requires enough samples for scikit-learn t-SNE's perplexity constraints.tsne_seed=N: use a fixed integer seed for repeatable t-SNE initialization.return_tsne=True: valid only when t-SNE is actually fitted; do not combine
it with tsne_dims=None.use_pca=False in similarity: safest default for small candidate sets.use_pca=True in similarity: fits PCA on the candidate texts, transforms
the query into that fitted space, then ranks by cosine similarity.(1, vector_width).max_length - 1 text tokens influence vectors. The pretrained
character-level model effectively uses the first 39 characters; train a model
with a larger max_length or word-level configuration if that is not enough.(number_of_texts, pca_dims) when the requested dimension
is supported.(number_of_texts, tsne_dims) when fitting succeeds.