Skip to content

Instantly share code, notes, and snippets.

View sismetanin's full-sized avatar

Sergey Smetanin sismetanin

  • Snap
  • London
View GitHub Profile
System P R F1
MNB 87.01% 81.22% 83.21%
BiLSTM 86.56% 86.65% 86.59%
M−BERT_BASE−Toxic 91.19% 91.10% 91.15%
ruBert−Toxic 91.91% 92.51% 92.20%
M−USE_CNN−Toxic 89.69% 90.14% 89.91%
M−USE_Trans−Toxic 90.85% 91.92% 91.35%
@inproceedings{
smetanin-2019-emosense,
title = "{E}mo{S}ense at {S}em{E}val-2019 Task 3: Bidirectional {LSTM} Network for Contextual Emotion Detection in Textual Conversations",
author = "Smetanin, Sergey", booktitle = "Proceedings of the 13th International Workshop on Semantic Evaluation",
year = "2019",
address = "Minneapolis, Minnesota, USA",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/S19-2034", pages = "210--214"
}
from keras.layers import Input, Dense, Embedding, Concatenate, Activation, \
Dropout, LSTM, Bidirectional, GlobalMaxPooling1D, GaussianNoise
from keras.models import Model
def buildModel(embeddings_matrix, sequence_length, lstm_dim, hidden_layer_dim, num_classes,
noise=0.1, dropout_lstm=0.2, dropout=0.2):
turn1_input = Input(shape=(sequence_length,), dtype='int32')
turn2_input = Input(shape=(sequence_length,), dtype='int32')
turn3_input = Input(shape=(sequence_length,), dtype='int32')
def getEmbeddings(file):
embeddingsIndex = {}
dim = 0
with io.open(file, encoding="utf8") as f:
for line in f:
values = line.split()
word = values[0]
embeddingVector = np.asarray(values[1:], dtype='float32')
embeddingsIndex[word] = embeddingVector
dim = len(embeddingVector)
from ekphrasis.classes.preprocessor import TextPreProcessor
from ekphrasis.classes.tokenizer import SocialTokenizer
from ekphrasis.dicts.emoticons import emoticons
import numpy as np
import re
import io
label2emotion = {0: "others", 1: "happy", 2: "sad", 3: "angry"}
emotion2label = {"others": 0, "happy": 1, "sad": 2, "angry": 3}
def preprocessData(dataFilePath, mode):
conversations = []
labels = []
with io.open(dataFilePath, encoding="utf8") as finput:
finput.readline()
for line in finput:
line = line.strip().split('\t')
for i in range(1, 4):
line[i] = tokenize(line[i])
if mode == "train":
Snackbar.make(
rootView,
"An update has just been downloaded from Google Play",
Snackbar.LENGTH_INDEFINITE
).apply {
setAction("RELOAD") { appUpdateManager.completeUpdate() }
show()
}
// Create a listener to track downloading state updates.
val listener = InstallStateUpdatedListener { state ->
// Update progress indicator, request user to approve app reload, etc.
}
// At some point before starting an update, register a listener for updates.
appUpdateManager.registerListener(listener)
// ...
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
AppUpdateType.FLEXIBLE,
activity,
0
)
// Create instance of the IAU manager.
val appUpdateManager = AppUpdateManagerFactory.create(context)
// Add state listener to app update info task.
appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo ->
// If there is an update available, prepare to promote it.
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
// ...
}