This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import keras.backend as K | |
def recall(y_true, y_pred): | |
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1))) | |
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1))) | |
recall = true_positives / (possible_positives + K.epsilon()) | |
return recall | |
def precision(y_true, y_pred): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from gensim.models import KeyedVectors, Word2Vec | |
from gensim.models.fasttext import FastText as FT_gensim | |
from nltk.tokenize import sent_tokenize, word_tokenize | |
import json | |
import pandas as pd | |
from tqdm import trange | |
W2V_PATH = 'data/GoogleNews-vectors-negative300.bin' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%time | |
clusters = dbscan.fit(doc2vec_list) | |
cl_labels = clusters.labels_.tolist() | |
def wordcloud_cluster_byIds(cluId): | |
texts = [] | |
for i in range(0, len(cl_labels)): | |
if cl_labels[i] == cluId: | |
for word in word_tokenize(dialogs_concatted.iloc[i].TEXT): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc_embedding(text): | |
tokens = word_tokenize(text) | |
vec = np.zeros(100) | |
num_tokens = 0 | |
for token in tokens: | |
if token in stopwords_list: | |
continue | |
if token in new_model: | |
vec += new_model[token] | |
num_tokens += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
translator = str.maketrans('', '', re.sub(r'[\?-]', '', string.punctuation+'«»”“', flags=re.MULTILINE)) | |
def clear_punctuation(sentence): | |
return sentence.translate(translator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tqdm import tqdm_notebook | |
tqdm_notebook().pandas() |
NewerOlder