285 points · by goodside · 4y ago · 83 comments
One of the things that frustrates me about Copilot is that all tasks posed to it must be in the form of a completion. By writing clever comments you can get it to generate a few lines of code or a short function body, but you never get coherent long-form generations just from mashing the tab key.
I’m working on a different approach. Instead of requiring you specify your code generation task through stilted comments, you can use GPT-3 to fill in what I call “instructional templates”. They’re like f-strings, except the English goes on the inside and the Python goes on the outside. Additionally, each instruction’s location and surrounding context can aid in interpreting it, allowing instructions to be impressively terse.
I’ve collected 10 examples of the method on a Twitter thread here. Most code examples are in Python, but I also demonstrate generating CSV, NDJSON, R, Markdown, and HTML: https://twitter.com/goodside/status/1559801520773898240?s=21...
I also have a few examples of more creative, non-program output in HTML and Markdown in this thread: https://twitter.com/goodside/status/1560953991722418177?s=21...
Interested in any feedback, especially from anyone who’s tried to apply my method to their own problems.
Replace the $$dollar-quoted expressions$$ with the content described therein, or follow the directions they contain.
main.cpp
```
$$c++ includes for output$$
$$Vec3 struct with three float members x, y, z. constructor. dot product implementation. $$
$$main method which allocates two vectors, then prints the dot product of them to standard output$$
```
Answer:
main.cpp
```
#include <iostream>
struct Vec3 {
float x, y, z;
Vec3(float x, float y, float z) : x(x), y(y), z(z) {}
float dot(const Vec3& v) const {
return x * v.x + y * v.y + z * v.z;
}
};
int main() {
Vec3 a(1, 2, 3);
Vec3 b(4, 5, 6);
std::cout << a.dot(b) << std::endl;
}
``` Write a C++ program that computes the dot product of two three-dimensional vectors.
--- #include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x1, x2, x3, y1, y2, y3;
//Get input for vector 1
cout << "Enter x1: ";
cin >> x1;
cout << "Enter y1: ";
cin >> y1;
cout << "Enter z1: ";
cin >> z1;
//Get input for vector 2
cout << "Enter x2: ";
cin >> x2;
cout << "Enter y2: ";
cin >> y2;
cout << "Enter z2: ";
cin >> z2;
//Calculate the dot product
double dot_product = x1*x2 + y1*y2 + z1*z2;
//Print the result
cout << "The dot product is: " << dot_product << endl;
return 0;
}
EDIT: It even does Rust, I'm blown away! (I'll forgive the compile error, it's close enough) fn main() {
let v1 = vec![1, 2, 3];
let v2 = vec![4, 5, 6];
let dot_product = v1.iter().zip(v2).map(|(x, y)| x * y).sum();
println!("The dot product of {:?} and {:?} is {}", v1, v2, dot_product);
}Is this a natural language meta-instruction prompt to GPT-3? If so, that seems kinda impressive. Does the model conceptualize this sentence somehow, or 'merely' recognize similar prompts from some specialized training?
I don't think the model is big enough to Chinese Room prompts like this. It has to "conceptualize" them (in the least loaded sense of the word that works).
Since we are on the topic of code generation, I had a question. I built this joke script called Rockstar [0] which generates fake git commits resulting in fully green GitHub commit graph. In each commit it adds gibberish, in the last commit adds a valid code. I wanted to know if there’s an easy way to generate realistic looking code which I can use in each commit? I can’t expect users of the script to use OpenAI or any such API service. Something which can be used to generate code locally would be sweet!
Fake code generators have been around since forever: https://hackertyper.net/
Combining them seems like the logical next step.
We have broken, emergent incentive structures in our system. Tweaking those can be good or bad. It's not like a cheating on a test.
If I were to modify it, I'd make it draw a picture :)
I for one am able to think of numerous ethical ways it might be of use.
I gather that there's loose some precedent for the latter with the chess computer stuff: I've read that serious chess players heavily incorporate computers into their training and even that hybrid human/computer teams often outperform either/or teams. I'd love if someone who actually knows chess commented.
Generating code via model sampling seems to have different, or at least exaggerated imperatives around "few-shot" tuning. One might wish to generate natural language for any number of purposes, but there is a probably a stronger "better"/"worse" gradient for code, and much like human language, excellent code is rare as a fraction of all code not only overall, but even by the same company or even by the same author. So you probably want the overall contours of like "this code compiles" from a big corpus, but to tune up the "this vectorizes well" eigen-tensor from Lemire's repo.
Crazy times.
Even for Go AI, where it is only ~6 years old now, I'd still believe that human bring 0 value to a computer. 2-3 years ago, there was still some precise sequence where human might conceivable be dealing with (due to the nature of MCTS, human was better at reading deep narrow move sequences -- in go player term, human was sometimes better at life & death + some ladder sequences). Nowadays, the network are just way stronger than any human that we can't really follow what is going on in serious hour-long matches of the machine.
What game or broad category of game is the least dominated by machines these days? When I first saw the AlphaStar/StarCraft stuff it seemed that there was still plenty of room for humans to be competitive in a general sense, but that was some time ago.
It's hard for me to imagine that 10 years from now there will be a game that isn't machine-dominated, but I could be wrong on either side: maybe that's true now, and maybe there's a set of games that still has DeepMind totally stumped!
In a broad stroke, I think all games should and could be dominated by machines nowadays -- though because it is no longer an interesting problem, no one really tried to do it anymore. The last big challenges were dealing with incomplete information game (poker, starcraft) and continuous state space game (starcraft, dota etc.), which was solved ~2-3 years ago. There is still challenges (AI still favor short-term rewards, while human has better long term planning), as well as technicalities (the machines doesn't really play like human: if you can control individual units, certain things like overkill doesn't happen anymore and certain units suddenly becomes overpowered). But those are just obstacles to playing a perfect game, you can still beat human reliably even with those limitation.
I have people skills; I am good at dealing with people. Can't you understand that? What the hell is wrong with you people?
In all seriousness though, this stuff is sobering to say the least. It's dangerous to extrapolate from 80% to 100%, but it's entirely possible that these things get good enough to take a meaningful bite out of software jobs.
It would be supremely ironic if after a decade of thinking taxi and truck drivers were going to be put out of work it turns out computer programmers have their jobs threatened by generative models sooner!
We might actually end up with a fancier version of that.
Problems passed: - Two sum - Text Justification edit: Newlines
https://beta.openai.com/playground?mode=insert
On a side note, I learned that the limitation on the number of tokens was often too restrictive to do anything fun with code generation. Have you run into this issue too?
I loved it for some scaffolding, quick drafts or explore some language features, but, not enough to pay monthly for it (yet!)
GitHub (msft) is still just copy pasting code from other projects with no regard for copyright. Whether it’s paid or not doesn’t matter much.
What the comment above me meant is that probably this is a shared feeling by many other people because the initial hype (like all the blog posts etc) died quite fast once it went paid.
I can't imagine how much it cost to train the thing but oh well, I guess it's irrelevant for me for now since I won't be using it...
the implication here is that if GPT-3 can solve your coding question, you are hiring people good at memorizing solutions and not skillfull engineers.
How is that any different than what it is now? Moreover, this type of rote learning is what has been rewarded most in most academic examination processes; SAT prep tests are doing exactly that: cramming students in order learn the exam process and deductive reasoning via multiple choice by taking many test exams.
Honestly, the only tech job I have ever received was extended to me because I was headhunted while working on my startup so my POV vastly differs from most with how on-boarding should go, and every time I see this white-boarding non-sense is the norm in the interview process it make me wonder what exactly it's trying to achieve if not just gate-keep and subject people to the same hazing process the hiring managers and project leads went through when they joined: people just say they'll just grind on leetcode rather than build something useful as this is the main barrier of entry and it dissapoints me so much that it's just been normalized over the years.
An example of the “format trick”, roughly as Boris described it to me, though in OpenAI’s examples the answers were simply numbered: https://twitter.com/goodside/status/1556729629263933440?s=21...
If someone at OpenAI corrects me and says they’ve known about my method, I’ll stop claiming to have discovered it.
Except the tag names are free form and the source is generated rather than defined.
alright how do i access gpt3 so i can write it like this?
Obviously the answer is not only "No", but "Hell, no, this is just starting to get interesting!" But a lot of young people who are primarily in it for the coding career prospects should probably reconsider.
Eventually I may consolidate my better findings into a blog post of some kind.
Python, CSV, NDJSON, R, Markdown, and HTML examples: https://twitter.com/goodside/status/1559801520773898240?s=21...
More creative, non-program output in HTML and Markdown: https://twitter.com/goodside/status/1560953991722418177?s=21...
The latter is a proxy for various Nitter instances, which is useful if nitter.net itself is overloaded, which is happening more and more these days because obviously it's such a useful service.
https://pbs.twimg.com/media/FaWHN2oXkAAPISD.jpg https://pbs.twimg.com/media/FaWHN2nWQAEERHQ.jpg https://pbs.twimg.com/media/FaWHN2pWYAIbJJ4.jpg https://pbs.twimg.com/media/FaWHN2oX0AACDC6.jpg
https://pbs.twimg.com/media/FaYtV6WXEAkTG83.jpg https://pbs.twimg.com/media/FaYtV6SX0AMHbYh.jpg https://pbs.twimg.com/media/FaYtV6YXkAE0FtH.jpg
https://pbs.twimg.com/media/Fac0K14aAAIdU5p.jpg https://pbs.twimg.com/media/Fac0K13UEAEb2eq.jpg https://pbs.twimg.com/media/Fac0K1xUEAY_ZAR.jpg https://pbs.twimg.com/media/Fac0K19akAUgzk1.jpg
https://pbs.twimg.com/media/Fai8ou4WAAApNaD.jpg https://pbs.twimg.com/media/Fai8ou3WIAU2AOs.jpg https://pbs.twimg.com/media/Fai8ovXVUAAE2K_.jpg
https://pbs.twimg.com/media/FajBEnPXwAAceIK.jpg https://pbs.twimg.com/media/FajBEnuVsAA4885.jpg https://pbs.twimg.com/media/FajBEnOWQAA9x7C.jpg https://pbs.twimg.com/media/FajBEnwUcAADGMX.jpg
https://pbs.twimg.com/media/FajjhfWX0AAVBNg.jpg https://pbs.twimg.com/media/FajjhfTWQAED_kB.jpg https://pbs.twimg.com/media/FajjhfUWAAApBjT.jpg https://pbs.twimg.com/media/FajjhfVXoAAKoK-.jpg
https://pbs.twimg.com/media/FalEEs-WAAAHo_J.jpg https://pbs.twimg.com/media/FalEEs-WIAEtrUW.jpg https://pbs.twimg.com/media/FalEEs_WIAAIAlP.jpg
https://pbs.twimg.com/media/FalQzNPX0AAFUvr.jpg https://pbs.twimg.com/media/FalQzNNWYAAj4ed.jpg https://pbs.twimg.com/media/FalQzNOXkAEFB5F.jpg
https://pbs.twimg.com/media/Falk4AyXEAArsb7.jpg https://pbs.twimg.com/media/Falk4AyXgAEQUeO.jpg
https://pbs.twimg.com/media/Fal0dGKX0AIK4w6.jpg https://pbs.twimg.com/media/Fal0dGGWQAABXxd.jpg https://pbs.twimg.com/media/Fal0dGKXoAAiTqC.jpg https://pbs.twimg.com/media/Fal0dGIWQAAo3GU.jpg