SpecGram Vol CLXXVII, No 4 Contents Linguimericks, Etc.—Book ३७

Sharper Than the Serpent’s Tooth1

A Letter from Associate Editor Pete Bleackley

At Speculative Grammarian, we make no secret of the fact that various members of the Editorial Team have been known to dip their toes into the waters of Computational Linguistics, and have even been known to receive payment for doing so. What is less well known is that disagreements occasionally arise between us about which programming language to use for the purpose. While the moreshall we say “experienced”?2computational linguists amongst us favour Perl,3 those with a more modern4 outlook advocate the use of Python.5

Python, of course, has many advantages.6 The clarity of the syntax, the wide range of scientific libraries available7... At this point, you might expect me to wax lyrical about NLTK, gensim, and other such bounties of the scientific Python ecosystem, but worthy as they are, it is matplotlib that I particularly wish to commend to your attention today.

“But Doctor Bleackley,” I hear you say8 (which is quite remarkable, since you are presumably reading this some time after I wrote it, and nowhere near me), “matplotlib is a plotting library. What makes it of particular interest to computational linguists?” Allow me to illustrate with the following code sample.

In:9

%matplotlib inline
import scipy.io.wavfile
import matplotlib.pyplot

(rate, data)=scipy.io.wavfile.read(‘specgram.wav’)
(spectrum, freqs, t, image)=matplotlib.pyplot.specgram(data)
image

Out:

<matplotlib.image.AxesImage at 0x7efc4c182150>

Figure 1: A spectrogram of “SpecGram”, rendered using specgram

As you can see, the function to compute and render the spectrogram is called specgram.10 What more could you ask for?11



1 If you are going to reference the classics, Pete, don’t forget this one: “Old age and treachery will always overcome youth and skill.” —Ed.-in-Chief

2 Did you misspell “employable” or maybe you should rephrase using “remunerative”?

3 Meh. The best tool is the one that gets the job done. Perl. Python. Unpaid interns.

4 “Oooolook at the shiny!”

5 “Eeek! I’m scared of braces!”

6 ’Tis true, but its attitude toward whitespace is not one of them.

7 The humility of its proponents.

8 As if anyone could hear anything over all the squealing about the braces.

9 Apologies to any devotees of python, who may lose their ever-lovin’ minds over the indentation should these lines of code happen to wrap. This is a linguistics journal, not an IDE.12

10 Okay, that is spiffy.

11 A non-pathological attitude toward whitespace, maybe?

12 One can only assume such Pythonistas use an IDE, and can’t code in vi13 like a real programmer.

13 I guess I’ll allow emacs, too, if I have to.

Linguimericks, Etc.Book ३७
SpecGram Vol CLXXVII, No 4 Contents