TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Tell HN: A new way to use GPT-3 to generate code (and everything else)

285 pointsby goodsideover 2 years ago
Hi HN,<p>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.<p>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.<p>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: <a href="https:&#x2F;&#x2F;twitter.com&#x2F;goodside&#x2F;status&#x2F;1559801520773898240?s=21&amp;t=-r-dR8pkhZ3lfCpeLOWqvw" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;goodside&#x2F;status&#x2F;1559801520773898240?s=21...</a><p>I also have a few examples of more creative, non-program output in HTML and Markdown in this thread: <a href="https:&#x2F;&#x2F;twitter.com&#x2F;goodside&#x2F;status&#x2F;1560953991722418177?s=21&amp;t=-r-dR8pkhZ3lfCpeLOWqvw" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;goodside&#x2F;status&#x2F;1560953991722418177?s=21...</a><p>Interested in any feedback, especially from anyone who’s tried to apply my method to their own problems.

20 comments

fotcornover 2 years ago
Seems like this also works with C++. This was my first time using GPT3, and first attempt at this, no fine-tuning, no cherry picking at all:<p><pre><code> 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 &lt;iostream&gt; struct Vec3 { float x, y, z; Vec3(float x, float y, float z) : x(x), y(y), z(z) {} float dot(const Vec3&amp; 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 &lt;&lt; a.dot(b) &lt;&lt; std::endl; } ```</code></pre>
评论 #32533598 未加载
评论 #32533489 未加载
评论 #32533380 未加载
avinasshover 2 years ago
Wow, I had no idea this could be done!<p>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!<p>[0] - <a href="https:&#x2F;&#x2F;github.com&#x2F;avinassh&#x2F;rockstar" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;avinassh&#x2F;rockstar</a>
评论 #32534160 未加载
benreesmanover 2 years ago
I find it fascinating that it seems like there&#x27;s this emerging field of expertise around how to best interact with these gigantic LMs. I have no idea if this is like a passing fad during a gawky adolescent phase of the models, or if this is just a new thing that some people will always be at the cutting edge of.<p>I gather that there&#x27;s loose some precedent for the latter with the chess computer stuff: I&#x27;ve read that serious chess players heavily incorporate computers into their training and even that hybrid human&#x2F;computer teams often outperform either&#x2F;or teams. I&#x27;d love if someone who actually knows chess commented.<p>Generating code via model sampling seems to have different, or at least exaggerated imperatives around &quot;few-shot&quot; tuning. One might wish to generate natural language for any number of purposes, but there is a probably a stronger &quot;better&quot;&#x2F;&quot;worse&quot; 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 &quot;this code compiles&quot; from a big corpus, but to tune up the &quot;this vectorizes well&quot; eigen-tensor from Lemire&#x27;s repo.<p>Crazy times.
评论 #32537957 未加载
评论 #32539310 未加载
simonwover 2 years ago
I&#x27;ve been following Riley on Twitter and he&#x27;s a constant source of fantastic GPT-3 tips, recommended: <a href="https:&#x2F;&#x2F;twitter.com&#x2F;goodside" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;goodside</a>
评论 #32535108 未加载
ricardobayesover 2 years ago
Just as cybersecurity analyst jobs are getting reduced to comparing risk score numbers, maybe programming jobs will be &#x27;reviewing&#x27; machine-generated code in the future.
评论 #32538024 未加载
terafoover 2 years ago
Is it in your plans to do such thing with actually open model?(something like Codegen from Salesforce or BLOOM).
评论 #32533618 未加载
overviewover 2 years ago
I just copy and pasted 3 random Leetcode problem prompts to GPT-3. It successfully generated Python code that passed all test cases for 2 out of the 3.<p>Problems passed: - Two sum - Text Justification edit: Newlines
howon92over 2 years ago
Thanks for sharing this. I&#x27;ve been playing around with GPT-3 for a bit. Have you tried comparing this method to using the `insert` mode in the Playground?<p><a href="https:&#x2F;&#x2F;beta.openai.com&#x2F;playground?mode=insert" rel="nofollow">https:&#x2F;&#x2F;beta.openai.com&#x2F;playground?mode=insert</a><p>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?
评论 #32534381 未加载
potatoman22over 2 years ago
You should make this into a website generation playground
brunoolivover 2 years ago
Is co-pilot now mandatory to be paid? I used a trial for a long while, at least enough to miss it in my workflows once it went paid. Is this really the case? Last I checked it was like 12 dollars a month? Is it possible for it still to be free or are there free plug-ins for intellij that leverage it?<p>I loved it for some scaffolding, quick drafts or explore some language features, but, not enough to pay monthly for it (yet!)
评论 #32534010 未加载
b20000over 2 years ago
if you take a coding interview and answer the question by feeding it into GPT-3, does that mean you pass the interview? it must do really well since all it takes is memorizing the solutions to a large body of meaningless challenges.<p>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.
评论 #32536099 未加载
评论 #32536248 未加载
infogulchover 2 years ago
What I would really like is to get it to craft commit diffs of an existing codebase in response to a request.
评论 #32537115 未加载
maytcover 2 years ago
GPT-3 also understand code to some degree so it can run the code as instructed.<p><a href="https:&#x2F;&#x2F;mayt.substack.com&#x2F;p&#x2F;gpt-3-can-run-code" rel="nofollow">https:&#x2F;&#x2F;mayt.substack.com&#x2F;p&#x2F;gpt-3-can-run-code</a>
andreykover 2 years ago
This is using standard prompting I think? It&#x27;d be neat to try with the full &#x27;fill in the blank&#x27; (where the blank is in the middle of the input) generation technique LLMs can support, might work even better!
评论 #32535610 未加载
bredrenover 2 years ago
Reminds me some of Django or jinja template tags.<p>Except the tag names are free form and the source is generated rather than defined.
renewiltordover 2 years ago
This is a very clever piece of prompting. Thank you for the idea. Great discovery!
yomkippurover 2 years ago
should i cancel my sub to copilot?<p>alright how do i access gpt3 so i can write it like this?
评论 #32533402 未加载
评论 #32534853 未加载
sltkrover 2 years ago
Posting screenshots to Twitter has to be the least convenient way to share code online (short of actual trolling).
评论 #32536108 未加载
评论 #32533584 未加载
goodsideover 2 years ago
Clickable version of links:<p>Python, CSV, NDJSON, R, Markdown, and HTML examples: <a href="https:&#x2F;&#x2F;twitter.com&#x2F;goodside&#x2F;status&#x2F;1559801520773898240?s=21&amp;t=-r-dR8pkhZ3lfCpeLOWqvw" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;goodside&#x2F;status&#x2F;1559801520773898240?s=21...</a><p>More creative, non-program output in HTML and Markdown: <a href="https:&#x2F;&#x2F;twitter.com&#x2F;goodside&#x2F;status&#x2F;1560953991722418177?s=21&amp;t=-r-dR8pkhZ3lfCpeLOWqvw" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;goodside&#x2F;status&#x2F;1560953991722418177?s=21...</a>
评论 #32533416 未加载
snapcasterover 2 years ago
This is really cool, commenting so i can easily find this later to check out
评论 #32534396 未加载