The Simplest Deep Learning Program That Could Possibly Work

Once upon a time, when I, a C programmer, first learned Smalltalk, I remember lamenting to J.D. Hildebrand “I just don’t get it: where’s the main()?” Eventually I figured it out, but the lesson remained: Sometimes when learning a new paradigm, what you need isn’t a huge tutorial, it’s the simplest thing possible.

With that in mind, here is the simplest Keras neural net that does something “hard” (learning and solving XOR) :

import numpy as np
from keras.models import Sequential
from keras.layers.core import Activation, Dense
from keras.optimizers import SGD

# Allocate the input and output arrays
X = np.zeros((4, 2), dtype='uint8')
y = np.zeros(4, dtype='uint8')

# Training data X[i] -> Y[i]
X[0] = [0, 0]
y[0] = 0
X[1] = [0, 1]
y[1] = 1
X[2] = [1, 0]
y[2] = 1
X[3] = [1, 1]
y[3] = 0

# Create a 2 (inputs) : 2 (middle) : 1 (output) model, with sigmoid activation
model = Sequential()
model.add(Dense(2, input_dim=2))
model.add(Activation('sigmoid'))
model.add(Dense(1))
model.add(Activation('sigmoid'))

# Train using stochastic gradient descent
sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='mean_squared_error', optimizer=sgd)

# Run through the data `epochs` times
history = model.fit(X, y, epochs=10000, batch_size=4, verbose=0)

# Test the result (uses same X as used for training)
print (model.predict(X))

If you run this, there will be a startup time of several seconds while the libraries load and the model is built, and then you will start to see output from the call to fit. After the data has been run through 10,000 times, the model will then try to predict the output. As you’ll see, the neural network has learned the proper set of weights to solve the XOR logic gate.

Now draw the rest of the owl.

“The Deuce” Stinks. A Rant.

I’m a hair’s-breadth away from declaring that “The Deuce,” HBO’s Sunday night “prestige drama” about flesh-peddling and pornos in Times Square and 42nd Street in the mid-70s, is an exercise in trolling, some kind of meta-level commentary on the lack of drama, characterization, or stakes in, y’know, pornos. It’s almost easier to believe that David Simon — the creator of “The Wire” FFS! — is engaged in some kind of multimillion-dollar performance art than that he’s presiding over a writing room as sloppy and listless (dare I say, “flaccid”?) as that churning out the scripts for this season.

The over-arching problem is that there’s no goddamn conflict: the characters just appear, smoke, have breakfast or a Dewar’s on the rocks, smoke, engage in the boring routine of their flesh-peddling, smoke, pour themselves another drink, and then we cut away to another character. I mean, my God, what was going on with James Franco and the dry-cleaning store he owned for two episodes? Why did we spend five minutes jazzing around in the JFK parking lot to establish “she’s going to LA alone because he’s scared of flying”?

Maggie Gyllenhaal says in one scene that her Little Red Riding Hood porno (are we supposed to gasp in wonder at the visionary genius?) will cost hundreds of thousands. Then the next time we see here she’s being offered $10K for 10% and a blowjob, which she gives, and what are we supposed to feel? “Boohoo, despite her ambitions she can’t escape the expectation that she’s a whore?” “Hooray, she’s doing what she has to do to realize her dream?” I dunno’. I don’t care. I mean, I could care if the writer’s decided to engage in character development rather than just moving on to the next damn thing.

I’ve watched something like 14 hours of this show on the strength of the writing talent of Simon and Pellecanos. That’s enough time to bring a lot of strands together, to get a lot of plots up to a rolling boil. But instead we’re halfway through the second season and goddam Lawrence Gilliard is walking in to a situation, taking it in, walking out, and then having the same damn conversation about how things never change. Yeah, you’re telling me, D’Angelo.

The first season was set in 1972, the “Walk On The Wild Side” pre-punk era, but the second jumped forward five years, to a 1977 that, contra reality, has Talking Heads, Elvis Costello, and The Damned as the soundtrack. (There were parts of NYC where that might have been the sound track, but they sure as hell weren’t mid-town discos.) One episode had a thirty-something musician quoting Rilke and Rimbaud and handing the plotless female bartender an album, which a sharp-eyed viewer can see was Jim Carroll’s “Catholic Boy,” released in 1980. Carroll you may remember from the song “Those Are People Who Died” but in 1977 the real Jim Carroll was not a musician but a poet struggling with heroin addiction. He didn’t start singing until he moved to California in 1978. All of which is trivial, but they’re the ones who decided to have this scene and we viewers are supposed to make sense of it and even if you know all about Jim Carroll, the scene is pointless. (And, by the way, Jim Carroll would have been a freakish red-haired beanpole friendly with everyone from Patti Smith to Keith Richards and would be an excellent character in a series about the bizarre confluence of high- and low- culture in mid-70s NYC which is a setting ripe for drama despite the evidence of “The Deuce.”)

Finally, and I understand that no one will ever get this far in this post, and it really neither supports nor refutes my thesis, but every time “The Deuce” opening credits end, and there is a shot of a building facade reflected in a puddle through which a foot walks, I get pissed off, because that’s a total rip-off of the closing shot in the opening credits for “Deadwood” and if there’s one thing that’s clear about “The Deuce” it’s that they don’t have David Milch writing for them.