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

110

u/mikelewis0 Jul 05 '17

Hi Reddit, I'm first author on the paper whose code was mentioned above.

I just wanted to say that while I completely agree that the code could be improved, I'm really glad that we released it anyway. We'll be improving the codebase over time, but releasing something as soon as possible is much better than waiting for perfection. I feel like the main obstacle to people sharing code is that they're embarrassed about their hacky research code - and I'm not sure that threads like these are particularly helpful in that respect. Everyone, please keep releasing whatever code you have - anyone who has ever written a paper will understand :-)

3

u/didntfinishhighschoo Jul 05 '17

I'm really glad you released it as well. Sorry again for singling this paper out. It's way above average paper and release. Still, putting in a few hours to clean things up and spruce the technical documentation as part of the release process would mean it will be much more accessible to thousands of engineers and researchers, not to mention the rest of the benefits.

50

u/divinho Jul 05 '17

I think the code is fine. OP just seems like an idiot.

14

u/TotsNotRussianSIGINT Jul 16 '17

Check the date of the last commit. And then feel like an idiot.

5

u/divinho Jul 17 '17 edited Jul 17 '17

When I was reading it that wasn't there yet. I only posted a comment after all the upvotes came in.

→ More replies (1)

3

u/ClydeMachine Jul 07 '17

Since others don't appear to have mentioned it, thank you for going back and adding in all the docstrings (if that indeed was you). It is much appreciated.

→ More replies (1)

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.

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.

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.

2

u/didntfinishhighschoo Jul 04 '17

The difference is that one of these methods can run by anyone anywhere, and the other requires arcane knowledge, logical jumps, and can only be run inconsistently, uniquely, in people’s heads. I can't believe people have a working executable proof of their work and they throw it away because apparently a brief description in natural language is enough. This attitude makes research slower.

11

u/[deleted] Jul 04 '17

You're still missing the point. The value of research isn't in the code, it's in the math. Research papers are not intended to be consumed by code monkeys, they are intended for consumption by other researchers. They use language and make assumptions based on who they are intending to communicate with. That obviously isn't you.

→ More replies (3)
→ More replies (1)

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.

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.

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.

→ More replies (4)

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)

39

u/internet_ham Jul 03 '17

Uni -> Grad School -> Silicon Valley, sure they can write professional looking code, but it's never had to be used by anyone else (or likely code reviewed outside of github issue tickets)

Also, on the academic side it's tricky to balance the readibility with abstract notation. I often cite the paper I'm working off and then cite equations, using the greek later names for (some level of) consistency. I know this isn't perfect, but if you have autoencoder_probability(i) rather than p(i) then your expressions are just gonna explode...

11

u/didntfinishhighschoo Jul 03 '17

I get the balancing act. The approach should be to use terseness in code and verbosity in comments (or vice-versa).

12

u/TheFML Jul 03 '17

why not write the meaning of all important variables as a glossary (in comments) somewhere? That way there is a single place to refer to...

27

u/WallyMetropolis Jul 03 '17

The glossary is the paper that's linked to in the comments.

2

u/[deleted] Jul 20 '17 edited Jul 20 '17

No amount of documentation will help you understand a complex equation that you have not read the paper for. If it's based off a paper, read the paper before reading the code.

If you had never bothered to read about dynamic programming do you think you'd understand the code just because it was commented and structured nicely? Short of copying the wikipedia article into the code I don't see how that would work.

Researchers can always work on their engineering skills, and many, if not most, do. But the main issue is that you guys are used to working on simple business logic and basic systems interactions where the density of complex concepts in a piece of code is much smaller relative to something like scientific computing (imagine taking years to understand dozens of nested concepts embedded in 10 lines of simple, clean code? Even with professors helping you learn?). So when you don't understand the code, you assume that it's because the code didn't tell you the simple thing it was doing or wasn't structured in a communicative way. No. It's mostly that you just haven't spent the necessary time to understand the underlying concepts.

→ More replies (4)

4

u/INDEX45 Jul 04 '17

Im fine with super short variable names if they match exactly the formulas and terminology in the paper. It helps translation greatly. But, if it's not a term in the paper, it should be spelled out.

78

u/olBaa Jul 03 '17

Noone pays us for releasing the code. Nothing motivates us to do that.

In my subfield, 3/4 major papers fucked with the first one's parameters because it was so good. Life is shit.

One author did not send his code for 2 months. When he sent it, it was a thousand line matlab code with only comments being 20% of lines commented randomly.

11

u/didntfinishhighschoo Jul 03 '17

Shouldn't doing good work be enough of a motivation? You're not serving burgers at a McDonalds.

59

u/olBaa Jul 03 '17

General issue with academic code is that it is intended to run once: for the experiments. It's other people's jobs to reimplement/reuse it for production.

I mean, I try to write decent code. But shit really happens and I do not have time to fix some of it. Why gcc fails to inline a function that is used with a function pointer? Can I fix that? idk, but the (correct) solution was to produce two versions of the code.

13

u/didntfinishhighschoo Jul 03 '17

That's cool, it happens. But the code only tells you what it is, not what was tried, why this path was picked. You take a two weeks break, get back to it, and have no clue what the fuck were you thinking, maybe even discard it because it looks silly, or makes another part more complicated to implement. No 'Here be dragons, I know what I'm doing' to stop you.

I write comments even for code I know no one will ever see. It makes me a better programmer. If I can't explain the code well enough in words for a human to understand, no way am I allowed to be comfortable with the implementation.

→ More replies (1)

36

u/yngvizzle Jul 03 '17

Have you ever heard of publish or perish? A normal nine-to-five workday is a dream for a successful academic. Time is of essence, and although I appreciate well commented code I don't expect it from academics who are paid for teaching students and publishing papers.

If you are at the point where you need to read research papers, then you should be able to implement the ML algorithms you read yourself.

18

u/Mr-Yellow Jul 03 '17

you should be able to implement the ML algorithms you read yourself.

Problem is, the papers don't contain everything needed to implement the discoveries they claim to have results for. Code does.

→ More replies (3)

8

u/Xilthis Jul 04 '17

You're not serving burgers at a McDonalds.

Exactly. And yet you are complaining about the quality of food you got for free, and expecting them to make better burgers.

Writing code isn't the job. And since it isn't the job, no one cares whether it is good.

The implementation is merely a necessity to evaluate an idea, but that's it. It's usually a quick hack, never intended to be readable or reusable. If it is released at all, then as a courtesy, because it was there anyway.

4

u/epicwisdom Jul 03 '17

The answer is, simply, no. There is a distinction between an art and a profession - people do what they are paid to do, and complaining when they meet their job description, and not one iota more, is hopeless optimism.

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

144

u/BeatLeJuce Researcher Jul 04 '17 edited Jul 04 '17

Why can't you guys do something more abstract than code?

Seriously.

I spent the last few years doing Machine Learning. Dug into web app a couple months ago. Supposedly, compared to the silicon-valley-startup guys doing Webstuff, ML programmers should be inbred peasants. But every project these peasants release, even a fucking library that trains an SVM has a half-decent paper, authors that are available via email, written in a non-obscure language that isn't just a JS-inbred-with-types, and a function that can be explained via a few lines of math, and, oh my god, better library names than angular or ReactJS or fuck_you_for_trying_to_guess_the_purpose_via_its_name.

The concepts and ideas behind micro-services, npm, node.js, 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 code conventions, trying to squeeze meaning from bullshit language used on websites, figuring out the super important steps, preprocessing, setup-routines 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 code? Is pseudo-code a fucking premium? Can you at least try to give some intuition before showering the reader with JS libraries?

  • How the fuck do you dare to release a website without a working JS-less version?

  • Why the fuck do you never ever add references with additional information to things you took off StackOverflow?

  • When using other people's code, are you charged by the module? Do you get a bonus for silly library names?

  • Do you realize that Google having needed to release an "optimized" JS interpreter is a fucking disgrace to your profession?

  • Jesus christ, who decided to name a JS library angular?


Now, in all seriousness: don't judge us before walking even a block in our shoes. Every field has it's barrier of entry and it's customs. Webdev is as guilty of this as ML. It just happens that in ML, the custom is that CODE IS IRRELEVANT, it's a side product. The formulas count. There's a reason most ML development happens at PhD-level. Math is not optional. You want to know how something works? Go fucking read the paper, not the code. You want to know why the variable is named x and not input_data? Because I develop my code on paper or black boards, and there x is the much better choice. My "code" is actually just a formula. The only reason I write code is that we haven't yet got the tools that auto-generate the code from my black board scribbles. But that's what you should consider most ML code: badly auto-generated code. It's the math behind them that does the actual "machine learning". You wouldn't read C code that comes out of matlab either, would you?

So now that we've got the ranting out of the way, let's be serious for a second: I think /u/awishp here and /u/bbsome here hit the nail on the head: code is cheap, it's changing all the time, and it's not where it's at. When I was a green-behind-the-ears fresh-out-of-CS beginning PhD student, I also wrote nice code, sensible abstractions, ... god was I wrong. The main concept ML programmers should stick to is YAGNI and KISSS. If you spend too much time on your code, you're wasting research time. Your code is going to be rewritten a gazillion of times, because you have so many ideas that you want to try out that you'll be writing prototypes all the time. Any abstraction that you found sensible last week (say "a module/class/interface that loads your input data") becomes totally irrelevant today, because you have a great new idea ("let's generate the input data via a GAN, and the GAN is fed by an RNN that processes the current output") so you need to refactor all abstractions again. The more crude and simple your code is, the more time you save. That tensorflow session variable you hid 3 abstraction levels below your actual training code? Guess what, you're going to be needing it tomorrow because of some idea you just thought of.

Yes, you should polish code and "implement stuff correctly" for your publication, but there usually isn't the time. And after all, your work is well documented in your paper, so if someone with financial interest wants to use it, he can pay someone to implement it efficiently/neatly. Because that is not my job. My job are the formulas, and showing that they actually work by writing some one-off prototype.

0

u/didntfinishhighschoo Jul 04 '17

You have the right idea about structuring proof-of-concept code. Abstractions are a hindrance when you do rapid prototyping, and I don't advocate for them in this context. But you do need to tell a story with your code, and it shouldn't take more than a slight overhead to do so, with a bigger payoff. Working on your model, you've made decisions, both theoretical and practical. If you don't document them, you're just keeping them to yourself. Others will have to re-discover them. If you programmed long enough, you already know that you yourself usually forget and throw away good decisions that were undocumented. The best way to do this is to write comments and notes as you go. If you do this at the end, when it already works, it will feel like a chore, and you will already have lost a lot of insights into all the micro-decisions that went into the process.

I've been around the block. I'm not a web developer, as the assumption goes. But web developers (front-end, back-end, operations) figured this out. More than mobile developers, more than game developers, more than systems developers, and obviously more than the ML research community. There's a lot of wrong hype cycles in web developers, a lot of clumsy signals and incentives and unwritten rules, tons of problems and things to critic – but it's, by far, the best community for open collaboration, and ML researchers will do well to learn from it.

5

u/mister_plinkett Jul 04 '17

But you do need to tell a story with your code

ML research is a whole separate field and it uses some different ways of handling things and communicating. The code isn't the focal point of the paper or where to look for all the ideas, and expecting it to is won't end well.

Working on your model, you've made decisions, both theoretical and practical. If you don't document them, you're just keeping them to yourself... The best way to [show your thinking] is to write comments and notes as you go.

This is assuming that

  • The non-code parts of a paper can't communicate such things

  • Everybody has the same balance of difficulty in commenting code vs. trying to write them later as you do

But web developers (front-end, back-end, operations) figured this out. More than... systems developers,

Clearly we've been working with different codebases.

but [web dev is], by far, the best community for open collaboration

Clearly we've been working with different projects.

2

u/ozzie123 Jul 06 '17

This is golden and should be more popular.

0

u/[deleted] Jul 04 '17

[deleted]

→ More replies (1)

57

u/jmmcd Jul 03 '17

I read the code for 30s and I think ctx_h is good choice of variable name. ctx is obvious from context (see what I did there) while h is commonly used in the equations in a paper to indicate the hidden layer. Maths is always written with 1-character variable names. Good code ends up being a very close reflection of the maths -- not just the variable names, but the structure, e.g. a \sum_{i=0}^N x_i^2 in maths becomes a sum(x[i]**2 for i in range(N)) in Python.

And cat is similarly a good name. Let me check: do you now, or have you ever, UNIX-ed?

22

u/alkasm Jul 04 '17 edited Jul 04 '17

Yeah I don't think this code was a particularly good case at all of what the OP is talking about. The OP is totally right about a lot of research code. But I think this is actually very well written code. I find a ton of research code littered with commented out lines that you have no idea what they're doing, variables like xx_y and you're just like "...what?", and strange vector calculations that are probably fast but have no comments to understand them.

For example, last summer I had a really neat vectorized operation to calculate a running average mean; the Nth element was the mean of the first N elements of another vector. This would be basic with loops but I was just bored so vectorized it. The line looks like

s_mean(1,:) = (tril(1./(1:N)' * ones(1,N)) * meas(1,:)')';

And coming across this I'm sure someone would be like "wtf" so above it I wrote in comments:

matrix multiplication for iterative averaging
(1   0   0   0   ...)   (m1)   (m1)
(1/2 1/2 0   0   ...) * (m2) = (m1/2 + m2/2)
(1/3 1/3 1/3 0   ...)   (m3)   (m1/3 + m2/3 + m3/3)
(... ... ... ... ...)   (..)   (..)

creating the lower triangular (tril) matrix
(1   0   0   0   ...)        (1   1   1   ...)        ( ( 1 )                     )
(1/2 1/2 0   0   ...) = tril (1/2 1/2 1/2 ...) = tril ( (1/2) * (1   1   1   ...) )
(1/3 1/3 1/3 0   ...)        (1/3 1/3 1/3 ...)        ( (1/3)                     )
(... ... ... ... ...)        (... ... ... ...)        ( (...)                     )

Reading this it's pretty obvious what

s_mean(1,:) = (tril(1./(1:N)' * ones(1,N)) * meas(1,:)')';

does. Took a few minutes to write and would save someone probably an hour of "wtf". Not that hard to do.

2

u/visarga Jul 04 '17

Yeah I don't think this code was a particularly good case at all of what the OP is talking about.

I found it accessible to read, but I read a lot of ML papers and code.

→ More replies (2)

0

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

Good points. I just picked this repository and this file randomly, happened to check it out today, it didn't trigger the post.

  • If it's the context of the hidden layer, shouldn't it be h_ctx? (when you use _ as a namespace it's a neat cod smell for recognizing that maybe you can compartmentalize your code better). Also, you got ctx and you got ctx_h (no other contexts) - that's like naming your files 'document' and 'document1'.

  • UNIX is (in)famous for its terseness (and it had some historic reasons and constraints for doing so). concat is the usual name in almost all languages. Plus, I'd bet most developers only know cat for printing out files.

2

u/name_censored_ Jul 04 '17 edited Jul 04 '17

when you use _ as a namespace it's a neat cod smell for recognizing that maybe you can compartmentalize your code better

Rubbish! Underscore as the "discard"/blow-away operator is literally part of the language, especially when unpacking. It's not unique to python either - bash, prolog, erlang, swift, clojure, C#, and probably dozens of others use this standard.

concat is the usual name in almost all languages. Plus, I'd bet most developers only know cat for printing out files.

concat instead of cat would be inconsistent - torch (the semi-external library) uses cat, which is its own [50 year old standard](https://en.wikipedia.org/wiki/Cat_(Unix)). Ignoring torch's preference, my personal feelings are that concat is the unfamiliar thing.

I appreciate that you were loathed to call out a specific example for a general frustration, but I actually felt your example was a well-written piece of code (even if it wasn't necessarily Pythonic) compared to a lot of the crap on github.

→ More replies (2)

23

u/clueless_scientist Jul 03 '17

shouldn't it be h_ctx? No, it should not. The symbol _ has specific function in the equation environment in LaTEX (namely the second argument is a subscript of the first), which is used by the majority of researchers to cast equations into text. Everyone who used this typesetting system recognizes the meaning of this notation.

0

u/[deleted] Jul 03 '17

[deleted]

→ More replies (1)

12

u/i_ate_god Jul 04 '17

You appear to want to learn the wrong thing.

ML is about math, not code. Learn the math, and the code will naturally follow.

→ More replies (1)

63

u/lefnire Jul 03 '17

Dear machine learning hosts. You've no doubt heard the news that we web devs are joining the fray. We'd like to get to know you! A bit about us, we have a range (more an ENUM) of personalities, sort of like the seven dwarves. You've just met Grumpy (a common one); there's also Hipster, Entrepreneur, Digital Nomad, and more. Brush up on HBO Silicon Valley for a primer. But enough about us, tell us about you?

0

u/[deleted] Jul 03 '17

[deleted]

10

u/JustFinishedBSG Jul 04 '17

Deep learning works better than any method in every scenario ever. Always try deep learning first no matter what.

Needs to a be a GAN, it's $currentYear now.

2

u/didntfinishhighschoo Jul 03 '17

Decent shitposting. I want to state for the record that I fucking love Schmidhuber and whisper his name every night before bed.

3

u/DanielSeita Jul 04 '17

We should ask him to run for US President, even though it'd be violating the Constitution. :)

7

u/TemplateRex Jul 04 '17

That should not be an impediment because the Constitution was heavily influenced by the pioneering work of Schmidhuber et al. (1741, 1745a, 1745b and 1759). The Constitution just took advantage of the revolution that followed those foundational writings.

→ More replies (1)

2

u/INDEX45 Jul 04 '17

Needs more XYPQR-GAN.

17

u/vmsmith Jul 04 '17

On one level, I agree with you completely. Donald Knuth nailed it with Literate Programming. When I teach undergraduates to code, I begin Day One with comments. As time goes on, the comments become more refined and meaningful, but I get them in the habit of commenting their code from the time they write their very first line of it.

But now take a look at your own post. Second sentence, "Dug into DL...", as if everyone immediately knows what DL means. LSTM...? I had to look it up. TRPO...same thing.

Sure, you're on /r/MachineLearning and perhaps it's a somewhat valid assumption that people will immediately get your acronyms. But did it every occur to you that others besides those who are deeply into machine learning might be reading posts and that they might not know?

The issue here is communication. It takes effort, and it takes a certain strain of empathy, to put yourself into your audience's shoes and ask yourself if what you are writing -- be it in a programming language or a natural language -- is, in fact, easily understandable.

So again, although I completely agree with you on one level, I think you need to check yourself on another level.

4

u/didntfinishhighschoo Jul 04 '17

Good comment. Reminded me of this. ("And so, once again, what looks like a technical problem--function naming--turns out to be deeply, personally human, to require human social skills to resolve effectively. I hate that").

3

u/didntfinishhighschoo Jul 04 '17

Also: Literate Programming is fantastic for machine learning stuff, since the code is very linear in structure. Jupyter notebooks are a great example (but the UX for writing them is horrible, imo).

→ More replies (1)

5

u/[deleted] Jul 04 '17

I particularly enjoy that he thought "input" was just too long so he wrote "inpt".

I'm a Rubyist, OP would probably call me a hipster peasant, so my code basically is pseudo code that happens to run.

5

u/didntfinishhighschoo Jul 04 '17

OP’s favourite language is Ruby. They used inpt because input is the name of a global Python function similar to gets in ruby. I usually name it features or x instead.

→ More replies (3)

36

u/darkconfidantislife Jul 03 '17

Sure, sure, if you'd be willing to compensate my time for writing good code, like Facebook does (as you mentioned in your question), then I'd be happy to.

Otherwise, stfu and enjoy the free code I gave you.

22

u/didntfinishhighschoo Jul 03 '17

Such piss-poor approach to life. I keep forgetting that for most people, their job is just their job, even if they’re in an interesting and important field, all that matters are the sticks and carrots the bosses lay out to them.

30

u/Jorrissss Jul 03 '17

their job is just their job,

I think the part you're not emphasizing or appreciating is that their job is just their job and without compensation they aren't necessarily interested in making more readable code for the public. A person can have a tremendous amount of pride or love for their work, but not give a shit about you.

8

u/didntfinishhighschoo Jul 03 '17

This is a practical field. Your tools and execution are multipliers of your ideas.

Look, I get that compared to other parts of the academia, DL is moving at a blazing speed. But compared to other parts of the industry - it's like going back in time for me, it feels like doing development in the nineties. Look at the ecosystem and the infrastructure and tools and culture available for web developers and operations people.

34

u/WormRabbit Jul 03 '17

It's not "a practical field", it is an academic study. The point of academic studies isn't to produce practical tools, but to invent new ideas and test approaches. Thus churning out 10 papers with piss poor code and numerous tests is strongly preferrable to a single well-written code example which may not even prove that useful.

→ More replies (9)
→ More replies (2)

6

u/east_lisp_junk Jul 04 '17

I think the part you're not emphasizing or appreciating is that their job is just their job and without compensation they aren't necessarily interested in making more readable code for the public.

I think the part OP is really missing is that there is absolutely no shortage of work to do. The decision here is not about whether to go put some extra hours in so that there's time to clean up research artifacts for general public consumption. Those extra hours are getting put in, no matter what. The decision is whether the extra hours go towards chasing another research result, or updating the curriculum for some course you're teaching, or serving on some committee for your department, or trying to really give detailed feedback on some students' homework, or writing another grant proposal so that you'll have the resources to get more research done, or making something they've already written more accessible, or giving a more thorough read to some papers they're reviewing, or....

→ More replies (1)

37

u/commisaro Jul 03 '17

Or maybe we'd prefer to spend our time working on those interesting and important problems, rather than doing the boring drudge work of fixing up code we wrote for problems we already solved? But I look forward to the clear, well-documented and commented code you will release along with your own state-of-the art algorithms for currently unsolved problems.

1

u/didntfinishhighschoo Jul 03 '17

I bet the guys in the eighties you reinvent and republish from thought the same thing.

13

u/TankorSmash Jul 04 '17

He's got a point man. I advocate great code as much as the next guy but you're here shitting on someone else's code without so much as a pull request to back your claims up.

You're literally just calling out some other devs to make yourself feel better. It would take some real effort but make the pull request with those variable names and try to comment some stuff out and help people instead of being a dick for no constructive reason.

→ More replies (1)

14

u/Mr-Yellow Jul 03 '17

boring drudge work

It's simply good coding habits. Nothing hard about getting things right the first time.

Of course it's extra work if you don't bother following good practice from the start.

13

u/darkconfidantislife Jul 04 '17

That's a false assumption, I care deeply about my research field, that's why I stick to it and don't go work at some hedge fund for way more money.

Here's the thing though, I want to work on interesting problems, I literally have a backlist of 100+ ideas I want to try out. That takes time. Why would I spend time on making my code look pretty for others and slow that down even more, when I could instead move onto trying out a new idea?

That being said, if people ask politely, I will help them out.

→ More replies (2)

2

u/crazylikeajellyfish Jul 03 '17

Remember that these people are also trying to hit deadlines, they can't do everything. Part of why JS tooling quality is so high is that it's a lot of open source passion projects where engineers have the leeway to Do The Right Thing. These Facebook devs probably cut corners because they were in a rush, not because they're lazy.

6

u/didntfinishhighschoo Jul 03 '17

The deadlines in the industry are fiercer. We write code in weekly sprints that no one outside the company will see. Nothing goes live without a code review from two people, automated checks, mandatory documentation, etc.

9

u/crazylikeajellyfish Jul 03 '17

Nobody outside the company will see it, but plenty of people within the company will have to work it once you're gone. Again, deployed industry code is responding to a very different set of requirements than a research group. You really think any of that code will get used in an actual Facebook product?

8

u/didntfinishhighschoo Jul 03 '17

No. What sucks is that other research groups won't build on top of it. They will have to rebuild and reinvent parts, probably get stuck on the same points the FAIR group hit on but didn't document. Waste of research cycles. If you have an idea you want to check out, see how it improves this model, how much time will it take you just to get to the starting line?

0

u/[deleted] Jul 05 '17

[deleted]

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

2

u/skilless Jul 04 '17

Most people live /r/notmyjob

2

u/Lampshader Jul 04 '17

Hey OP, maybe you can come work for me? I won't pay you, but it's an interesting and important field.

3

u/[deleted] Jul 03 '17

Yeah - but if you get scooped and don't get publications then you won't be in the interesting and important field for long.

It sucks, but don't hate the player hate the game...

→ More replies (2)

24

u/syedashrafulla Jul 03 '17

Readable, good code is for others to read. That other is, usually most importantly, you in a few months. Academics working on their own code waste a lot of time trying to find root causes due to poorly written code. If graduate students would have a Review Friday where another student reviewed their code over the last week (via quid pro quo with another graduate student), I think total research velocity would increase a significant amount.

Source: me and my abhorrent code during my way-too-long PhD

5

u/throwawaycompiler Jul 03 '17

It has been continuously repeated to me throughout my studies that one should comment their code well (and structure it well). But I have looked at code from well-praised people at my job that are just absolutely horrendous in terms of readability. I hardly understand what it does, and there are hardly any comments, and it blows my mind that everyone else on the team is ok with this.

I've come to believe that being able to read any type of code and understand it should be emphasized a lot more than writing nice code. It seems to me that companies are looking for people who can learn quickly rather than write things nicely for people.

3

u/syedashrafulla Jul 04 '17 edited Jul 06 '17

This is a good take, but I will challenge a couple of points.

there are hardly any comments, and it blows my mind that everyone else on the team is ok with this.

My challenge to this is I was taught that comments are to be used only when the design isn't code-evident. If variables and functions are named well, then comments are generally sparse. The tradeoff is that naming variables & functions eloquently is the hardest part of programming.

I can lob this criticism at the OP too, but I suspect the OP is disappointed in the lack of function docstrings.

I've come to believe that being able to read any type of code and understand it should be emphasized a lot more than writing nice code.

My challenge to this is you can't have one without the other. Being able to read varying code choices requires being able to write good code. The only way to write good code is to read many styles of code.

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

63

u/halfeatenscone Jul 04 '17

I've definitely felt this problem. But uncommented code is better than no code. If we shame researchers for sharing unreadable code, there's a risk that next time they finish a project they just put the code in a drawer somewhere because they don't have time to polish it up.

I've found that people are pretty open to pull requests for this kind of thing. I spent a while trying to understand the code for sketch-rnn (hard-to-google abbreviations like 'MDN', occasional bad variable names like result1, result2). When I figured out something that was puzzling me, I added a comment to remind myself. In the end, I put them all together in a P.R. which they merged.

118

u/[deleted] Jul 04 '17

One valuable lesson that I've learned from grad school and now working in R&D is that you shouldn't write good code when doing research.

Consider the researcher's perspective: You have this new idea that you want to try and see if it's worth anything. You could spend a week planning your codebase out, carefully documenting everything, and using good design patterns in your code. However, you have no idea whether or not your idea is going to work, and you cannot afford to spend that much time on something you're very likely going to discard. It is much more economical and less riskier to write your code and iterate on it as fast as possible until you get publishable results, and once you're at that point there's no real incentive to refactor it to make it more readable or reusable. Behind every paper there are tens to hundreds of failed ideas that you don't see that aren't worth a researcher's time, and what you see is the result of compounded stress, anxiety, and doubt that permeates the life of a researcher.

Also I think a lot of work that is developed or sponsored by big tech companies purposely obfuscate their papers and code to prevent people from reimplementing it, since they want the good PR that comes from publishing but still want to own the IP generated from it. There's been several times where I've talked with other researchers about work from X big-name company and we've agreed that we can't figure out what is exactly going on from the paper alone because it seems to strategically leave out key details about the implementation.

23

u/[deleted] Jul 04 '17

I don't buy this all. Forget comments. You can still write code that's clear to understand and uses appropriate variable names. Academics are usually just better at theory than they are at writing semantic code. It takes a lot of time and experience to have best practices drilled into you. I don't think they have that experience.

To put things in perspective, just look at any code that you've personally written when learning a new programming language. It'll probably look amateur and be hard to understand.

7

u/[deleted] Jul 04 '17

True, but from my experience the process is so iterative that it's extremely difficult to keep up with yourself. You might write your initial program with good practices, but eventually you're going to want to see what happens when you change some parameter, or preprocess your data a different way, apply some filtering, add in another method from another paper, etc. After modifying your code 100's of times within a few days to meet a deadline you're not going to have a well-engineered piece of code anymore. (but that's OK, you're not an engineer you're a scientist, or worse, an underpaid grad student)

The point of research is delving into the unknown, and it's hard to plan for that.

That said, the state of machine learning nowadays is such that we have really good frameworks and libraries to work within that help tremendously to structure research code better, so there really is less of an excuse for publishing bad code (or none at all).

3

u/Mr-Yellow Jul 04 '17

After modifying your code 100's of times within a few days to meet a deadline you're not going to have a well-engineered piece of code anymore.

This is actually where solid semantics helps a lot. If everything has a good strong well defined name, then refactoring along the way should keep looking clean, if not getting cleaner as time goes on.

Mess happens where the semantics were confusing or ambiguous to begin with.

→ More replies (1)
→ More replies (3)

22

u/UsingYourWifi Jul 04 '17 edited Jul 04 '17

It is much more economical and less riskier to write your code and iterate on it as fast as possible until you get publishable results, and once you're at that point there's no real incentive to refactor it to make it more readable or reusable.

That's the crux of the problem. For some reason this code doesn't need to be presentable or understandable. Probably because nobody reads - much less bothers to replicate the results of - 99.9999% of these papers.

2

u/[deleted] Jul 04 '17

For most conferences having published code is evidence enough for "reproducibility." Reviewers often never bother to try running it, probably because it's too much effort and probably because it's the reviewer's grad student who's actually doing the review.

→ More replies (1)

2

u/Reykd Jul 04 '17

This is exactly why. Its all about costs. Writing "nice" code is great, however not at the expense of holding back the state of the art. Some people eventually come back to "old" papers and implement them nicely (read OpenAI Baselines). But researchers must do what they do, get great ideas and push the state of the art.

→ More replies (1)

38

u/[deleted] Jul 04 '17 edited Jul 04 '17

I agreed until:

the unnecessary equations

lolwut. I can't think of any equation or algorithm that's just "unnecessary". I would practice more with math/calculus if you think they're unreadable. Sometimes I find a sigma equation clears so much so quickly whereas I agree with you that shitty code is shitty.

→ More replies (1)

63

u/conventionalWisdumb Jul 03 '17

The code is written by scientists, not engineers. Scientists write code once and it is not meant to be reused or maintained. Engineers have to write code that is to be both reused and maintained. Clarity of intent is a premium in the style of the code for engineers, where clarity of intent is left to the text accompanying the code in a journal for scientists.

0

u/[deleted] Jul 04 '17

[deleted]

11

u/[deleted] Jul 04 '17

No joke, this is one of the reasons why I left my PhD program. I couldn't take it anymore.

12

u/errordrivenlearning Jul 04 '17

If you're learning ML or DL, avademic papers (or worse, conference proceedings) aren't at all the way to do that. To torture a metaphor, that's like trying to drink from a firehose at the bleeding edge. And who wants to drink a firehose of blood?

Start with textbooks and tutorials, implement some models, use the well-published libraries, learn the culture and the acronyms, and then, if you want, explore the latest and greatest from academia.

3

u/MrNaaH Jul 04 '17 edited Jul 04 '17

This such be preached more often to newcomers really, first I want to recommend 'Deep Learning' by Goodfellow, Bengio and Courville to people with a software engineering background. Don't skip chapters if you a total beginner to ML ;)

20

u/alexmlamb Jul 04 '17

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

You really should be careful about saying these things until you have a high level of understanding of the field.

It's possible that an expert's understanding is more complex than the lowest level of understanding required to implement. For example, VAEs have a pretty simple intuitive explanation which is sufficient for implementing it reasonably well (you're trying to make the bottleneck look like a prior) but I think that the variational bound explanation also has value.

I think it is true that some papers have extraneous math that doesn't really add value to the idea, but you should make sure that you fully understand both the intuitive version of the idea and the formal version of the idea before making such a claim.

8

u/Mr-Yellow Jul 03 '17

I love the bit where there is a magic line which hacks everything back into shape in a complex, odd and hard to decipher way.... but lacks any comment as to it's purpose.

25

u/dummeq Jul 03 '17

to mirror your tone: git gud scrub ,-)

39

u/bbsome Jul 04 '17

So, I really don't understand why developers and people from industry somehow expect people from academia to publish and present well documented, test proven, nicely commented, battle ready code. So here is my 2 cents, intentionally in the same spirit as the thread.

First, to start somewhere, if equations are something you don't understand, then you either have to go back to high school or you literally have no ground for requiring academic people to understand and write in your beloved 100-layers of abstraction bullshit enterprise factory based code. Mathematics has been invented to be and still is the unifying language of anything numerical, it is clear and simple and independent of any language. I really can not be convinced that there is another medium which can convey ideas more clearly than maths. Also at academia, we are NOT paid to produce code, any code, or to open source stuff. As a grad student, given that I get paid minimum wage and live in one of the most expensive cities in the world, why the heck am I suppose to waste my time on this, rather than someone like you who is hired to this gets paid about x10 than me? If you so much don't like/understand things in the paper well just hire someone from academia to translate it to you, what is the problem? It's how free markets work and we are not some kind of charity obliged to do the job for you.

Also, on the topic using single letter and similar variables - well this is because all of the implementations HAVE BEEN DERIVED AND PROVEN with mathematics, and the implementation follows the mathematical derivation. Note that this guarantees that the implementation is correct and does not need 1000 tests just because we have no idea what we are doing. Have you EVER look at proper battle proven mathematical libraries like BLAS for instance - libraries which exist before your pathetic JS even existed and have made the whole world of engineering go around for several decades, has gotten us to the moon and so on. Well here is an example:

_GEMM ( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC ) S, D, C, Z

Does that seem anything like fuck_you_for_trying_to_understand? No! Obviously No! Because all these functions are based on mathematics and they use the mathematical notations for this. And guess what - it's same the thing for Machine Learning. People must finally get to understand that Machine Learning is not your basic software engineering and it is actually based on maths.

Thirdly, for the papers not including details. I think a lot of people already talked about this, but I will repeat. Please tell me how many papers you have written? Do you have any idea how little space it is allowed on a publication compare to what you need? Literally, this is never the author's problem, but the conference requires it. A lot of the papers get literally curate and crammed down to at least a half just so that it could fit in the page limit. Then you have to actually sell the whole research and have an introduction and description of how the whole thing fits into the giant landscape of the whole field. Pseudocode? Do you have any idea how much space that takes? And nobody in the reviewers would even give a damn if you have it. What incentive would someone writing this have of putting it there, if the acceptance rate is 20% and you literally have removed about 80% of the maths and 60% of the original text? The answer is simple - NONE.

5

u/frequenttimetraveler Jul 04 '17

Mathematics has been invented to be and still is the unifying language of anything numerical,

DL is still algorithms however, and you rarlely see algorithms described solely with matrix equations. The use of math instead of pseudocode/diagrams would make more sense if the the math could be interpreted/visualized in a geometric way, or if the system was solved in closed form rather than iteratively through GD. I find that the math notation does not lend itself to some geometric interpretation that can give new intuition. It looks more like a somewhat-forced formalization.

To a newcomer, the terse math notation seems like premature vectorization/optimization of what are usually very simple to grasp procedures. Of course everyone should be able to understand the linear algebra, but i am not sure it's the optimal format for presenting an algorithm, or that the matrix notation is actually helping in solving problems / coming up with new architectures. I find that it's usually the other way around - a simple idea can lose its simplicity if one tries to fit it in with the rest of the notation.

6

u/bbsome Jul 04 '17

DL is still algorithms however

I quite disagree with this statement. DL and ML, in general, is not algorithmic at all - you have a model and potentially a loss, which most often is log-likelihood objective. The only algorithmic part is the optimisation, but that is hardly a big part of the problem. If you like to think of a network as some form of algorithmic procedure, that is perfectly fine, but I do not agree that is the usual view.

math could be interpreted/visualised in a geometric way

I don't agree that all math needs to be explainable with geometry to be consistent or intuitive to understand. I still think you are talking here more about the optimisation problem.

Could you present me an example of your last paragraph? I really don't see too many examples where writing something in pseudo code would be any more clear than writing the mathematical equations.

3

u/frequenttimetraveler Jul 04 '17

i am only referring to DL and yes generally about optimization. i may be biased to look at matrices as something that "transforms vectors" rather than doing hadamard operations.

I would say the math notation for an LSTM is quite cumbersome, and that the intution is lost ; it's hard to figure out what it does but it's easy to explain it in words.

→ More replies (3)
→ More replies (1)

7

u/Dagusiu Jul 04 '17

I'm currently doing some ML research, and it will (hopefully) lead to a published paper. And I'm guilty of most of the things you accuse "us" of, poorly commented code, that's poorly structured and generally hard to understand. I probably won't release it, not in this state at least. Why is it so? One word: deadline. When working under heavy time constraints, cleaning up the code is a luxury we often cannot afford. And once the project is over, there's certainly a new deadline coming up, so if there was ever any ambition to clean up the code before releasing, that's hard to justify compared to doing new research (which is often what we're getting paid for).

When reading papers, focus on understanding the ideas. A well written paper should contain enough information for you to be able to implement it yourself. (if you can't, then the paper is shit and you don't have to feel bad about it)

39

u/evc123 Jul 03 '17

The paper is the comments/docs.

14

u/roryhr Jul 03 '17

Exactly. The idea is the code should fall out from the theory and methods described in the paper. Implementation is the easy part.

0

u/[deleted] Jul 04 '17

[deleted]

→ More replies (5)
→ More replies (12)

12

u/geraltofrivia783 Jul 03 '17

A student researcher with CS Engineering background here. I've come to terms with this. I'm still amazed when people release the Source Code in the first place.

I just spent almost four hours interpreting a custom LSTM code in a repo with more than 1200 github stars, with almost no comments. It's a torture.

The problem worsens as you deal with symbolic libraries (Keras, Theano...) since debugging them is more of a hassle.

Sigh. No information to add but I had to pitch in with the rant.

12

u/vosper1 Jul 04 '17

Hey, it could be worse - I once considered trying to understand this: http://blog.robertelder.org/diff-algorithm/

I have been told that this style is called "academic coding".

4

u/radicality Jul 04 '17

Well, at least it comes with a comment that links to that site and a large explanation with examples of what does what.

6

u/TheProfessional9 Jul 03 '17

Agreed, they should have named the function OperationKitCat

6

u/cerved Jul 03 '17

Academic papers in general aren't very pedagogical

6

u/IdentifiableParam Jul 04 '17

It is pretty easy to release a paper without source code if you know your code is going to enrage people who see it.

16

u/Zulban Jul 04 '17

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

I wrote a paper discussing this serious issue (it was about reproducibility, transparency, and peer review). I submitted it to a relevant journal. It was rejected as off topic.

6

u/Jigsus Jul 04 '17

You're the 1000th one to write a paper on that topic and get rejected

→ More replies (1)

16

u/r-sync Jul 04 '17 edited Jul 04 '17

An entitled idiot who has a narrow world-view.

You seem to think that your priorities and perspectives are the only ones that matter. You have very little understanding of other perspectives.

Go save the world with your javascript programming, one npm package at a time.

I think I'll just be the same, writing shitty code.

70

u/GuardsmanBob Jul 03 '17

Do you intentionally try to obfuscate your papers?

As far as I can tell from the outside, there is actually a real incentive to obfuscate a paper. The harder it is to replicate, the less likely it's findings will be verified by someone else, and thus the author wont have to face the possibility of his paper being invalidated.

This field seriously need a real incentive for authors to get their work verified by a third party, every other paper I try to read I bail on because it seems obvious that its just an attempt to publishCount++;

42

u/Jorrissss Jul 03 '17

thus the author wont have to face the possibility of his paper being invalidated.

People do obfuscate papers, but this is seldom (if ever?) the reason why I believe. In my experience, it's more about not wanting other groups to catch up to you immediately. No one wants to get scooped.

31

u/GuardsmanBob Jul 03 '17

In my experience, it's more about not wanting other groups to catch up to you immediately.

This still seems to be in contrast to the spirit of publishing, thus I at least stand by my assertion that the incentive structure could be improved.

16

u/Jorrissss Jul 03 '17

This still seems to be in contrast to the spirit of publishing,

It totally is.

thus I at least stand by my assertion that the incentive structure could be improved.

Agreed!

4

u/WallyMetropolis Jul 03 '17

That, along with the fact that writing well and clearly about complex topics is itself a difficult skill that isn't really taught or encouraged at any level in academia.

5

u/Nimitz14 Jul 03 '17

cat

That sounds awesome. I hate tensorflow's verbosity. Such a PITA to write. Code looks fine to me.

5

u/theflofly Jul 04 '17 edited Jul 04 '17

The TensorFlow source code is well commented actually. It helps a lot.

5

u/Inori Researcher Jul 04 '17

Why stop with ML, let's go after everybody! I'll start with math:

The concepts and ideas behind derivatives, integrals, limits, whatever – it's clear, it's simple, it's intuitive. The slog is to go through the jargon, the unnecessary equations, trying to squeeze meaning from bullshit language used in analysis papers.
/s

5

u/hooba_stank_ Jul 04 '17

368 comments

All comments missing in github projects were added here :)

Talking seriously, you should distinguish production code and PoC code from researchers. There's no aim to make it fully supportable and extensible and no strict production-like coding standards.

So people spend as much time on cleanup and commenting their code as they like.

Treat opensourced code more as a free gift you can just ignore (if you don't like it), but not smth you can hate someone for ;-)

5

u/kkastner Jul 04 '17 edited Jul 04 '17

We do document our code, often with additional pointers to past and related documentation (and related code if the authors released) - it's the publication and "prior/related work" section of that paper. It is a pain, but often you need to read lots of relevant literature before the paper, code, and math makes sense. Sometimes this takes months or even years - deep learning is downright accessible compared to some other subsectors of ML - ever looked for code for submodular optimization or some graphical model methods?

Not saying it should take months or years to catch up with certain subfields, but that's how it is right now today.

Also, I find the linked code extremely clear, not sure what the problem is there. It clearly demonstrates the methods and pieces needed for the experiments in the paper, which is the whole point. The TPE code linked in a below comment is a bit tricky, but it presupposes an understanding on Theano - the author was a key contributor there. Thinking in a graph-based way is pretty rough, especially if you are used to imperative programming. Even understanding vectorized "languages" like Matlab or numpy takes time, and that is basically a prerequisite for understanding Theano and TF IMO.

I encourage you to rewrite/extend or blog about a paper or code you find unclear - many times a relevant blog to explain a paper or research code in another way is incredibly valuable and helps a lot of people (who probably have similar problems as you do). This is also some of the value of a "survey paper", though in deep learning there aren't many of those yet.

Open source code accompanying a paper is a (very) recent trend, and one I hope continues. However there is a catch - now authors may spend time supporting users instead of new research. I personally think interacting and supporting people using code (to some extent) is extremely valuable experience, but I see how some people might be uninterested in that.

At an extreme, if releasing source only results in criticism and has no effect on paper acceptance, why should authors bother? This is why I applaud code release with a paper, no matter how rough the code may be.

25

u/YANNLECUNT Jul 04 '17 edited Jul 04 '17
  • do you intentionally try to be bad at CS and math?

  • how the fuck do you dare demand free code?

  • why the fuck do you need so much hand-holding?

  • yes I'm so disgraced that after many clueless master's students and bored webdevs had a hard time implementing a mildly complex algorithm, OpenAI decided to help them out

  • hello? unix? have you ever typed cat in a shell or are are you one of those people complaining that torch doesn't work on windows?

→ More replies (14)

4

u/WasterDave Jul 04 '17

Oh man, it gets a lot worse than that.

4

u/letsgoanddothis Jul 04 '17 edited Jul 04 '17
There are two ways of constructing a software design: 
One way is to make it so simple that there are obviously no deficiencies,
and the other way is to make it so complicated that there are no obvious deficiencies.
The first method is far more difficult.
  • C.A.R. Hoare

4

u/t_o_m_a_s Jul 04 '17

Finally, I thought I was the only one. I can actually relate to most issues mentioned in the comments - how the researchers seldomly have time to produce high quality code, only having a few pages for a conference paper and whatnot.

What I do not understand is why would anyone not publish their source code. It's literally a few clicks away from uploading it to GitHub.

What's more, without the code, there's actually no proof that the method described in the paper works. The authors could just as well make up a bunch of numbers showing that their method is slightly superior to all other state-of-the-art (how I hate that expression) methods, but without the source code provided, there is no way of making sure they are not making stuff up.

Thus, when trying to overcome a certain method, I have to reimplement it first. During that process, I am likely to make a few mistakes, since the paper did not bother to mention a few "details". Then, my own method defeats my implementation of someone else's method only due to a few bugs I would have not made had the original authors published their source code for comparison.

Even if the published source code is of horrible quality, it's still better than nothing and can serve as a reference during my own reimplementation.

→ More replies (1)

15

u/redrumsir Jul 04 '17 edited Jul 04 '17

Isn't this whole post against the "Rules For Posts" ??? Seriously.

Rule 1: No personal attacks, name-calling, or insults. By the way ... the code link you posted looked OK to me. It could have used a few lines of comments on the top class ... but if you read the associated paper ( referenced https://github.com/facebookresearch/end-to-end-negotiator ) it's not rocket science.

6

u/BeatLeJuce Researcher Jul 04 '17

yes, we could've done without the name calling, but since it sparked such an intense discussion, we let it slide.

6

u/redrumsir Jul 04 '17

Interesting choice.

I'm kind of a spectator here. My background is pure math ... and my interest in ML is strictly related to Graphical Programming and Bayesian Networks. I found the discussion yesterday a big turnoff to the whole sub as it had echoes of students in mathematics who somehow wanted cutting edge and/or hard math to magically be easy. I've also programmed and been around programmers ... and their code ... long enough to recognize that the majority of their complaints are "hypocritical posturing" since almost all code (even their own) ignores best practices (it's why PEP8 is so popular because it's form-over-substance at best).

→ More replies (9)

10

u/Kaixhin Jul 03 '17

Former web developer, now ML-er here. Yeah, I've been frustrated by this too. Basically, many people in academia haven't worked in industry and hence are less likely to have the impetus to write good code, and as others have mentioned too, there are several reasons why you may not want to clean up and/or release code.

If you're frustrated, release your own code. Be the change you want to see. If you think you can write good code, try and be an example for others. Here's some things I try to do:

  • Have an informative readme, with requirements plus instructions if fairly complex.

  • Write modular code (although fitting complex pipelines into one file with PyTorch is fun and possible).

  • Use descriptive variable names/names that correspond to mathematical notation.

  • Comment regularly (especially for non-ML but otherwise technical decisions).

  • Add maths to code comments via unicode.

Has this benefited my career as a scientist? Nope, repos with hundreds of stars and good documentation does not help with grants or scholarships. But still, I know making ML accessible has wider reaching benefits beyond my own career, so I'm going to keep doing it, and still try to publish so that I can work my way to a position where I can influence others to promote good coding practices.

3

u/Mr-Yellow Jul 03 '17

Besides the completeness of different DQN styles available... Your DQN code really does shine compared to other implementations in that you're fully setup as a proper documented open source project people can actually use and contribute to.

Others might have small parts which are better, but they fail on the code presentation. Leaving yours to stand-out.

5

u/skilless Jul 04 '17

I totally agree—the code in ML is often atrocious.

Some memorable examples I've encountered: Kera's argument called x that is described as x: input data. Why it isn't called input_data, I'm unsure.

The many tutorials and courses that frequently have variables with single-letter names, such as u. It's especially fun when u is overwritten multiple times with different things.

My absolute favourite is numpy's method T.

But I rest easy realizing that machine learning has hit an inflection point and it appears none of the old guard have noticed: the engineers are coming. These academia-accepted bad practices are about to be washed out by an absolute tsunami of software engineers, who will bring with them the skill and practices of actually making software.

3

u/BeatLeJuce Researcher Jul 04 '17

I replied to here, but the main point is: ML is still a research field, and we see ourselves as researchers. We think in formulas, code is just a side product. The closer the code is to our formulas, the easier our job becomes. And in our formulas, the input data is called x and a matrix transpose is denoted by a T. I absolutely agree that someone will need to take our findings and make usable products out of them. But that shouldn't be us, it gets in the way of our job. We all hope the engineers will be coming and doing cool stuff with our work. But there's a (IMO sensible) separation of jobs: ML scientists and ML engineers need to work together, and do so well. But if you ask one man to do both jobs, he will either only make half as much progress or do the job half-as-well.

0

u/[deleted] Jul 04 '17

[deleted]

3

u/skilless Jul 04 '17

The javascript developers do make for easy strawmen, but software engineering is much, much larger than that.

0

u/[deleted] Jul 04 '17

[deleted]

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

13

u/DerNalia Jul 04 '17

You're an asshole. Learn the theory, and then it'll make sense.

Commenting code for non technicals is a waste of time.

Basically, know your audience.

3

u/dismal_denizen Jul 04 '17

One thing to remember is that a lot of research code is disposable. Ideas come and go quickly, and often you will want to hack something together just to try it out. Unfortunately this leads to very messy projects with heaps of flags for running different experiments with different optimizers and models or whatever. You can't really maintain a beautifully engineered piece of software as you go without wasting A LOT of time. You don't even know what you're building sometimes.

Afterwards, when you have something working and write a paper on it, there is pretty much no incentive to go back and rewrite the code. My supervisor would probably say something to the effect of "why are you rewriting code that already works for a paper that's already written?". And you know what? Given the way things operate in academia, it's pretty hard to argue against that.

I'd love to take the time to meticulously comment and structure projects, but this does take time (regardless of what others seem to think) and the incentives aren't there.

3

u/serge_cell Jul 04 '17 edited Jul 04 '17

You can consider it as a test to pass, before you gain access to arcane knowledge.One does not simply copy past in research :) More seriously though, parsing other researcher code and understanding it using only paper is fastest way (or one of) to gain intuitive understating of method.

PS If code would be commented it would be not much more easy to understand for OP. Because all comments would be in latex :)

3

u/Tsadkiel Jul 04 '17

I both do and don't agree with you.

I DO agree that papers libraries, etc... need to have properly commented and understandable source code. Once code is ready to be released yea, variable names should be made meaningful, loss oof comments added, etc...

I DON'T agree that research code should be "good". Research is not the production of product, it's the production of ideas. The goal is to get your ideas out there in a fashion that others can test for reproducibility. When you write research code you should not be concerned with proper naming schemes and conventions. You should not be concerned with efficiency and optimization. You should not be concerned with class structures, or profiles, or interfaces or whatever. You should be concerned with getting it to work. Period. Everything else is putting the cart before the horse. Making it pretty / efficient / easily useful is not the job of a scientist.

3

u/[deleted] Jul 04 '17

http://www.gitxiv.com/

GitXiv releases code and papers together.

3

u/resemble Jul 05 '17

Often, in research code, you don't know what you'll have when you're finished.

For "a fucking library that colorizes CLI output," it's very easy to understand how exactly everything is going to fit together at the end, so it's easy to plan and have a clear idea of what the final product will be.

For an experimental machine learning system, it's often duct taped together, with various parts dangling off in ways you hadn't expected as you try to bridge the space between the complexities of the world and the computer. Usually, what works barely works. Like pdehaan's comment, it should be better, but at the moment it's not, and in doing bleeding edge research, it's hard to spend time making things nice.

3

u/RylandResearch Jul 10 '17 edited Jul 10 '17

I am Ph.D. student and researcher in the field of cognitive science with a specialty in neural network mathematics. I am also one of the few researchers I know that has avidly programmed since high school. I have read plenty of bad code, and yes it is a problem. However you seem to have some real misconceptions about machine learning and neural network experts, keep it in mind most researchers are not paid to code or in any way evaluated by their code other than it's functionality. I could write an essay about this, but apparently I can only use 1000 words.

If you want a WHY for this it's mostly history:

  • The 1980s: This is arguably when the modern field of machine learning that you are familiar with really kicked off (I'm referring to when gradient descent started to become a thing). If you remember the 80s, readable code didn't matter. If you ask Hinton how he learned to code, he would tell you it was back in the days of spaghetti and one letter variable names. This is actually how most of the most influential names in machine learning learned how to code. These are the people who taught the next generation of machine learning practitioners. For better or worse this style lends itself to writing code that resembles mathematical equations and it stuck in the field of machine learning and neural networks, because when the people in the know taught their students it was often in this style. Machine learning developed on a separate path from general computer science. If anything people studying machine learning back then had stronger computer science backgrounds than they do now in many cases.

  • 90s: Code readability become important in computer science, high-level languages and documentation and design becomes almost as important as function. This did not catch on in machine learning circles. These are people who really feel nostalgia for FORTRAN and lisp. Few in the wider world of highly-profitable computer and application programming really care a whole lot what those funny academics are doing with their neural nets and fuzzy non-sense, so academics keep their style of coding and are slow to adopt new languages and concepts from computer science. The code is entirely secondary to the math, which is the main vehicle of communication. Further, the math is geared toward formal precision not readability. Naturally the community stays small. Other academics publish papers referring to neural networks as a "Dark Art" I'm not joking.

  • 2006: Deep learning, CNNs, LSTMs, and other recent models take the world by storm making it very clear that a whole new world of functionality could be possible. The machine learning community is still small, insular, and they still communicate largely through near indecipherable math. Now most of them are far more specialized in their niche math than current computing to the point where many basically use and teach decades old programming practices (Many fields of research are actually this way it's not unique to ML).

  • 2017: Everyone wants to learn machine learning, but unless you just want a cursory overview that wont show you how to do anything cool you need to go study with monks in the alps or find Hogwarts. The machine learning and neural net communities largely learned master apprentice style, with high burnout. There is no pipeline, no curriculum, and little accessible material available to help the hordes of people who suddenly want to do machine learning.

The reality is what you want is already happening, but it will take a decade before you can appreciate the results. Before that happens here is what will need to happen in the meantime

  • It took decades for readability to become a mainstay of general computer science and it was helped along by the creation of widely agreed upon concepts and norms. It will take at least a decade for standards like these to become important in ML.

  • There are too few people that can teach this stuff at a high-level. Until the current generation of PhD students start teaching don't expect the field to magically become much more accessible to anyone outside the community, because until this generation of students that wasn't a priority.

  • These fields and most scientific research disciplines in general need to make programming fundamentals a mandatory part of their curriculums, so that student's actually know what it means to make code readable in the first place, and instill in them a sense of value for code reuse.

  • Development of better more usable mathematical notations. I myself am actually working on making a more readable and intuitive notation and methodology that will make taking derivatives of multi-dimensional arrays and simplifications trivial, while highlighting the ideas behind what is happening. Unfortunately, that is something I do for my students and myself in my spare time. The current dominant notation is ... difficult to say the least.

  • Improving the accessibility of our field needs to become a priority of our field. With that comes making code that others can actually read. Actually implementing this kind of change takes a lot of time and effort, and we really are not being funded to do this sadly.

  • Machine learning and Neural Networks need to be given their own majors at universities and specialized course requirements so students are actually prepared to interact with the math, the bio, and the computer science required to be fluent in our field. Right now these disciplines are taught as advanced topics of other domains.

What you can do to help the process:

  • If you have a question about a particular model that you have seen in a paper, go to that researcher's website and see if the paper has an appendix. Often important details for exactly replicating a model and even source-code are included as extra materials that had to be cut out of the paper proper. Again high-level practitioners in a field can just look at a diagram or some equations and get enough to implement their own version, they rarely care about exactly recreating other peoples algorithms.

  • If you cannot find additional helpful materials and you are stuck on something, you can try reaching out to researchers. We tend to be pretty approachable and we all have easily found university and lab e-mail addresses that we often respond to when people are polite and inquisitive. Admittedly, we might skim the e-mail and realize that the question shows that the person will not understand the answer and will require quite a lot of help to understand where they are going wrong. In which case they may try to direct you to helpful materials.

  • If you come to a reasonable understanding of an algorithm that was tricky please write up a tutorial whitepaper and run it by a friendly machine learning expert and put it out on the internet.

  • If you feel like you have an approach to explaining some of the more difficult parts of the math of machine learning to newbies, write it up and run it by a friendly machine learning expert, and put it out there.

  • If neural network math classes that go deep into the math become available to you, show support and take one if you can. These are rare and difficult to teach, but universities need to see that students want to take them.

  • Complain to your congressman that the current research funding and evaluation environment creates perverse incentives that promote quantity over quality of research.

6

u/[deleted] Jul 03 '17

You mistake the code for the output of the research to those who have a stake in it.

4

u/tinkerWithoutSink Jul 04 '17

For researcher's who are self taught, that's great. But here's the habits you should pick up:

  • give variables meaningful names, even if they are longer. window_length not w

  • unit test your classes and functions: "If it isn't tested it's broken". Plus these are usage examples

  • stick to a recognized coding style by using an automatic formatter/linter

  • comment complex or obscure blocks of code

Even just the first one will make you code much nicer and people will like reading your code much more. And if you already do them, great :)

2

u/Xanthus730 Jul 04 '17

In my case, I wrote most of this code in long, after-work hours, while doing a masters degree while holding down a full time job. With a wife and kids...

I still tried to make it fairly self-commenting, but as it's basically a math library, it's 90% formulas.

I tried to leave well-named functions and variables so I would know what formula was being used, and which variable was which.

But, I didn't bother re-writing all the formulas in comment form (which I have done for other things in the past) mainly due to time constraints and the fact that at the end of the day, I didn't think it would add much readability.

Code in question: https://github.com/Reithan/MachineLearning

→ More replies (2)

2

u/rodrigosetti Jul 04 '17

One of the reasons is that some researchers consider the implementation a second class citizen. The important thing is the paper.

2

u/approximately_wrong Jul 04 '17

Note to self: comment my code :x

2

u/DT777 Jul 04 '17

You really would think people would write self-documenting code. If not for other's sake, then at least their own.

God I don't know what I'd do if I had to decipher my old code sometimes. I don't have time for that shit.

2

u/sigma914 Jul 04 '17

"cat" is a pretty standard name for concatentation, you know the shell command cat? That's the concatenation command.

It'd be nicer in a typed language where you could see it was cat :: Iterable<Tensor> -> Tensor but it's still a decent name.

I agree with the most of the rest :)

→ More replies (2)

2

u/[deleted] Jul 04 '17

I swear some people still think that a long variable name or a verbose comment means the compiled machine code will be bigger and slower.

2

u/ptitz Jul 04 '17

Cause all this code is written just to publish one or two papers, under presumption that no one will ever bother to look through it all. Which is true like 99.5% of the time.

2

u/vega455 Jul 04 '17

IT'S ALL ABOUT INCENTIVES. For computer scientists, the incentive is to make many experiments, try different things, and publish. The code is intended to be used for the experiment, and never again. It's not supposed to be software engineered production-quality code. But it's freely available for others to make the most out of it.

It would take exponentially more time to build top-quality code with error checking, testing, full documentation and all the bells and whistles. Little time would be spent doing science. Variables with names like W, b, h and y_hat don't mean anything. But once you read the papers it is quite clear.

HOWEVER, I also don't understand the rampant lack of comments. I comment ALL my code, if for no one else, at least for myself.

2

u/evc123 Jul 04 '17 edited Jul 04 '17

/u/didntfinishhighschoo This is the most commented non-AMA r/MachineLearning thread of all time.

2

u/ArEnScGh Jul 04 '17

Ill explain, so scientist generally put science and theory before an engineered product or demo. What you are usually looking for here is a nice demo that is developer friendly. I am sorry to disappoint you scientists generally are not software engineers, nor product people. It takes a lot of effort to move science foreward and at the same time takes a lot of effort to communicate ideas in code. A scientist is paid on results not their code quality. In an ideal world yeah the code should be commented and documented. We do not live in an ideal world.

2

u/MrNaaH Jul 04 '17 edited Jul 04 '17

I don't think cutting edge ML research is for you. Some enthusiastic software engineering will eventually get it, do all of these things you are asking. By the way, I personally don't find your code example particularly hard to read such the author of it read this, good job. OP "didntfinishhighschoo" if you are seriously considering getting into the field, probably finish high school and get a degree if you have not.

2

u/znfi Jul 05 '17

I think this question is actually is quite interesting if one instead views it as how one could try to apply best practices from software engineering to improving machine learning research. I should probably add that I am very far from being a researcher in ML but is probably more well versed in standard software engineering.

Anyway, in my experience the speed at which "requirements" change when doing experiments in for example ML cannot be compared to traditional software development, and I think this is probably one of the most important underlying factors for the current situation. At least in the experiments I've been doing I find myself more or less constantly having to rework the basic "control flow" of the application, and traditional software engineering practices seems to be of limited value.

I don't have any particular example of this unfortunately, but I think it's something like one comes in with the assumption that one might be interested in how some parameter affects the outcome, and then after doing some experiments one figures out one is actually interested in some other parameter one had no idea about when starting out, and this is now very hard to change in some clean way. Well, parameters in this paragraph might not be the right word, if it was just a single number it would be trivial to write the experiments so they are all tunable, but instead it is rather entire subsystems.

In the web application one usually has a very static structure with different modules passing information in a way that will basically never change throughout the lifetime of the application, and then some configurable bits between these modules. One might have some basic layer responsible for routing a request to the correct controller, and then controller doing its stuff and interacting with the models and then handing the request off the the view, and so on. If the web developers on a daily basis had this fundamental structure of the application challenged I think that code would be quite a mess as well.

My point here is not that all hope is lost, software engineering in traditional fields have taken a long time to develop and something as simple as MVC was figured out fairly recently, in the grand scheme of things. Instead my point is that there are some real difficulties in this area, and just saying that the ML community does not follow good software engineering practices seems to miss many important points. Finally, this answer has not addressed why the final product is not polished and refactored into a more understandable style, but I think many others have addressed this part of the problem.

2

u/Fa1l3r Jul 05 '17 edited Jul 05 '17

I have also noticed this problem, so I call upon my fellow programmers to document their code and document open source projects. Pull requests are a godsend, assuming the administrators accept the merge.

edit: Anyway, it seems that your discussion has fostered the undocumented code to be documented.

3

u/[deleted] Jul 03 '17

Man, once you get through formatting your code to meet all the python style guide rules (which PyCharm helpfully underlines everywhere) you can't really be fucked writing comments.

But I think the real reason for lack of comments is most post-post-post-docs doing AI stuff are not developers.

3

u/[deleted] Jul 03 '17 edited Jul 04 '17

Haha, yes. Look at this:

# These produce conditional estimators for various prior distributions
@adaptive_parzen_sampler('uniform')
def ap_uniform_sampler(obs, prior_weight, low, high, size=(), rng=None):
prior_mu = 0.5 * (high + low)
    prior_sigma = 1.0 * (high - low)
    weights, mus, sigmas = scope.adaptive_parzen_normal(obs,
    prior_weight, prior_mu, prior_sigma)
    return scope.GMM1(weights, mus, sigmas, low=low, high=high, q=None, size=size, rng=rng)

Just let your eyes gloss briefly over it. It doesn't matter too much what it does. You've some function which does something, right? You run it and it does some sort of 'sampling' with a 'GMM' right?

Well.... no. Because fuck you, that's why.

The code never runs this like a normal bit of code. Instead it later creates an abstract syntax tree for this, then manipulates the abstract syntax tree to modify the call to 'GMM1' to instead call a different function, then runs that manipulated syntax tree...

More details here:

https://johnflux.com/2017/02/13/worst-code-i-have-ever-seen/

→ More replies (4)

5

u/mimighost Jul 03 '17

This code looks good to me. No one owe you anything to write the comments.

5

u/Cherubin0 Jul 03 '17

Welcome to the Python culture, where not even the language itself follows semantic versioning.

3

u/omg_drd4_bbq Jul 04 '17

Because if other people can understand it easily, it means it's not advanced enough and you can't sit smugly atop your ivory pillar.

→ More replies (1)

1

u/Reddit1990 Jul 04 '17

I feel you. I've been dealing with a lot of "data" and "index" lately.

1

u/ftyyppo Jul 04 '17

I can relate so much to this!

I actually believe that code should be written as readable as possible so the need for comments is minimized, but docstrings should be mandatory! Especially for language like Python with no type declaration so it is painfully hard to figure out what a function argument should be (list/dict/what) without knowing how it is used. These researchers must treat code writing like academic writing skill; you write clearly so other people can understand whatever your idea is easily. It is not enough to just publish the code. I agree that this is mostly incentive problem. If conferences mandate publishing the code and also code review, pretty sure code quality is gonna improve.

P.S. that Python code is still much better than this crap.

1

u/[deleted] Jul 04 '17

My favorite is tons of ultra short comments, just so you can get to the fucntionality you're looking for quickly

1

u/shele Jul 04 '17

To be fair you should mention https://arxiv.org/pdf/1706.05125.pdf

1

u/frownyface Jul 04 '17

I'm amazed that so many cutting edge results in machine learning are released as code at all, I feel like it's way too good to be true right now, and it won't be obvious when it happens, but that the spigot will at some point turn off. It's very easy to take this sort of thing for granted.

And the current situation creates a ton of opportunity for people to write more understandable and maintainable versions of things, write blog posts, and create visualizations explaining things, etc.

1

u/k10_ftw Jul 04 '17

"for a few months"

1

u/Altourus Jul 04 '17

I'm going to guess it's a matter of familiarity with the subject matter. You wouldn't think to comment a counter being incremented in a for loop, it's likely very similar for them.

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

I'd guess a unix user, isn't that a command from the unix prompt that is used to concatenate files?

1

u/NMcA Jul 04 '17

Just my two cents - at some stage a widely cited result in the field will turn out to be wrong due to a bug. There'll be an embarrassing retraction, then people will start writing more tests.

1

u/synaesthesisx Jul 04 '17

Anyone have a good Sublime Text plugin that'll comment my shit for me?

1

u/microface Jul 05 '17

Mostly because as a software engineer of 25+ years I use variable, and function names that describe what is supposed to be going on. When I inherit code, then I use Doxygen to see flow, and use debug statements to get real time flow. I have seen code that does not explain what is going on and the variable names or function names have no meaning for me, so yes I have been on both ends. I also wrote a RAW RGB Camera demosaicing code based on Stanford algorithms and had more comments about matrix manipulations than code, because I knew I would never remember why I did something

1

u/[deleted] Jul 05 '17

As a grad student who has been working on ML and NLP for a while, I'm very happy with the way things are at the moment! A couple of years back, releasing code with the paper was a completely foreign concept to the field, and thus we had to manually request the authors to provide their internal code to be able to benchmark against, or use their systems. In most cases, such a request was denied (had a couple of personal experiences too), and we had to write things from scratch, which slowed down the entire research process.

At the moment, I'm really grateful that companies (and research groups) are releasing their super-efficient and super-useful libraries (like Tensorflow, PyTorch, DyNet et al) and now even useful wrappers like Seq2Seq, TF-Fold etc. Trust me, it has always been easy to come up with new ideas in the field, but it was really hard to quickly benchmark them a couple of years back. The time that I have to invest to understand their code is way lesser than the time that it would take me to write good implementations of tricky architectures (for instance, Memory Networks, Neural Turing Machines) from scratch.

Sure, things can improve, but if that improvement comes at the cost of the research groups not releasing that code because of bad quality, I would rather have them release it nevertheless and clean it up myself.

1

u/[deleted] Jul 05 '17

Honestly agree with this so much. I'm an undergrad student now trying to get into ML and I love the theory but absolutely can't stand trying to work through people's confusingly written code. It almost makes me completely turned off from the field of ML in general, as extreme as that may sound. It makes the whole process miserable.

1

u/Zenol Jul 05 '17 edited Jul 05 '17

Well, research paper are not mean to be read, but published. If you want the idea, you should go to conferences, that's where ideas and concepts are explain. Research paper contain rigorous (well, if they get accepted in good review) proof of what is happening and when (means under which hypothesis) it's happening. Not always easy to read, especially if you don't work in the same field of the author.

No paper is intentionally obfuscated, but few of them are written for anyone outside of the research field. Pseudo code is something that you can easily write once you get the idea, so not all paper give it to the reader. Some time intuition is in the equation.. when you have the required academic background.

Well, a research paper is not a program, so of course they are published without code. It's like publishing a recipe, and not the cooked dish. Easier and more versatile.

Which code? :)

Yep, we receive 1$ by letter removed.

Why? Researcher are payed for inventing algorithm and publishing papers, there is no extra money for implementing them, and it doesn't help for your career... (actually, it's the opposite effect)

Should definitively have been namedc or simply . :)

By the way, your question is interesting, because it point out that researcher are not paid for explaining their concept to peoples that could actually make them alive... Yep, it sucks :)

1

u/bshillingford Jul 05 '17

Research is centered around ideas and knowledge. Software engineering is about building something.

Research code != reusable library. Research code, by its nature, needs to get thrown away and rewritten far more often than production code. You try something for a few hours, a day, or a week, it doesn't work, you throw away much of it and keep a bit, and you repeat. I can't tell you how many times I made the mistake of refactoring myself into a hole, simply because things evolve fast enough that writing proper abstractions (and iterating them to follow the research) is a burden. Note that this doesn't apply as strongly to ML engineering, where projects are better defined, goals are more concrete, and less of the work is research.

Since research works with ideas rather than code, code (nor even the text of a paper) isn't the end goal. You're merely translating the ideas into natural language and code.

About your comments on papers themselves. "Unnecessary" equations? I'm not sure why you're complaining about what's typically the most precise way to communicate an idea. Papers also tend to be brief because of page limits, and also the need to balance the main content with related work, background, etc. Most of your concerns don't apply to the best-written papers. But those are rare, just as high-quality software projects are.

If you value high-quality ML code, why not contribute? Refactor/rewrite a fork and document it, release useful libraries, start a blog about implementing algorithms, etc. Clearly people'd appreciate all of these. People even occasionally cite blogs sometimes nowadays.

1

u/[deleted] Jul 05 '17

Fine, pay me for it, and I clean my code.

1

u/dakami Jul 05 '17

What you need to realize is that machine learning code is not written to do machine learning, it's written to do more machine learning. In other words, they're not trying to give you a tool that does a thing, they're trying to get you to create new tools.

Scikit-Learn is the notable exception here, while Tensorflow is basically an engine for creating more Tensorflow.

1

u/-RVG- Jul 10 '17

I'd like to add one more point to your list:

  • If you are going to give me a math formula with 10 weird Greek letters in it, at least provide a legend. Most people interested in AI generally suck at divination.

1

u/bachi76 Jul 10 '17

I feel you, absolutely :-). However, be proud of your hard-earned software development experience, gained from a career of software engineering. And be a little forgiving to those that see programming just as a tool for their main work and have not much industrial-grade experience. Or professional s/w background (meaning being efficient in complex client environments and in large and changing teams).

That being said: Yes, there's a lot of possible improvements :-)

1

u/vwibrasivat Jul 11 '17

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

Using cat for tensorConcatenate() would barely make sense as an Assembly code instruction for a SPARC processor.

→ More replies (2)

1

u/ScroogeMcDuck00 Nov 21 '17

It's weird seeing a message of "get your shit together" get blasted at a group of people vastly, vastly more sophisticated and productive than me. I could've had a long train of "vastly"s there, without it being hyperbole. All right: pick variable names that make sense, write helpful comments, include glossaries for terms, et cetera. Granted.

But this tone is ridiculous. I've seen this kind of "why can't you write code like me, idiot?" attitude from some programmers, and it is utterly toxic. Just give simple, polite feedback.

1

u/wtpayne Dec 03 '17

... and this is why you need people like me who can not only understand the ML code but can also refactor it into something that a mere mortal can read and understand. :-)

1

u/eternviking Oct 14 '25

Was going through the Rasa paper and found the link to this post there. 8 years later and this is still relevant.

1

u/Puzzleheaded-Night21 Aug 12 '22

I am really tired of people who think it is a coders duty to comment his code. If you cannot understand the code then you should be writing your own original code. There is widespread theft of open source code as it is going into commercial products where original developer was essentially defrauded of his intellectual property. See GitHub ML scandal!

get over it move on stop whining and maybe find a less stressful job!