Quick Tips: An Easy Way to Make Slideshows from Jupyter Notebooks

27 October 2015

Jupyter seems to be working towards support for converting notebooks to Reveal.js slideshows, but it’s not working quite yet, at least for me. Luckily, there’s a pretty easy way to turn your Jupyter notebooks into slideshows not only with Reveal, but also S5, DZSlides, Slidy, Slideous, or the latex beamer package: Pandoc.

Pandoc is a document converter that can read a good number of formats and turn them into an even greater number. The idea is to use nbconvert to convert your notebook to markdown—which, if anything, is Pandoc’s native language—and use Pandoc to convert to the slide format of your choice.

Here’s the one liner:

nbconvert --to markdown --stdout path/to/notebook.ipynb | pandoc -Ss -t revealjs -o slides.html

The -Ss handles smart quotes and produces a standalone file. You can change the -t format to whatever slide engine you want. If you would like your lists to appear incrementally, add the -i flag to the pandoc command, like so:

nbconvert --to markdown --stdout path/to/notebook.ipynb | pandoc -Ssi -t revealjs -o slides.html

This works well for me with images and code blocks. You do have to keep in mind the way Pandoc parses markdown for slides, but it’s pretty simple. The thing to keep in mind is that the highest-level header that is followed by non-header content is the slide-level title, the level above that becomes the section-level title, and levels below that are in-slide headers. You can actually get a fair amount of customization with Pandoc options, like the location of the slide libraries or slide themes, but I’ll leave that as an exercise for the reader.

Donald Trump's Tax Plan in Two Charts

01 October 2015

A few days ago, Donald Trump released his new tax plan. This morning, the Tax Foundation released its analysis, which found that (with a dynamic model) the plan would lead to a 11 percent higher long-term GDP, but also significantly increase the deficit.

The Tax Foundation’s analysis is all well and good, but it doesn’t pay enough attention to some of the more interesting aspects of Trump’s plan. So I figured, hey, macroeconomic modeling is basically lame data science, right? And I did my own.

First, one distinctive feature of the tax plan is that low-earners would pay no taxes. Instead of filing a return, they would send in a piece of paper that says I Win. I modeled the number of Americans who would be winning before and after Trump’s tax plan:

I Win!

I find that the number of winning Americans goes up about 300 million fold after the implementation of Trump’s tax plan. Note that, before implementation, the number of winning Americans is not quite zero; that’s because Donald Trump is, and has historically been, winning. He is a winner and he wins.

Second, Trump’s plan is focused on making America great again. I modeled Gross National Greatness, with these results:

Great

Note that the sharp decline in greatness seen since 2000 is completely reversed after implementation of Trump’s plan. In fact, the level of greatness achieved is higher than that seen since 2000. However, I should caution that these results should not be over-interpreted; some portion of the expected increase in greatness is likely due to other greatness-reviving policies of the Trump administration.

Review: The Book of Strange New Things

28 September 2015

It has been popular to say that The Book of Strange New Things, the latest and perhaps last novel by Michel Faber, defies genre. It does not; the book falls well within the realm of science fiction. Perhaps the confusion comes from a reluctance to acknowledge science fiction as good literature, which the book certainly is—a phenomenon neither strange nor new.

Like all good science fiction, Strange New Things lets the science serve the fiction. Yes, a spaceman goes to space and does space things, but the focus stays on the spaceman. This particular spaceman is Peter Leigh, a self-described lefty pastor. Peter has, after an arduous interview process, been selected by the inscrutable mega-corporation USIC to serve as missionary to the native creatures of the planet Oasis, where USIC has established a base.

While on Oasis, Peter can only communicate with his wife Bea through a text-only email-like terminal, called a chute. From Peter’s arrival on the new planet, the novel consists of conversations and observations in three settings: first, the letters with Bea, who describes for Peter an increasing drumbeat of disaster on Earth; second, the USIC base, where Peter tries, with varying success, to understand the friendly but detached personnel; and third, the Osirans, in whom Peter finds a receptive audience, but with whom he struggles to connect on a deeper level.

These conversations dwell on common themes: God, prayer, suffering, tough childhoods, estrangement, reconciliation, and hope. Some of them are better than others.

It is depressing, as you read, to wonder whether Faber actually believes that Christians spend most of their time explaining basic theological ideas and quoting Bible verses to each other, or whether he has inserted these ideas into the dialogue to introduce them to readers who don’t realize that Christianity contains ideas. And it is no less depressing to wonder whether Peter and Bea’s watery Christianity arises from the author’s ignorance of it or, worse, his acquaintance with it.

In any case, the Peter preaches a neutered faith. I try to treat people the way Jesus would have, he explains toward the end of the book, that’s Christianity to me. Of course, that’s not Christianity at all. Christianity necessarily includes ideas like sin, and hell and crucifixion and resurrection and salvation and redemption. Peter seems to believe in these things, but seems in no hurry to convey them to his converts.

The Christian concepts explored in depth don’t fare any better. Early in the book, for example, Peter and Bea both refer to the apostle Paul as having trouble with women, ignoring the many women he celebrated in his epistles. John the Baptist, to Peter, was just another pastor, while to Christ he went forth in the spirit and power of Elijah. The discussion of prayer reeks of vapidity. In the last part of the book, it’s clear that Peter, with his supposedly encyclopedic knowledge of scripture, has somehow glossed over the book of Job.

Even with these criticism, it is clear that Faber, an atheist, has tried to give Christianity a fair shot in the book. Peter is not a fool or a charlatan, as authors more afraid of Christianity tend to write pastors. He is believably good man and a faithful Christian one, if you squint a bit, who is faced with a universe that he struggles to comprehend. There is real flesh on the bone.

That weak flesh, far more than the willing spirit, makes the book work. When the punches come—a bit suddenly, perhaps—they hit hard. The isolation, the apparently insuperable failures of communication into which Peter sinks are imminently familiar, no matter how fantastic the setting.

Some reviewers have compared Strange New Things to another work of good, science fiction literature: A Canticle for Liebowitz. But the similarities—both feature religious figures and disaster—are superficial. A book about an order of steadfast monks cannot share too much with a book where the ongoing state of a marriage drives the action. Strange New Things more truly recalls Ingmar Bergman’s The Seventh Seal—a poignant search for a God who seems to remain silent while earthly suffering abounds.

Like The Seventh Seal, and indeed like Job, Strange New Things focuses more on questions than answers. And if the questions are familiar and old, there is, perhaps, a reason we keep asking them.

The Book of Strange New Things

Michel Faber

Hogarth

528 pp.

Audiobook Note: The Random House recording of the book is, for the most part, merely competent and professional, but reader Josh Cohen brings particular skill to the intentionally difficult Osiran dialogue. In lesser hands, the absurdity could have become comic, but Cohen achieves the earnestness the text deserves.