12 ms·
Try to guess if code is real or GPT2-generated
- neolog 6y agoThe black background on white background makes it annoying to read.
- damenut 6y agoThis was so much harder than I thought it was going to be. I would get a few right and then be absolutely sure of the next one and be wrong. After a while I felt like I was noticing more aesthetic differences between the gpt and real, rather than distinguishing between the two based on their content. Very interesting...
- ivraatiems 6y agoI found this impressively hard at first glance. It just goes to show how difficult getting into context is in an unfamiliar codebase. I think with any amount of knowledge of anything allegedly involved (or, you know, a compiler), these examples would fall apart, but it's still an achievement. I'm also pretty sure there are formatting, commenting, and in-string-text "tells" that indicate whether something is GPT2 reliably. Maybe I should try training an AI to figure that out...
- pwinnski 6y agoI tried using a weird indent as a signal of GPT-2... which gave me my first wrong answer. 4/5.
- deleted 6y ago[deleted]
- technologia 6y agoThis was a fun exercise, definitely think this could be difficult to suss out for greener devs or even more experienced ones. It’d be hilarious to have this model power a live screensaver in lieu of actually being busy at times.
- klik99 6y agoFor the ones that were just part of the header file, listing a bunch of instance variables and function names, it seems impossible. But for the actual code, it is possible but still quite difficult, though I spent too long in finding some logical inconsistency that gave it away.
- Aeronwen 6y agoGot 40/50 just smashing the GPT2 button.
- loa_in_ 6y agoI had about 50% picking one option over and over.
- lelandbatey 6y agoInteresting, I guessed GPT2 each time 200 times in a row and only found that GPT2 was correct 89/200 times, so about 45% was GPT2 for me.
- nickysielicki 6y agoThis is difficult... because these models are just regurgitating after training on real code. Fun little site but I hope nobody reads too much into this.
- moyix 6y agoI've tried searching for variable and function names and even bits of comments to see if they're copied from the training data. They're not!
- moyix 6y agoHi, author here! Some details on the model: * Trained 17GB of code from the top 10,000 most popular Debian packages. The source files were deduplicated using a process similar to the OpenWebText preprocessing (basically a locality-sensitive hash to detect near-duplicates). * I used the [Megatron-LM](https://github.com/NVIDIA/Megatron-LM https://github.com/NVIDIA/Megatron-LM) code for training. Training took about 1 month on 4x RTX8000 GPUs. * You can download the trained model here: https://moyix.net/~moyix/csrc_final.zip https://moyix.net/~moyix/csrc_final.zip and the dataset/BPE vocab here: https://moyix.net/~moyix/csrc_dataset_large.json.gz https://moyix.net/~moyix/csrc_dataset_large.json.gz https://moyix.net/~moyix/csrc_vocab_large.zip https://moyix.net/~moyix/csrc_vocab_large.zip Happy to answer any questions!
- ivraatiems 6y agoThanks for stopping by! This is impressive. I would be curious to know if my hunch below about potential weaknesses/tells was at all correct. Did people find it to be as challenging when you showed it to them as some of us are here? Did you expect that level of complexity?
- moyix 6y agoThere are likely some "tells" but many fewer of them than I expected. I've seen it occasionally generate something malformed like "#includefrom", and like all GPT2 models it has a tendency to repeat things. Yes, I think people definitely find it challenging. I'm keeping track of the correct and total guesses for each snippet, right now people are at almost exactly 50% accuracy: correct | total | pct ---------+-------+----- 6529 | 12963 | 50
- hntrader 6y agoAre you presenting real samples and GPT2 samples to users with equal probabilities? EDIT another poster guessed GPT2 each time and found the frequency was 80 percent
- 6y ago
- et1337 6y agoThis looks like overfitting to me. Some of the GPT samples were definitely real code, or largely real code. One looked like something from Xorg, another like it was straight from the COLLADA SDK. It’s really hard to define what “truly new code” is, if it’s just the same code copy pasted in different order. Blah blah Ship of Theseus etc.
- moyix 6y agoThe generated snippets are prompted with 128 characters from real code (but not code from the training data), so they can often pick up on the name of the project etc.
- et1337 6y agoApologies if my comment was dismissive. This is an impressive project!
- minimaxir 6y agoOverfitting on 17GB of input data would be interesting, even though it's using the "large" 774M GPT-2 model. It's possible training for a month may be too much.
- dzdt 6y agoI got some code related to VICE emulator. It looked pretty real, referring to concepts that make sense in the context of a C64 emulator, but the results said it was GPT not real code. It even had the correct GPL license matching that project. It seems the GPT model has learned quite a bit about the real projects it was fed as input.
- moyix 6y agoIt has entirely memorized a bunch of common open source licenses, a bunch of contributor names/emails, and so on. However when I've tried to locate the actual code it's producing in the training data it's not there.
- sdflhasjd 6y ago
- TehCorwiz 6y agoThe two factors that seemed like dead giveaways were comments that didn't relate to the code, and sequences of repetition with minor or no variations.
- hertzrat 6y agoIf only. Humans leave dead comments all the time and I was wrong when I guessed “gpt” wrote this based on that. Being confusing isn’t reliable either unless it’s a syntax error
- ggreer 6y agoI saw what I'm almost certain was a syntax error but when I guessed GPT-2, it said I was wrong. I really wish the site let me view my previous guesses.
- thebean11 6y ago6/6, quitting while I'm ahead
- qayxc 6y agosame here :D
- The_rationalist 6y agoHow much of it is just regurgitating the training set and therefore chunks of real code?
- deleted 6y ago[deleted]
- thewarrior 6y agoThis is actually quite impressive. Try reading the comments in the code. The comments often make perfect sense in the local context even if it’s GPT-2 gibberish. The real examples have worse comments at times. The only flaw is that it shows fake code most of the time so you can game it that way.
- jackson1442 6y agoSome of the "real" ones have absolutely atrocious comments. Two variables labelled with literally just the name of the variable like so: bool hasdied // has died and then a `// done` for seemingly no reason after initializing variables... where did this code come from?!
- moyix 6y agoThe “real” code came from these packages: https://moyix.net/~moyix/sample_pkgnames.txt https://moyix.net/~moyix/sample_pkgnames.txt
- hertzrat 6y agoThe goal when writing code is to be pretty machine like and to keep things extremely simple. People also write dead or off topic comments. That’s why this is so hard
- Aardwolf 6y agoThere was some code about TIFF headers, and it was apparently GPT2 generated TIFF is a real thing, so some human was involved in some part of that code, it has just been garbled up by GPT2... In other words, the training set is showing quite visibly in the result
- Felk 6y agoI got a function that assigned the same expression to three variables. Then it declared a void function with documentation stating "returns true on success, false otherwise". Apparently that code was written by a human, which makes me either doubt the correctness of that website, or the quality of the code it was fed with
- psyklic 6y agoSame thought here - apparently humans read from uninitialized arrays immediately after declaring them! That said, it is still a pretty fun website :)
- dataflow 6y agoI actually ran into a case where I wanted to do this, but was forced not to. What was the scenario? I had a couple of small, fixed-size char buffers and I wanted to swap their valid portions, but the obvious choice of swap_ranges(a, b, a + max(na, nb)) would run into this issue. (n.b. this wouldn't be correct for non-POD types anyway, but we're talking about chars.) On top of it being annoying to not be able to do the convenient thing, it made life harder when debugging, because the "correct" solution does not preservs the bit patterns (0xCC/0xCD or whatever) that the debug build injects into uninitialized arrays, therefore making it harder to tell when I later read an uninitialized element from a swapped-from array.
- cmeacham98 6y agoWhy would you ever want to swap an uninitialized value into a buffer? You're wasting CPU cycles writing out data that you are guaranteed to never want to use. Why not just do a copy from the source buffer to the uninitialized one (as that is likely the half of the swap that is desired)?
- dataflow 6y agoI literally explained why I want to do that in my last paragraph?
- _coveredInBees 6y agoI got 4/4 GPT-2 guesses right. It is impressive but the "tell" I've found so far is just poor structure in the logic of how something is arranged. For example: a bunch of `if` statements in sequence without any `else` clauses with some directly opposing prior clauses. Another example was repeating the same operation a few times in individual lines of code which most human programmers would write in a simpler manner. It's harder to do with some of the smaller excerpts though, and I'm sure there are probably examples of terrible human programmers who write worse code than GPT-2.
- Aardwolf 6y agoI found that a comment with license, followed by C++ code, but without any header inclusions in between, is a clear tell for GPT-2 generated code
- theurbandragon 6y agoHow long before we can just write specs instead of code?
- AnssiH 6y agoAh, 0/5, I give up :)
- t0astbread 6y agoJust invert your guesses then!
- cryptica 6y agoI was always able to correctly identify GPT2 but on a few occasions, I misidentified human-written code as being written by GPT2. Usually when the code was poorly written or the comments were unclear. GPT2's code looks like correct code at a glance but when you try to understand what it's doing, that's when you understand that it could not have been written by a human. It's similar to the articles produced by GPT3; they have the right form but no substance.
- thombat 6y agoI ran into some value setters which simply logged their parameters but did not store them. Hah! obviously GPT2, not understanding that a setter should, well, set. Wrong, of course. Now maybe the human concerned was far down some inheritance tree and simply wanted to document misuse of a deliberately limited class but assert()ing would have been too punitive. Or may it was indeed "right form but no substance", but authored by an SWE.
- cryptica 6y agoHaha I also got tricked a few times by this sort of thing. One of the ones I got wrong was there was a comment which said '// end of for loop' after every closing brace of every 'for' loop and I thought that there is no way that a human would ever write such pointless comments... I did manage to get 100% correct after a while but it takes a thorough reading of the code.
- tpoacher 6y agoThere is a "codes" top-level domain? Codes? CODES?? What's next? Advices? Feedbacks? Rests? I give ups.
- drdeca 6y agoisn't there a .pizza ? there's also .black , and , I think maybe a .travel ? Or something along those lines.
- jwilk 6y ago"codes" as in "coupon codes". From <https://icannwiki.org/.codes https://icannwiki.org/.codes>: The .CODES TLD is attractive and useful to end-users as it better facilitates search, self-expression, information sharing and the provision of legitimate goods and services.
- tpoacher 6y agoThank you. Faith in humanity restored just a tiny bit xD
- pikzel 6y agoOh you'd be surprised. Here's a few (tld and target market)[0]: .kim - Kim (Korean surname) .lol - LOL: laughing out loud .organic - organic gardeners, farmers, foods, etc. .plumbing - plumbing businesses [0] https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains https://en.wikipedia.org/wiki/List_of_Internet_top-level_dom...
- efferifick 6y agoI wonder how likely are code invariants found in the training set preserved in GPT-2/3. In other words, if I train GPT-2 with C source produce by Csmith (a program generator which I believe produces C programs without undefined behaviour) would programs produced by GPT-2/3 also do not exhibit undefined behaviour? I understand that GPT-2/3 is just a very smart parrot that has no semantic knowledge of what it is outputting. Like I guess let's take a very dumb markov chain that was "trained" on the following input: a.c ``` int array[6]; array[5] = 1; ``` b.c ``` int array[4]; array[3] = 2; ``` I guess a markov chain could theoretically produce the following code: out.c ``` int array[4]; array[5] = 1; ``` which is undefined behaviour. But it is produced from two programs where no undefined behaviour is present. A better question would be, how can we guarantee that certain program invariants (like lack of undefined behaviour) can be preserved in the produced code? Or if there are no guarantees, can we calculate a probability? (Sorry, not an expert on machine learning, just excited about a potentially new way to fuzz programs. Technically, one could just instrument C programs with sanitizers and produce backwards static slices from the C sanitizer instrumentation to the beginning of the program and you get a sample of a program without undefined behaviour... so there is already the potential for some training set to be expanded beyond what Csmith can provide.) EDIT: I don't know how to format here...
- xingped 6y agoThe giveaway seems to be the comments. Some comments a computer could obviously generate and some are obviously written by humans. The code seemed to be irrelevant in making a determination in my playing around with it.
- MisterBastahrd 6y agoI picked up on that and also numeric parameters that were not assigned to variables first.
- ironmagma 6y agoWould be nice if the back button worked so you could see what you guessed wrong. This is a good example of where POST is used unnecessarily and URLs should be idempotent.
- moyix 6y agoI was trying to avoid letting people figure out what id mapped to real/fake but in retrospect this was a mistake, yeah. Sorry about that!
- jmpeax 6y agoAn interesting approach to lossy compression.
- azhenley 6y agoThe snippet I'm looking at isn't code at all. It is Polish, and there isn't any comment tokens or anything.
- jeff-davis 6y agoCool! Sadly, it's really hard to tell whether OOP boilerplate is real or generated.
- reillyse 6y agoIt's easy after a while... all the terribly written code is human made and the clean tidy code is GPT2, I for one welcome our new programming overlords.
- dnautics 6y agoThere was one sample where the code written by gpt-3 had nonsensical grammar in the comments and another where it had an overloaded > operator with 3 parameters (is that even valid c++?)
- reillyse 6y agoI'd say always using proper grammar in your comments would be a dead giveaway :)
- dnautics 6y agoA mistake is a dead giveaway for human; proper grammar is a crapshoot; nonsensical grammar is a giveaway for gpt (like adjectives modifying words that aren't nouns, I think b/c gpt is and dropping a reference to an identifier into the comment)
- sli 6y agoI generally find spelling to be a much better tell than grammar. Most programmers I've known had (mostly) fine grammar but horrendous spelling. I frequently end up being the proofreader. Which is fine with me.
- iconara 6y agoI was confused on most examples I got because they started in the middle of a block comment. That's clearly wrong, but was it an artefact of the presentation rather than the generation?
- avipars 6y agowhy not use GPT-3 for next time?
- IceWreck 6y agoDid afew, got all of the right. GPT2 generated code always seems to follow a pattern
- Gravityloss 6y agoA lot of the real code seems superficially nonsensical as well! Functions with lots of arguments while the body consists of "return true;" I guess it tells what AI often tells us about ourselves: That what we do makes much less sense than we think it does. It is thus easy to fake. How is it possible to churn out so much music or so many books, or so much software? Well, because most creative works are either not very original or are quite procedural or random. And this kind of work could be automated indeed (or examined if it needs to be done in the first place).
- mhh__ 6y agoI may have delusions of grandeur because I mainly work on compilers and libraries rather than business code but there is some diabolically awful code in this training set
- kristopolous 6y agoStay in your bubble. Really. You have no idea. It'll make you hate computers
- u8mybrownies 6y agoHas anyone checked that it’s not “both”? GPT2 is big enough to memorize
- deleted 6y ago[deleted]
- blueblimp 6y agoIt's fascinating that the main reason this is hard is that some of the human code is bad enough that it's hard to believe it's not GPT-2 output. (The first time this happened for me, I had to look it up to convince myself it's really human code.) It reminds me of how GPT-3 is good at producing a certain sort of bad writing. My guess as to why this happens: we humans have abilities of logical reasoning, clarity, and purposefulness that GPT doesn't have. When we use those abilities, we produce writing and code that GPT can't match. If we don't, though, our output isn't much better than GPT's.