r/MachineLearning • • Jul 03 '17

Discussion [D] Why can't you guys comment your fucking code?

Seriously.

I spent the last few years doing web app development. Dug into DL a couple months ago. Supposedly, compared to the post-post-post-docs doing AI stuff, JavaScript developers should be inbred peasants. But every project these peasants release, even a fucking library that colorizes CLI output, has a catchy name, extensive docs, shitloads of comments, fuckton of tests, semantic versioning, changelog, and, oh my god, better variable names than ctx_h or lang_hs or fuck_you_for_trying_to_understand.

The concepts and ideas behind DL, GANs, LSTMs, CNNs, whatever – it's clear, it's simple, it's intuitive. The slog is to go through the jargon (that keeps changing beneath your feet - what's the point of using fancy words if you can't keep them consistent?), the unnecessary equations, trying to squeeze meaning from bullshit language used in papers, figuring out the super important steps, preprocessing, hyperparameters optimization that the authors, oops, failed to mention.

Sorry for singling out, but look at this - what the fuck? If a developer anywhere else at Facebook would get this code for a review they would throw up.

  • Do you intentionally try to obfuscate your papers? Is pseudo-code a fucking premium? Can you at least try to give some intuition before showering the reader with equations?

  • How the fuck do you dare to release a paper without source code?

  • Why the fuck do you never ever add comments to you code?

  • When naming things, are you charged by the character? Do you get a bonus for acronyms?

  • Do you realize that OpenAI having needed to release a "baseline" TRPO implementation is a fucking disgrace to your profession?

  • Jesus christ, who decided to name a tensor concatenation function cat?

1.7k Upvotes

471 comments sorted by

View all comments

189

u/crazylikeajellyfish Jul 03 '17 edited Jul 04 '17

I don't know what makes you think developers in one of the fastest-moving, highly demanded spaces (JS-based web dev) are inbred peasants, but that's beside the point.

Code quality is probably lower in ML because lots of it comes out of academia, which is notorious for bad code. Most of these people aren't software engineers, they're domain specialists who write code when they have to. They're also writing code to publish papers, not to build an evolving product with a team that will grow over time. Their shit doesn't need to work forever on anyone's machine, it needs to work once on their setup so they can spit out some results. Those requirements don't make best practices seem important.

7

u/[deleted] Jul 04 '17

I'd take this argument a step further actually, and likely step on some toes: Many people from academia write bad code, not only because they had no incentive during their studies to write good code, but also because many of those people are actually incapable of doing so.

Academia these days is all about specialization, so it breeds a lot of "depth first" people who hone into one tiny aspect of the science, but have no vision or perception of what's going on around them. A good software engineer is the exact opposite; good code cleanly interacts with a very flexible surrounding, and at the same time exhibits structural clarity that fosters understanding by peers. It's the antithesis of research essentially.

2

u/INDEX45 Jul 05 '17

Part of this is historical. CS is popular now, and it pays well, so it draws in people in undergrad who haven't had a lot of experience. They take CS courses that are only partly related to actual programming, then go to grad school where there is even less emphasis on programming. You end up with people who are nominal experts in their field but couldn't code themselves out of a wet paper bag. And their code quality is exactly what you'd expect, low quality, spaghetti, poor variable naming, poor abstraction, little documentation, little consistency, etc.

Whereas perhaps before the dot com boom, by the time most of those people made it to undergrad, they had already been programming for years.

Academics these days are very much like a fresh grad student entering the workforce, except they don't, and so their code quality remains at that level for years and years because there is no pressure to write better code.

→ More replies (1)

46

u/Mr-Yellow Jul 03 '17

They're also writing code to publish papers

Believe the culture needs to shift to "Code or it didn't happen".

"They're writing code because publishing demands it"

Where your paper doesn't practically exist for the community unless you actually published all of it, not only a high-level description. Where the standard is high and people make better attempts to meet that standard.

Where an academic feels embarrassed to release what would be considered an incomplete paper, one lacking actual experiments, actual code. Forcing academia to get real. To publish completely their findings, tweaks, hyper-parameters and other methods.

Results aren't good enough, we have to see how you got those results. Might be there was something magic in there that you didn't see or write about in the paper. Too often this science can't be duplicated without long communications with the author discovering all the critical things which were left out of the paper.

18

u/local_minima_ Jul 04 '17

Agree with the sentiment, but disagree with this shift. I believe Google still has the best MapReduce system out there, despite the paper having been published and countless attempts to reproduce it. "Code or it didn't happen" would probably mean it wouldn't have happened at all. Perfectly reasonable for an industry research lab to release the big ideas in a paper to move the field forward, but leave the nitty gritty details of implementation out.

5

u/[deleted] Jul 04 '17

What are the superior features of the Google MapReduce implementation?

4

u/XYcritic Researcher Jul 04 '17

There's always going to be multiple ways to publish, including Arxiv, so that's not really a concern.

→ More replies (2)

3

u/JanneJM Jul 04 '17

So change the incentives. Make research grants depend on doing this. Which means you need to make published code count on your CV along with papers; and it means adding money to grants for maintaining software after the project has ended.

And both of those means you (as in the research community and grant agencies/the state) have to agree and accept that you will get less science for the money. More time and money will be spent on software development and maintenance, and that will necessarily come from money that would have gone towards research projects and grad students.

2

u/Mr-Yellow Jul 04 '17

less science for the money

Will it really be though?

What if half of the stuff you used had already been created previously (and published) meaning you didn't need to re-implement it along the way?

maintaining software

Do you really need to maintain it though?

RatSLAM hasn't been touched since it was uploaded in 2011, even with googlecode dying a slow death it still exists and is still published.

→ More replies (1)
→ More replies (2)

27

u/didntfinishhighschoo Jul 03 '17

That’s my go-to explanation as well, but I think the way to fix it – just as it was in the JS community – is to make ML researchers realize the value of their code and presentation to market themselves and their research. Karpathy is a star because his shit is accessible, not because his ideas are one of a kind. Think about the internet-famous people in the JS community: they work on tools, on frameworks, they write blog posts. If you're a new developer they (and the ethos) tell you to write a few posts, contribute to open-source, write a library, answer questions on StackOverflow. The ants build a system. If you're an up and coming ML researcher, what's the plan? publish, publish, publish? Get cited? That's a shit-show of an incentives system.

41

u/htrp Jul 03 '17

Publish publish publish ==> tenure. It's why most large firms are hiring ml research roles and also ml engineer roles

19

u/epicwisdom Jul 03 '17

Actually, I think this is good reason to believe that coding culture in ML will change quickly and soon. There's quite a bit of intermixing of industry and academia, so better coding practices and project management in general might result. But this is mostly dependent on the openness of industry and how many people go back from industry to academia.

→ More replies (2)

4

u/VelveteenAmbush Jul 04 '17

Sincerely curious, what proportion of ML PhD grad students envision tenure as their career path? I had assumed that most of them largely planned to go into industry but I guess that's because I've been relatively closer to industry than academia and these past few years in particular have been white-hot in terms of industry demand for ML talent, and maybe that will wane once the population of ML researchers reaches equilibrium.

9

u/[deleted] Jul 04 '17

You can't compare new JS developments with ML developments. They are fundamentally different with different goals, despite the fact that ML is achieved through programming. ML is an area of scientific research and discovery, and new advances are described mathematically- we just need to coax a computer to do the math because it would be too cumbersome to do by hand. JS frameworks are tools for the sake of helping other programmers quickly make things for consumption by end-users with expectations of usability, consistency, and stability. It's not research, and it can't be described mathematically even if you wanted to. Completely different purposes mean the two have completely different focuses.

For another perspective, I was doing (quantitative) graduate research before I learned to program or learned about ML. ML research papers have always seemed very approachable to me. New software frameworks (including well-documented ones), on the other hand, have often frustrated the hell out of me because I couldn't figure out how to get the information I needed. Realize that you have become an expert at acquiring information when it's communicated a certain way. A professional software developer and an academic researcher have very different ways of communicating information, and both have been refined for the different purposes and audiences that they hold.

→ More replies (6)

6

u/crazylikeajellyfish Jul 03 '17

Heh, I'm not disagreeing with you -- take it up with the people giving out grants, not the researchers. You're right, it boils down to incentives. Software engineers have incentive to market their code quality, it becomes jobs. Researchers have incentive to publish results, everything else is just nice. That said, I would expect code out of the Facebook Research team to be higher quality than other research groups -- it's not like they're fighting for funding.

3

u/stiffitydoodah Jul 04 '17

We don't get to choose the system we have to work in.

→ More replies (1)

12

u/pengo Jul 04 '17

Most of these people aren't software engineers, they're domain specialists who wrote code when they have to.

This is pretty much it but I hate this excuse. It's like "ooh, dearly little me, I'm just an academic, not a real software engineer! I can barely write code, so you can't expect me to go a step further and do all these complicated software engineering things like writing comments!"

10

u/dreugeworst Jul 04 '17

The problem is that the main product of an academic isn't his code or even his data: it's academic papers. They write as little code as possible as quickly as possible to get the data they need to publish that paper. Since their papers are maths-heavy, naming their variables in a maths-like way makes sense to them. Commenting beyond what's needed for themselves to be able to write a follow-up paper is unnecessary work for them.

4

u/DethRaid Jul 04 '17

I'm a software engineering major living with two math majors. I mentioned the poor code quality of math code to them and they said that they didn't want to use more than one character per variable because they were lazy and that was somehow a valid excuse for making code that is all but unreadable. I tried explaining to them that it's important to make your code readable so that other people can read it but they weren't having any of it. Seemed to me that the idea of code maintainability was something that they just didn't have.

8

u/JanneJM Jul 04 '17

To be fair, for 99% of academic software, nobody but the authors will ever use it, and the code is abandoned the moment the research project ends. If you are tight on time it makes little sense to spend it on making nice-looking code rather than getting another paper out the door.

8

u/nondetermined Jul 04 '17

math code
use more than one character per variable

If it's indeed math code, then using simple variables may actually be the right thing to do. Ideally they're much closer to math notation, and reading such code will be much nicer (there's a reason math notation makes heavy use of single char variables) - given those variables have been properly introduced.

3

u/OperaRotas Jul 04 '17

The problem is, most of the people working on ML research aren't math majors, but CS majors. You could expect a bit more from them.

→ More replies (1)
→ More replies (1)
→ More replies (2)