News for hackers. Stuff that matters.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by fotcorn on Saturday August 20, 2022 @12:43PM (#32533354)
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:

    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;
    }
    ```
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by TakeBlaster16 on Saturday August 20, 2022 @01:12PM (#32533598)
I had no idea GPT-3 could write code! It seems to do pretty well even with a one-sentence prompt:

  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);
  }
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by goodside on Saturday August 20, 2022 @01:19PM (#32533650)
In general, anything that has a “textbook” solution is easy. What it’s doing here is more recitation than synthesis. Where it becomes harder, and where my method is necessary, is when you need to specify the structure of the solution yourself because the model can’t get there on its own.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by lossolo on Sunday August 21, 2022 @11:57AM (#32541405)
Exactly, that's why GPT3 generated things that were not included in task description in C++ example like reading the numbers first and then printing them. Same thing in Rust, here vectors are static, while in C++ you were asked. All because of examples on which the model was trained.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by b20000 on Saturday August 20, 2022 @06:38PM (#32535772)
the reason it does well is because you gave it a question that might come up in coding interviews.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by michannne on Saturday August 20, 2022 @06:51PM (#32535858)
I think that's amazing on its own. Rather than having to do a leetcode hard on the fly, you can just ask for the solution. You'll still need to know the problem space in order to properly optimize it, but it can save a lot of time.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by Max-q on Saturday August 20, 2022 @06:01PM (#32535536)
It’s incredible. I have used it to make several arduino programs for me, controlling different hardware and connecting them. It’s just amazing.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by wyldfire on Saturday August 20, 2022 @12:59PM (#32533489)
> Replace the $$dollar-quoted expressions$$ with the content described therein, or follow the directions they contain.

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?

Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by sp332 on Saturday August 20, 2022 @01:19PM (#32533651)
Here's one of the craziest examples I've seen. It's just a page of instructions, and GPT-3 follows them https://mobile.twitter.com/goodside/status/15575245464120524...
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by andrepd on Saturday August 20, 2022 @01:42PM (#32533812)
I have just a question: how many prompts did it completely fail for each prompt it answered brilliantly? 5? 10? 100? That's what these "twitter threads showing gpt3 doing astonishing things" fail to show.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by goodside on Saturday August 20, 2022 @01:48PM (#32533838)
Many! In this example, my question was explicitly, “How many diverse tasks can I stack into a single generation before it becomes unreliable?” If you scroll down in the thread, I explain that these questions are on the “golden path” of tasks GPT-3 does well. There are any number of simple tasks I could have given it, like writing a sentence backwards or summing a list of 10 numbers, where it would fail every time.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by nodespace on Saturday August 20, 2022 @05:12PM (#32535170)
Is there any way to get it to respond the same way when something is outside the golden path? So for example, if you gave it the backwards sentence task, it would respond with "I don't know how to do this" or really any way of programatically evaluating that it failed, without needing to know what the task itself was.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by janekm on Saturday August 20, 2022 @05:26PM (#32535260)
Knowing whether or not it’s giving you a sensible response is one of the things that are hard for gpt-3, unfortunately. It has no concept of failing.
Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by goodside on Saturday August 20, 2022 @05:42PM (#32535384)
On the contrary, doing a two-stage generation where the second stage simply judges whether a generation is correct can help a lot. It works even better if you give it several generations and let it choose whichever is the most truthful. I wrote a basic example of this here that uses my own confabulation-suppressing prompt in the first stage, but simpler variations of this exist in the published literature: https://twitter.com/goodside/status/1559586486705602562?s=21...

The hallucination-suppressing prompt it implicitly uses the output of is here: https://twitter.com/goodside/status/1556459121834168320?s=21...

Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by goodside on Saturday August 20, 2022 @05:25PM (#32535253)
Yes. You can, with effort, condition it to respond sensibly with phrases like “I’m sorry, I don’t know how to reverse strings,” or “I’m sorry, I can’t do any math calculation that a human couldn’t do in their head.” But in doing so you damage its ability to do some tasks it’s actually capable of, e.g. reciting a memorized answer to “What is the fourth root of 625?” Its memorization abilities are insane: It seems to know, for example, the exact MD5 hashes of all single-character alphanumeric strings. Much of the arithmetic it knows is probably similarly memorized, and it’s hard to clarify for it what aspects of that memory are safe to use.

The initial problem that got me interested in GPT-3 is suppressing confabulated answers to the Hofstadter-Bender questions published in The Economist. I eventually found an apparent solution but I’m yet to carefully validate it: https://twitter.com/goodside/status/1556459121834168320?s=21...

Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by wyager on Saturday August 20, 2022 @01:20PM (#32533663)
> 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).

Re:Tell HN: A new way to use GPT-3 to generate code (and eve... by goodside on Saturday August 20, 2022 @12:47PM (#32533380)
Nice! In general these are better if you run them at the lowest possible temperature. I.e., try temp=0 first for deterministic output and then raise slowly if you need to cherry-pick a better generation.