Train emoji embeddings based on emoji descriptions.

Overview

emoji2vec

This is my attempt to train, visualize and evaluate emoji embeddings as presented by Ben Eisner, Tim Rocktรคschel, Isabelle Augenstein, Matko Boลกnjak, and Sebastian Riedel in their paper [1]. Most of their results are used here to build an equivalently robust model in Keras, including the rather simple training process which is solely based on emoji descriptions, but instead of using word2vec (as it was originally proposed) this version uses global vectors [2].

Overview

  • src/ contains the code used to process the emoji descriptions as well as training and evaluating the emoji embeddings
  • res/ contains the positive and negative samples used to train the emoji embeddings (originated here) as well as a list of emoji frequencies; it should also contain the global vectors in a directory called glove/ (for practical reasons they are not included in the repository, but downloading instructions are provided below)
  • models/ contains some pretrained emoji2vec models
  • plots/ contains some visualizations for the obtained emoji embeddings

Dependencies

The code included in this repository has been tested to work with Python 3.5 on an Ubuntu 16.04 machine, using Keras 2.0.8 with Tensorflow as the backend.

List of requirements

Implementation notes

Following Eisner's paper [1], training is based on 6088 descriptions of 1661 distinct emojis. Since all descriptions are valid, we randomly sample negative instances so that there is one positive example per negative example. This approach proved to produce the best results, as stated in the paper.

There are two architectures on which emoji vectors have been trained:

  • one based on the sum of the individual word vectors of the emoji descriptions (taken from the paper)

emoji2vec

  • the other feeds the actual pretrained word embeddings to an LSTM layer (this is my own addition which can be used by setting use_lstm=True i.e -l=True)

emoji2vec_lstm

Not like in the referenced paper, we used global vectors which need to be downloaded and placed in the res/glove directory. You can either download them from the original GloVe page or you can run these bash commands:

! wget -q http://nlp.stanford.edu/data/glove.6B.zip
! unzip -q -o glove.6B.zip

Arguments

All the hyperparameters can be easily changed through a command line interface as described below:

  • -d: embedding dimension for both the global vectors and the emoji vectors (default 300)
  • -b: batch size (default 8)
  • -e: number of epochs (default 80, but we always perform early-stopping)
  • -dr: dropout rate (default 0.3)
  • -lr: learning rate (default 0.001, but we also have a callback to reduce learning rate on plateau)
  • -u: number of hidden units in the dense layer (default 600)
  • -l: boolean to set or not the LSTM architecture (default is False)
  • -s: maximum sequence length (needed only if use_lstm=True, default 10, but the actual, calculated maximum length is 27 so a post-truncation or post-padding is applied to the word sequences)

Training your own emoji2vec

To train your own emoji embeddings, run python3 emoji2vec.py and use the arguments described above to tune your hyperparameters.

Here is an example that will train 300-dimensional emoji vectors using the LSTM-based architecture with a maximum sequence length of 20, batch size of 8, 40 epochs, a dropout of 0.5, a learning rate of 0.0001 and 300 dense units:

python3 emoji2vec.py -d=300 -b=8 -e=40 -dr=0.5 -lr=0.0001 -u=300 -l=True -s=20 

The script given above will create and save several files:

  • in models/ it will save the weights of the model (.h5 format), a .txt file containing the trained embeddings and a .csv file with the x, y emoji coordinates that will be used to produce a 2D visualization of the emoji2vec vector space
  • in plots/ it will save two plots of the historical accuracy and loss reached while training as well as a 2D plot of the emoji vector space
  • it will also perform an analogy-task to evaluate the meaning behind the trained vectorized emojis (printed on the standard output)

Using the pre-trained models

Pretrained emoji embeddings are available for download and usage. There are 100 and 300 dimensional embeddings available in this repository, but any dimension can be trained manually (you need to provide word embeddings of the same dimension, though). The complete emoji2vec weights, visualizations and embeddings (for different dimensions and performed on both architectures) are available for download at this link.

For the pre-trained embeddings provided in this repository (trained on the originally proposed architecture), the following hyperparameter settings have been made (respecting, in large terms, the original authors' decisions):

  • dim: 100 or 300
  • batch: 8
  • epochs: 80 (usually, early stopping around the 30-40 epochs)
  • dense_units: 600
  • dropout: 0.0
  • learning_rate: 0.001
  • use_lstm: False

For the LSTM-based pre-trained embeddings provided in the download link, the following hyperparameter settings have been made:

  • dim: 50, 100, 200 or 300
  • batch: 8
  • epochs: 80 (usually, early stopping around the 40-50 epochs)
  • dense_units: 600
  • dropout: 0.3
  • learning_rate: 0.0001
  • use_lstm: True
  • seq_length: 10

Example code for how to use emoji embeddings, after downloading them and setting up their dimension (embedding_dim):

from utils import load_vectors

embeddings_filename = "/models/emoji_embeddings_%dd.txt" % embedding_dim
emoji2vec = utils.load_vectors(filename=embeddings_filename)

# Get the embedding vector of length embedding_dim for the dog emoji
dog_vector = emoji2vec['๐Ÿ•']

Visualization

A nice visualization of the emoji embeddings has been obtained by using t-SNE to project from N-dimensions into 2-dimensions. For practical purposes, only a fraction of the available emojis has been projected (the most frequent ones, extracted according to emoji_frequencies.txt).

Here, the top 200 most popular emojis have been projected in a 2D space:

emoji2vec_vis

Making emoji analogies

The trained emoji embeddings are evaluated on an analogy task, in a similar manner as word embeddings. Because these analogies are broadly interpreted as similarities between pairs of emojis, the embeddings are useful and extendible to other tasks if they can capture meaningful linear relationships between emojis directly from the vector space [1].

According to ACL's wiki page, a proportional analogy holds between two word pairs: a-a* :: b-b* (a is to a* as b is to b*). For example, Tokyo is to Japan as Paris is to France and a king is to a man as a queen is to a woman.

Therefore, in the current analogy task, we aim to find the 5 most suitable emojis to solve a - b + c = ? by measuring the cosine distance between the trained emoji vectors.

Here are some of the analogies obtained:

๐Ÿ‘‘ - ๐Ÿšน + ๐Ÿšบ = [' ๐Ÿ‘ธ ', ' ๐Ÿ‡ฎ๐Ÿ‡ฑ ', ' ๐Ÿ‘ฌ ', ' โ™‹ ', ' ๐Ÿ’Š ']

๐Ÿ’ต - ๐Ÿ‡บ๐Ÿ‡ธ + ๐Ÿ‡ช๐Ÿ‡บ = [' ๐Ÿ‡ฆ๐Ÿ‡ด ', ' ๐Ÿ‡ธ๐Ÿ‡ฝ ', ' ๐Ÿ‡ฎ๐Ÿ‡ช ', ' ๐Ÿ‡ญ๐Ÿ‡น ', ' ๐Ÿ‡ฐ๐Ÿ‡พ ']

๐Ÿ•ถ - โ˜€ + โ›ˆ = [' ๐Ÿ‘ž ', ' ๐Ÿ  ', ' ๐Ÿ– ', ' ๐Ÿ•’ ', ' ๐ŸŽ ']

โ˜‚ - โ›ˆ + โ˜€ = [' ๐ŸŒซ ', '๐Ÿ’…๐Ÿพ', ' ๐ŸŽ ', ' ๐Ÿ“› ', ' ๐Ÿ‡ง๐Ÿ‡ฟ ']

๐Ÿ… - ๐Ÿˆ + ๐Ÿ• = [' ๐Ÿ˜ฟ ', ' ๐Ÿ ', ' ๐Ÿ‘ฉ ', ' ๐Ÿฅ ', ' ๐Ÿˆ ']

๐ŸŒƒ - ๐ŸŒ™ + ๐ŸŒž = [' ๐ŸŒš ', ' ๐ŸŒ— ', ' ๐Ÿ˜˜ ', '๐Ÿ‘ถ๐Ÿผ', ' โ˜น ']

๐Ÿ˜ด - ๐Ÿ›Œ + ๐Ÿƒ = [' ๐ŸŒž ', ' ๐Ÿ’ ', ' ๐ŸŒ ', ' โ˜ฃ ', ' ๐Ÿ˜š ']

๐Ÿฃ - ๐Ÿฏ + ๐Ÿฐ = [' ๐Ÿ’ฑ ', '๐Ÿ‘๐Ÿฝ', ' ๐Ÿ‡ง๐Ÿ‡ท ', ' ๐Ÿ”Œ ', ' ๐Ÿ„ ']

๐Ÿ’‰ - ๐Ÿฅ + ๐Ÿฆ = ['๐Ÿ’‡๐Ÿผ', ' โœ ', ' ๐ŸŽข ', ' ๐Ÿ“ฒ ', ' โ˜ช ']

๐Ÿ’Š - ๐Ÿฅ + ๐Ÿฆ = [' ๐Ÿ“ป ', ' ๐Ÿ˜ ', ' ๐ŸšŒ ', ' ๐Ÿˆบ ', '๐Ÿ‡ผ']

๐Ÿ˜€ - ๐Ÿ’ฐ + ๐Ÿค‘ = ['๐Ÿšต๐Ÿผ', ' ๐Ÿ‡น๐Ÿ‡ฒ ', ' ๐ŸŒ ', ' ๐ŸŒ ', ' ๐ŸŽฏ ']

License

The source code and all my pretrained models are licensed under the MIT license.

References

[1] Ben Eisner, Tim Rocktรคschel, Isabelle Augenstein, Matko Boลกnjak, and Sebastian Riedel. โ€œemoji2vec: Learning Emoji Representations from their Description,โ€ in Proceedings of the 4th International Workshop on Natural Language Processing for Social Media at EMNLP 2016 (SocialNLP at EMNLP 2016), November 2016.

[2] Jeffrey Pennington, Richard Socher, and Christopher D. Manning. "GloVe: Global Vectors for Word Representation," in Proceedings of the 2014 Conference on Empirical Methods In Natural Language Processing (EMNLP 2014), October 2014.

Owner
Miruna Pislar
Miruna Pislar
This is the repo for the paper `SumGNN: Multi-typed Drug Interaction Prediction via Efficient Knowledge Graph Summarization'. (published in Bioinformatics'21)

SumGNN: Multi-typed Drug Interaction Prediction via Efficient Knowledge Graph Summarization This is the code for our paper ``SumGNN: Multi-typed Drug

Yue Yu 58 Dec 21, 2022
PyTorch implementation of InstaGAN: Instance-aware Image-to-Image Translation

InstaGAN: Instance-aware Image-to-Image Translation Warning: This repo contains a model which has potential ethical concerns. Remark that the task of

Sangwoo Mo 827 Dec 29, 2022
Weakly Supervised Segmentation by Tensorflow.

Weakly Supervised Segmentation by Tensorflow. Implements semantic segmentation in Simple Does It: Weakly Supervised Instance and Semantic Segmentation, by Khoreva et al. (CVPR 2017).

CHENG-YOU LU 52 Dec 27, 2022
Leaderboard and Visualization for RLCard

RLCard Showdown This is the GUI support for the RLCard project and DouZero project. RLCard-Showdown provides evaluation and visualization tools to hel

Data Analytics Lab at Texas A&M University 246 Dec 26, 2022
Repo for Photon-Starved Scene Inference using Single Photon Cameras, ICCV 2021

Photon-Starved Scene Inference using Single Photon Cameras ICCV 2021 Arxiv Project Video Bhavya Goyal, Mohit Gupta University of Wisconsin-Madison Abs

Bhavya Goyal 5 Nov 15, 2022
A flexible ML framework built to simplify medical image reconstruction and analysis experimentation.

meddlr Getting Started Meddlr is a config-driven ML framework built to simplify medical image reconstruction and analysis problems. Installation To av

Arjun Desai 36 Dec 16, 2022
The source code of CVPR 2019 paper "Deep Exemplar-based Video Colorization".

Deep Exemplar-based Video Colorization (Pytorch Implementation) Paper | Pretrained Model | Youtube video ๐Ÿ”ฅ | Colab demo Deep Exemplar-based Video Col

Bo Zhang 253 Dec 27, 2022
Source code for "Roto-translated Local Coordinate Framesfor Interacting Dynamical Systems"

Roto-translated Local Coordinate Frames for Interacting Dynamical Systems Source code for Roto-translated Local Coordinate Frames for Interacting Dyna

Miltiadis Kofinas 19 Nov 27, 2022
Official PyTorch implementation of "Evolving Search Space for Neural Architecture Search"

Evolving Search Space for Neural Architecture Search Usage Install all required dependencies in requirements.txt and replace all ..path/..to in the co

Yuanzheng Ci 10 Oct 24, 2022
Automatic Number Plate Recognition using Contours and Convolution Neural Networks (CNN)

Cite our paper if you find this project useful https://www.ijariit.com/manuscripts/v7i4/V7I4-1139.pdf Abstract Image processing technology is used in

Adithya M 2 Jun 28, 2022
A PyTorch toolkit for 2D Human Pose Estimation.

PyTorch-Pose PyTorch-Pose is a PyTorch implementation of the general pipeline for 2D single human pose estimation. The aim is to provide the interface

Wei Yang 1.1k Dec 30, 2022
HomeAssitant custom integration for dyson

HomeAssistant Custom Integration for Dyson This custom integration is still under development. This is a HA custom integration for dyson. There are se

Xiaonan Shen 232 Dec 31, 2022
Romanian Automatic Speech Recognition from the ROBIN project

RobinASR This repository contains Robin's Automatic Speech Recognition (RobinASR) for the Romanian language based on the DeepSpeech2 architecture, tog

RACAI 10 Jan 01, 2023
NLU Dataset Diagnostics

NLU Dataset Diagnostics This repository contains data and scripts to reproduce the results from our paper: Aarne Talman, Marianna Apidianaki, Stergios

Language Technology at the University of Helsinki 1 Jul 20, 2022
็™พๅบฆ2021ๅนด่ฏญ่จ€ไธŽๆ™บ่ƒฝๆŠ€ๆœฏ็ซž่ต›ๆœบๅ™จ้˜…่ฏป็†่งฃPytorch็‰ˆbaseline

้กน็›ฎ่ฏดๆ˜Ž: ็™พๅบฆ2021ๅนด่ฏญ่จ€ไธŽๆ™บ่ƒฝๆŠ€ๆœฏ็ซž่ต›ๆœบๅ™จ้˜…่ฏป็†่งฃPytorch็‰ˆbaseline ๆฏ”่ต›้“พๆŽฅ:https://aistudio.baidu.com/aistudio/competition/detail/66?isFromLuge=true ๅฎ˜ๆ–น็š„baseline็‰ˆๆœฌๆ˜ฏๅŸบไบŽpaddlepadd

ๅ‘จไฟŠ่ดค 54 Nov 23, 2022
Home repository for the Regularized Greedy Forest (RGF) library. It includes original implementation from the paper and multithreaded one written in C++, along with various language-specific wrappers.

Regularized Greedy Forest Regularized Greedy Forest (RGF) is a tree ensemble machine learning method described in this paper. RGF can deliver better r

RGF-team 364 Dec 28, 2022
BMW TechOffice MUNICH 148 Dec 21, 2022
Self-Supervised Learning of Event-based Optical Flow with Spiking Neural Networks

Self-Supervised Learning of Event-based Optical Flow with Spiking Neural Networks Work accepted at NeurIPS'21 [paper, video]. If you use this code in

TU Delft 43 Dec 07, 2022
Self-Correcting Quantum Many-Body Control using Reinforcement Learning with Tensor Networks

Self-Correcting Quantum Many-Body Control using Reinforcement Learning with Tensor Networks This repository contains the code and data for the corresp

Friederike Metz 7 Apr 23, 2022
ILVR: Conditioning Method for Denoising Diffusion Probabilistic Models (ICCV 2021 Oral)

ILVR + ADM This is the implementation of ILVR: Conditioning Method for Denoising Diffusion Probabilistic Models (ICCV 2021 Oral). This repository is h

Jooyoung Choi 225 Dec 28, 2022