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 more
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
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.
%matplotlib inlineimport scipy.io.wavfileimport matplotlib.pyplot
scipy.io.wavfile. read (‘specgram.wav’)(spectrum, freqs, t, image)= matplotlib.pyplot. specgram(data)image
AxesImage at 0x7efc4c182150>
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-
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.
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-
10 Okay, that is spiffy.
11 A non-
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.