This blog contains whatever random tech stuff I'm thinking about recently. And a lot of conference reports.

from future import everything

from future import everything

Did you know you can just import a sentiment analysis library, which will give you a rating of -1 to +1 on how positive or negative your text is? Did everyone know that? I realise that this is the entire point of language ecosystems, but I still get like "WHAT? CAN EVERYONE ELSE SEE THIS?" every time I use a library to predict the weather or give me subway arrival times or do some other thing that feels like it should have been harder.

Look at this. I pip installed textblob and ...

>>> from textblob import TextBlob
>>> TextBlob("oh no something terrible happened").sentiment
Sentiment(polarity=-1.0, subjectivity=1.0)
>>> TextBlob("hurray kittens are nice").sentiment
Sentiment(polarity=0.6, subjectivity=1.0)
>>> TextBlob("everyone is happy").sentiment
Sentiment(polarity=0.8, subjectivity=1.0)

The first one is very sad (-1.0). The second one is quite happy. (+0.6) and the third one positively upbeat. And they're all extremely (1.0!) subjective opinions, says TextBlob. I tried telling it that water was wet, and it reckons that's 0.4 subjective. I've been playing with it, trying to find an objectively positive sentence, and the best I can do is:

>>> TextBlob("happiness exists").sentiment
Sentiment(polarity=0.7, subjectivity=0.2)

Not bad. I have no idea what I want to do with a sentiment analyzer, but it doesn't matter because nothing would be as good as the chatbot a group made at FlawlessHacks a couple of years back, which augmented all text with an appropriate Beyonce emotion gif. This is clearly why code was invented.

TextBlob also does translation and lexical parsing and all sorts of things that seem to me like they should be too hard to just pip install a thing and have at it.  And yet here we are ¯\_(ツ)_/¯

The reason I started playing with TextBlob is another thing that was easier than expected: an extremely my-first-slackbot bot that I made last weekend. The excellent tutorial at  https://www.fullstackpython.com/blog/build-first-slack-bot-python.html walks you through setting up keys in the admin console of your slack and getting started with the API.

It's straightforward and good fun. I had a little chunk of code ("The least necessary 86 lines of python that have ever existed") responding to messages in a slack channel in under an hour, and that was immediately rewarding enough that I keep returning to it and adding other stupid stuff. You can see how sentiment analysis might seem like a good idea when you've taken a long weekend off work and you're just sitting around, right? (Right?) 

I'm running the bot (and a bunch of other toys and nonsense) on a GCE VM instance which costs less than a dollar a month. Add that to the list of things about this future that will continue to be witchcraft to me for a long time.

My slackbot (without any sentiment analysis because seriously, what was I thinking?) is at https://github.com/whereistanya/screambot

Banner image: frankie cordoba on Unsplash

It's called glossophobia!

It's called glossophobia!

Conference report: The Lead Developer NYC 2018

Conference report: The Lead Developer NYC 2018