My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a...

19
Baby steps in a short-text classification with python My personal horror story Alisa Dammer me: alisadammer.com @FedorinoGore 90 July 12, 2017

Transcript of My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a...

Page 1: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Baby steps in a short-text classification with pythonMy personal horror story

Alisa Dammerme: alisadammer.com

@FedorinoGore 90

July 12, 2017

Page 2: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Structure

Initial information collection

Award winning model

Going live

Did I learn anything?

Questions?

Page 3: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

What can I do with a text

I Part of the speech tagging

I syntax model

I classification

I text generation

I translation

Binary classification it is!

Page 4: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

What can I use?

Topic1Topic2

Topic3

We are a great company working in the health care sector.We are searching for a secretary for our chief doctor.

We want you to work with papers answer calls, make coffee.The salary is good!

Page 5: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

KLDB vs ISCO

43412Informatics, Software development, Assistant/low level complexity

43494Informatics, Software development, CTO, Tech Lead

Page 6: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Basic tools

I nltk

I sci-kit

I gensim

Page 7: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Evaluation tools

actual

predicted

p n

p

TruePositive

FalseNegative

n

FalsePositive

TrueNegative

Page 8: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Let the evaluation begin!

I Bernoulli classification

I Naive Bayesian

I Support Vector Machine

I Decision Tree

Page 9: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Tuning up

I Tweak data set as a whole

I Tweak each item in the data set

Page 10: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Tweaking the item

I Add information

I Remove information

I Stemm the crap out of it

Page 11: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Data transformed!

Page 12: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Some output

import nltk.NaiveBayesClassifier as nbcdef build_nb(train):

modelTrained = nbc.train(train)return modelTrained

def train_nb():sample = load("path/filename")train, test = splitSample(sample, 0.7)train = formatForNLTK(train, True, lang)test = formatForNLTK(test, True, lang)model = build_nb(train)getEstimationResults(model, test, labels)savePickle("models/classify.pkl", model)

Page 13: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Every day we’re modelling

Time required to train NB is 0.6297673170047347General TP is 224General FP is 119overall accuracy is 0.6530612244897959confusion matrix is[[ 53 32 0][ 16 112 0][ 0 0 0]]

Page 14: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Doooooom!

Page 15: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Reconnection

I Jython

I Starting python scripts inside of the java code

I Rewrite in Java

I Message brokers

I REST

Page 16: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Deployed with GUnicorn

...model = readPickle("model.pkl")@app.route('/classify', methods=['POST'])def classify():

formatted = {}results = {}if request.method == "POST":

item, lang = validate(request)if lang != expected:

error_response(lang, model)else:

formatted[model.label] = [item]classify(results, formatted, lang, model, model.label)logging.info("Classified!")return jsonify(results)

Page 17: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Is the problem solved?

I Spend more time on base research

I Don’t go too deep

I Try graphs first

I Don’t be afraid to change the data itself

I Monitoring over historical data

I Have a minimal quality test

I Cross validation is a thing

Page 18: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Thanks for the patience!

Page 19: My personal horror story Alisa Dammer me: alisadammer.com … · 2017-07-12 · Baby steps in a short-text classi cation with python My personal horror story Alisa Dammer me: alisadammer.com

Maybe useful informationTutorials:

I https://pythonprogramming.net/naive-bayes-classifier-nltk-tutorial/I http://www.nltk.org/book/ch06.htmlI http://scikit-learn.org/stable/tutorial/text_analytics/working_with_

text_data.htmlI http://scikit-learn.org/stable/modules/svm.htmlI http://www.nltk.org/_modules/nltk/metrics/confusionmatrix.html

Basic:I http://www.linguistics.fi/julkaisut/SKY2006_1/1.6.6.%20NIVRE.pdfI http:

//blog.josephwilk.net/projects/latent-semantic-analysis-in-python.htmlI https://rstudio-pubs-static.s3.amazonaws.com/79360_

850b2a69980c4488b1db95987a24867a.htmlI https://www.kaggle.com/c/word2vec-nlp-tutorial/details/

part-1-for-beginners-bag-of-words

Deep:I https://arxiv.org/pdf/1408.5882v2.pdfI http://karpathy.github.io/neuralnets/I http://course.fast.ai/lessons/lesson2.html