SubSlay converts plain text into emoji sequences using semantic similarity with pre-embedded GloVe vectors and emoji keyword mappings β all bundled inside a pure Rust crate.
use EmojiStylist;
π§Ύ What is SubSlay?
SubSlay is a Rust library that transforms ordinary text into emoji sequences that capture the semantic meaning of each word. It uses pre-trained GloVe word embeddings and maps them to emojis using embedded semantic vectors β all packed into the crate itself.
This enables fast, expressive emoji translation fully offline with zero API calls or external resources.
Itβs ideal for:
- β¨ Chat apps
- π€ Discord bots
- π± Social media tools
- π» Terminal utilities
π Features
- π¦ Pure Rust β no runtime dependencies
- π¦ Embedded embeddings β GloVe + emoji vectors bundled as a single
embeddings.binfile - π§ Cosine similarity with emoji semantics for contextual matching
- π Fallback handling for unknown or out-of-vocab words
- π WASM-compatible β works in browser/Edge without filesystem or network access
- π¨ Blazing fast & offline β powered by
bincodeand quantized vector loading - πͺΆ Tiny footprint β uses
f16(half-precision) vectors for compact size
π¦ Installation
Add SubSlay to your Cargo.toml:
[]
= "0.1.9"
π οΈ Usage
use EmojiStylist;
Example:
let stylist = new?;
let sentence = "I love pizza and cats";
let emojis = stylist.slay;
println!;
// Possible output: ["β€οΈ", "π", "πΊ"]
βοΈ How It Works (Under the Hood)
SubSlay embeds a pre-serialized binary file (embeddings.bin) using include_bytes!, which includes:
- π€ A
HashMap<String, Vec<f16>>of words mapped to quantized 50D GloVe embeddings - π A
HashMap<String, Vec<f16>>of emojis mapped to semantic emoji vectors
When .slay(&str) is called:
-
The input is cleaned (only letters and spaces).
-
Words are lowercased and split.
-
Each word:
- Tries to fetch a GloVe embedding
- Computes cosine similarity with all emoji vectors
- Selects the closest emoji
- Falls back to
"@"if no match is found
Cosine similarity is calculated like this:
π― API Overview
| Method | Description |
|---|---|
EmojiStylist::new() |
Initializes the struct by deserializing the embedded binary file |
stylist.slay(&str) |
Translates each word in the input into a matching emoji, returns Vec<String> |
π§ͺ Testing
SubSlay includes unit tests for:
- β
Correct output for known words like
"pizza" - β Full sentence translation
- β Unknown/fallback behavior
- β Empty input
Run tests:
π Package Contents
src/lib.rsβ Main logic for translation and similaritydata/embeddings.binβ Serialized, quantized GloVe and emoji vectorsCargo.tomlβ Dependency configREADME.mdβ Youβre reading it
π§βπ» Developer Notes
- Embeddings are stored using quantized half-precision floats (
f16) to reduce file size - All data is serialized using
bincode - Pre-trained GloVe 50d embeddings are used for English vocabulary
- The emoji vectors are handcrafted or generated using centroid-like heuristics
π‘ Future Plans
- Weighted phrase-to-emoji aggregation
- Fuzzy matching for slang and typos
- Custom user dictionaries or theme packs
- Parallel or batch
.slay()calls - Embedding compression + streaming load
π License
MIT Β© AndriaK GitHub Repository Live Demo