HashEmbedder#
- class scikitplot.corpus.HashEmbedder(dimension=1024, token_pattern="[^\\W\\d_]+(?:['’][^\\W\\d_]+)*", lowercase=True)[source]#
Embed text with deterministic signed feature hashing.
- Parameters:
- dimensionint, default=1024
Number of output features. Must be positive.
- token_patternstr, optional
Regular expression used to extract tokens. The default recognizes Unicode words and internal straight/curly apostrophes.
- lowercasebool, default=True
Lowercase text before tokenization.
- Parameters:
Notes
This embedder is deliberately local and deterministic. Each token is hashed with BLAKE2b into one output column and assigned a deterministic sign. Rows are L2-normalized. The result is suitable for reproducible lexical/dense teaching paths, smoke tests, and offline retrieval baselines.
It does not provide learned semantic similarity and should not be presented as a substitute for sentence-transformer or API embeddings.
Examples
>>> embedder = HashEmbedder(dimension=32) >>> vectors = embedder(["ghost father", "sleep dream"]) >>> vectors.shape (2, 32) >>> vectors.dtype == np.float32 True
Gallery examples#
Build and Search a Real Hamlet Corpus with FluentCorpus
Build and Search a Real Hamlet Corpus with FluentCorpus