Python Argument Surprise

Python function signatures are flexible, complex beasts, allowing for positional, keyword, variable, and variable keyword arguments (and parameters). This can be extremely useful, but sometimes the intersection between these features can be confusing or even surprising, especially on Python 2. What do you expect this to return?

>>> def test(arg1, **kwargs):
...     return arg1
>>> test(**{'arg1': 42})
...

Read more…


Introducing nti.fakestatsd

Lately at NextThought we've been much more focused on using application level metrics to proactively monitor and understand the run-time characteristics of our applications. Much of the open source stack we are built on top of is already instrumented with the great perfmetrics library. Because of this, when it was time to expand the metrics we collected, perfmetrics was the obvious choice. However we quickly ran into a problem. How should we test the metrics we generated were actually emitted as the StatsD metrics we expected?

Read more…


Getting Started With Python inside PostgreSQL

PostgreSQL uses the tagline "the world's most advanced open source relational database." For PostgreSQL, part of being "advanced" means supporting multiple server-side procedural languages, both built-in and provided by third parties. Luckily for us here at the blog, one of the built-in languages is Python. Unluckily, it's not completely obvious how to get started using Python inside PostgreSQL. This post will provide a short walkthrough demonstrating how to do that. It's written for macOS, but many of the steps are generic.

Read more…


My Three Introductions to Open Source

I didn't particularly enjoy my first introductions to open source:

Later I found out I wasn't alone. This tweet ended up in a conference talk about how contributing to open source is a hassle:

So what makes starting out in open source so difficult?

Read more…


CPython vs PyPy Memory Usage

If you have lots of "small" objects in a Python program (objects which have few instance attributes), you may find that the object overhead starts to become considerable. The common wisdom says that to reduce this in CPython you need to re-define the classes to use __slots__, eliminating the attribute dictionary. But this comes with the downsides of limiting flexibility and eliminating the use of class defaults. Would it surprise you to learn that PyPy can significantly, and without any effort by the programmer, reduce that overhead automatically?

Let's take a look.

Read more…



Making It Up: Generative Adversarial Networks

Goodfellow et al. at Google Brain published Generative Adversarial Nets (GANs) in 2014 that turned the machine learning world on its side. In the past, neural networks had only been used for classification and regression, but these researchers developed a way to generate synthetic data that looks at least somewhat real. Nvidia submitted a study early into this development that generated fake celebrities. The major caveat was (and mostly still is) this methodology has only been applied to generating images using convolutional neural networks; however, more researchers are finding more expansive uses. In this post I will be using MNIST: a popular data set composed of thousands of handwritten numbers such as the following:

MNIST sample digits

Photo credit to GitHub user czala in repo https://github.com/cazala/mnist

I will first present the common architecture of a GAN as well as the theory behind its operation, followed by an example implementation that generates instances of these handwritten digits.

Read more…