Skip to content

npm package that lets you add a touch of fun and expressiveness to your text. This package can interpret the sentiment behind your text and suggest relevant emojis. ๐Ÿ™Œ

Notifications You must be signed in to change notification settings

MagnusCardell/emoji-whisperer-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

27 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Engine for the emoji whisperer npm package

Building a search engine for emojis

Implementation

The inverse word frequency ($iwf$) is calculated as:

$$ iwf(e, W) = \log \frac{{|W|}}{{|{w \in W: e \in w}|}}$$

where $|W|$ is the total number of words, and $|{w \in W: e \in w}|$ is the number of words where the emoji $e$ appears.

The median frequency ($mf$) is the median distance between a word an the emoji.

The emoji-word frequency ($ewf$) is calculated as:

$$ ewf(e, w) = \frac{{\textit{{count of emoji }} e \textit{{ for word }} w}}{{\textit{{total number of emojis}}}}$$

where $f_{e, w}$ is the frequency of emoji $e$ given word $w$.

Finally, the score is computed as:

$$ score(e, w, W) = \frac{{iwf(e, W)}}{{mf + ewf(e, w)}}$$

$e$ corresponds to an emoji, $w$ corresponds to a word in the query, and $W$ corresponds to the entire corpus from which the index was built.

Given an input query $Q$, the resulting emoji is calculated as:

$$ score(e, Q, W) = \sum_{{w \in Q}} \frac{{\textit{{iwf}}(e, W)}}{{\textit{{mf}}_w + \textit{{ewf}}(e, w)}} $$

$$ \textit{{topEmojis}}(Q, W, n) = \textit{{top }} n \textit{{ emojis }} e \textit{{ sorted by }} \textit{{score}}(e, Q, W) $$

See repository https://github.com/MagnusCardell/emoji-whisperer for an implementation of index in node.js

Results

example input sentence and output 5 top scoring emoji groups

Who else is excited for the new Avengers movie? #MarvelFan,"๐Ÿ˜™๐Ÿ‘Œ, โœจ, ๐Ÿค, ๐Ÿ˜‚๐Ÿคฃ, ๐Ÿคทโ€โ™‚๏ธ๐Ÿ™"
Can't believe how beautiful the sunset was today. #NaturePhotography,"๐Ÿ’–, ๐Ÿ˜™๐Ÿ‘Œ๐Ÿผ, ๐Ÿ”‹, ๐Ÿ˜”๐Ÿ™, ๐Ÿ‘Œ๐Ÿผ๐Ÿ‘Œ๐Ÿผ"
Dinner at my favorite sushi place #Foodie,"๐Ÿ˜ญ, ๐Ÿ™Œ๐Ÿ™Œ๐Ÿ™Œ, ๐Ÿคž๐Ÿฝ, ๐Ÿ‘๐Ÿป, ๐Ÿ‘"
Throwback to my trip to Paris last summer #TravelDiaries,"๐Ÿ˜Ž๐Ÿค™๐Ÿฝ, ๐Ÿค˜๐Ÿฝ, ๐ŸโœŠ, ๐Ÿ™Œ๐ŸŒ…, ๐Ÿ˜Ž๐Ÿ˜‚๐Ÿ‘"
Feeling so blessed to have such amazing people in my life #Blessed,"๐Ÿ˜‚๐Ÿ™Œ๐Ÿผ, ๐Ÿ”ฅ, โค๏ธ๐Ÿ™๐Ÿพ๐Ÿ’ฏ, ๐Ÿ˜โœ‹๐Ÿผ, ๐Ÿ‡ธ๐Ÿ‡ด"
That was the best concert ever!,"๐Ÿ˜ฉ๐Ÿ‘Œ, ๐Ÿ‘Œ๐Ÿฝ, ๐Ÿคฉ๐Ÿ™Œ, ๐Ÿค๐Ÿผ, ๐Ÿคš๐Ÿผ"
I'm scared of spiders.,"๐Ÿ™ˆ, โœจ๐Ÿคž๐Ÿผ, ๐Ÿ˜”๐Ÿคš, ๐Ÿ˜ƒ๐Ÿ‘‹, ๐Ÿ˜โœŒ๏ธ"
My heart is broken.,"๐Ÿ’™, โค, ๐Ÿƒ, ๐Ÿ™๐Ÿฝ๐Ÿ˜ฉ, ๐Ÿฅฐ๐Ÿ‘"
I can't wait for my birthday.,"๐Ÿ’Ž๐Ÿ™Œ, โœจ, ๐Ÿ’ช๐Ÿพ๐Ÿ”ฅ, ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ™Œ๐Ÿ™Œ๐Ÿ™Œ, ๐Ÿ‡ฌ๐Ÿ‡น"
angry,"๐Ÿ‘บ, ๐Ÿ’ข, ๐Ÿ—ฏ, ๐Ÿ˜–, ๐Ÿ˜ฃ"
love,"๐Ÿ™๐Ÿฝ๐Ÿ˜ƒ, ๐Ÿ’˜, โ™ฅ, โฃ, ๐Ÿฉ"
hate,"๐Ÿ‘ˆ๐Ÿฝ๐Ÿ’ฏ๐Ÿ‘, ๐Ÿ™„๐Ÿ‘Ž๐Ÿผ, ๐Ÿ˜ˆ๐Ÿ‘Œ๐Ÿป๐Ÿ”ฅ, โœ‹๐Ÿผ๐Ÿ™„, ๐Ÿ’ช๐Ÿพ๐Ÿ’–"
food,"๐ŸŒญ, ๐ŸŒฎ, ๐ŸŒฏ, ๐ŸŒถ, ๐ŸŒฝ"
hungry,"๐Ÿ˜ญ๐Ÿ–•, ๐Ÿ˜”๐Ÿคš๐Ÿฝ, ๐Ÿ˜‚๐Ÿ˜‚๐Ÿ˜‚๐Ÿ˜ญ, ๐Ÿ˜Š๐Ÿ‘๐Ÿ‘โค๏ธ๐Ÿ‘, ๐Ÿ‘๐Ÿ˜ญ"
tired,"๐Ÿ˜ซ, ๐Ÿ›€, ๐Ÿ›, ๐Ÿ›, ๐Ÿ˜ช"
excited,"๐Ÿค‘๐Ÿ‘๐Ÿผ๐Ÿ‘๐Ÿผ, ๐Ÿ˜ญ๐Ÿ™Œ๐Ÿป, ๐Ÿ˜ฉ๐Ÿ™Œ๐Ÿผ, ๐Ÿคฉ๐Ÿ™Œ๐Ÿป๐Ÿ‘๐Ÿป, ๐Ÿคช๐Ÿ™Œ๐Ÿป"
work,"๐Ÿ‘๐Ÿผ๐Ÿ‘๐Ÿผ, โŒจ, ๐Ÿข, ๐Ÿ’ป, ๐Ÿ’ผ"
home,"๐Ÿด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟโœŒ๏ธ, ๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘ , โœˆ๏ธ, ๐Ÿ˜, ๐Ÿ "
play,"โ–ถ, ๐ŸŽด, ๐Ÿ˜‚๐Ÿ˜‚๐Ÿ˜‚๐Ÿ‘๐Ÿฝ๐Ÿ‘๐Ÿฝ๐Ÿ‘๐Ÿฝ, ๐Ÿ’ฏ๐Ÿ™Œ๐Ÿฝ, ๐Ÿ˜Ž๐Ÿ‘๐Ÿ˜‚๐Ÿ˜‚"
game,"๐Ÿ˜Ž๐Ÿ‘๐Ÿ‘๐Ÿ‡ธ๐Ÿ‡ป, โ™ , โ™ฃ, โ™ฅ, โ™ฆ"
sports,"โšฝ, โšพ, โ›ท, โ›ธ, ๐ŸŽฑ"
music,"๐Ÿ‘๐Ÿพ๐Ÿ‘๐Ÿพ๐Ÿฅบ, ๐ŸŽ™, ๐ŸŽš, ๐ŸŽ›, ๐ŸŽต"
movie,"๐ŸŽž, ๐ŸŽŸ, ๐ŸŽฅ, ๐ŸŽฆ, ๐ŸŽซ"
book,"๐Ÿ“–, ๐Ÿ“”, ๐Ÿ“•, ๐Ÿ“—, ๐Ÿ“˜"
travel,"โ›ฉ, โ›ฐ, โ›ฑ, โ›ฒ, โ›ด"
adventure,"๐Ÿ™๐Ÿฝ๐Ÿˆ, ๐Ÿ™๐Ÿพ๐Ÿ‘๐Ÿพ๐Ÿ˜Ž, ๐Ÿ™Œ๐Ÿ™Œ๐Ÿ™Œ๐Ÿ’™๐Ÿ’™๐Ÿ’™๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ, ๐Ÿ˜Ž๐Ÿค™๐Ÿผ, ๐Ÿ˜ƒ๐Ÿ™๐Ÿฝ"
family,"๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆ, ๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘ฆ, ๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘ฆโ€๐Ÿ‘ฆ, ๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘ง, ๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ"
party,"๐Ÿท, ๐Ÿพ, ๐ŸŽ, ๐ŸŽ†, ๐ŸŽ‡"

Notes

Building index:

  1. collect documents (sentences with emojis)
  2. tokenize the documents
  3. preprocess the tokens. lowercase, cleanup, english
  4. Index documents with inverted index

About

npm package that lets you add a touch of fun and expressiveness to your text. This package can interpret the sentiment behind your text and suggest relevant emojis. ๐Ÿ™Œ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published