| Crates.io | subslay |
| lib.rs | subslay |
| version | 0.1.9 |
| created_at | 2025-07-12 17:15:13.019626+00 |
| updated_at | 2025-07-13 21:42:40.294566+00 |
| description | SubSlay: Text β emoji π π» Powered by Rust. |
| homepage | |
| repository | https://github.com/8ria/subslay |
| max_upload_size | |
| id | 1749518 |
| size | 7,413,001 |
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 subslay::EmojiStylist;
fn main() {
let stylist = EmojiStylist::new().unwrap();
let emojis = stylist.slay("Hello, world!");
println!("{:?}", emojis); // ["π", "π"]
}
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:
embeddings.bin filebincode and quantized vector loadingf16 (half-precision) vectors for compact sizeAdd SubSlay to your Cargo.toml:
[dependencies]
subslay = "0.1.9"
use subslay::EmojiStylist;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let stylist = EmojiStylist::new()?;
let emojis = stylist.slay("happy pizza");
println!("{:?}", emojis); // e.g. ["π", "π"]
Ok(())
}
let stylist = EmojiStylist::new()?;
let sentence = "I love pizza and cats";
let emojis = stylist.slay(sentence);
println!("Emojis: {:?}", emojis);
// Possible output: ["β€οΈ", "π", "πΊ"]
SubSlay embeds a pre-serialized binary file (embeddings.bin) using include_bytes!, which includes:
HashMap<String, Vec<f16>> of words mapped to quantized 50D GloVe embeddingsHashMap<String, Vec<f16>> of emojis mapped to semantic emoji vectorsWhen .slay(&str) is called:
The input is cleaned (only letters and spaces).
Words are lowercased and split.
Each word:
"@" if no match is foundCosine similarity is calculated like this:
fn cosine_similarity(a: &[f16], b: &[f16]) -> f32 {
let dot = a.iter().zip(b.iter()).map(|(x, y)| x.to_f32() * y.to_f32()).sum::<f32>();
let norm_a = a.iter().map(|x| x.to_f32().powi(2)).sum::<f32>().sqrt();
let norm_b = b.iter().map(|x| x.to_f32().powi(2)).sum::<f32>().sqrt();
if norm_a == 0.0 || norm_b == 0.0 {
return -1.0;
}
dot / (norm_a * norm_b)
}
| 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> |
SubSlay includes unit tests for:
"pizza"Run tests:
cargo test
src/lib.rs β Main logic for translation and similaritydata/embeddings.bin β Serialized, quantized GloVe and emoji vectorsCargo.toml β Dependency configREADME.md β Youβre reading itf16) to reduce file sizebincode.slay() callsMIT Β© AndriaK GitHub Repository Live Demo