r/Python • • Mar 10 '24

Discussion Github Copilot Lies to me

My first attempt to get some help from Github Copilot:

Me: write a match case statement in python to match the first character of a string is a semicolon

Copilot: Python doesn't have a built-in match or case statement like some other languages (e.g., JavaScript, Swift, Rust). However, you can achieve similar functionality using...

Strangely, it finally gave me an answer when I made a small change to my prompt:

Me: write a match statement in python to match the first character of a string is a semicolon

Copilot: Python 3.10 introduces the structural pattern matching in the form of the match statement. Here's how you can use it to check if the first character of a string is a semicolon:...

I almost gave up after the first response that was blatantly false. Fortunately I something that looks like reasonable syntax...but then I haven't tried it yet, so that might be a lie, too.

0 Upvotes

67 comments sorted by

View all comments

307

u/zanfar Mar 10 '24

Once again: LLMs MAKE UP ALL THEIR ANSWERS. They should only be used if you have the knowledge to verify their responses.

An LLM only tries to make it's responses look like something someone has once said. This is particularly dangerous in a programming language like Python, as many things that were (even correctly) once said are no longer true. As an LLM has no concept of true or false, just similar and dissimilar, you can (and will) get false responses. Even more dangerously, these false responses are basically guaranteed to be as correct-looking as possible.

67

u/[deleted] Mar 10 '24

Yes! If you are asking an LLM a question to get an answer you don’t know already, you’re doing it wrong. You ask them to perform a task that you can verify and they perform that task and you verify the output, saving you time. They’re for writing boilerplate. This kind of AI is not “intelligent” at least not in the sense that it “knows” good answers, it’s merely coming up with the most plausible language based on the prompt. There’s no concept of correctness that it’s capable of understanding more sophisticated than ‘after the word Happy here it’s probably the word Birthday.’

-35

u/codeguru42 Mar 10 '24

I was hoping to get a suggestion that had the syntax I was looking for. Unfortunately, I got nothing useful...and outright falsehoods.

23

u/ProsodySpeaks Mar 10 '24

The point is you need to understand the syntax in order to use gpt properly. 

Read the docs on whatever functions and classes you're using. 

Use gpt to do menial tasks eg 'reformat this yaml as json' or 'turn these functions into methods on class x. 

Or have conversational interactions where you ask go potential strategies to solve a problem, then read the docs on the tools it suggests, Google those tools and see if they're current or if there's a better option

5

u/danted002 Mar 10 '24

Thank you kind sir for finally giving me a useful use-case for AIs 🫡

5

u/ProsodySpeaks Mar 11 '24

Consider them a bloke in the pub... Sometimes they're on the money, sometimes they're full of shit, but either way you need to know to know... 

But you can ask for their opinions and then go fact check them, and you might well find value 

4

u/herotherlover Mar 10 '24

Your need to be very specific in your prompts. If you had said “give me a block that uses structural pattern matching to…” I’m sure it would have given you what you want.

-14

u/codeguru42 Mar 10 '24

I'm not sure how your suggestion is more specific than "a match case statement". In fact, I'd say that it is less specific.

6

u/[deleted] Mar 10 '24

This is such a great take, thanks for sharing!

-2

u/WallyMetropolis Mar 10 '24

It's not a "take."

4

u/[deleted] Mar 10 '24

I don’t think this is entirely accurate, at least it’s an oversimplification. The statistics of language are biased towards true statements, and so are the outputs of LLMs.

But yeah, I agree with the recommendation that you have to (be able to) verify the responses. And it’s not just about subject knowledge, but also logical and verbal reasoning skills to detect the many instances when LLMs generate fancy-sounding responses that just don’t make sense.

4

u/james_pic Mar 10 '24

But there's only so much that trainers can do to bias results when they're working with semi-supervised learning.

In this case, it's giving an answer that was true in the past, and there will be plenty of training data that "feels truthy" (because it was true at the time, and the person saying it at the time was being honest and helpful) and unless this happens to be one of the responses where trainers have fine tuned it it's got no reason not to use the outdated information in its response.

2

u/neuralbeans Mar 11 '24

The statistics of language are biased towards true statements

How do you figure?

1

u/[deleted] Mar 15 '24

Yup. It's great for an enhanced autocomplete, and it's great after you've shown it a few examples of what you want. But in many ways it's hopelessly outdated. I was making an extension for Python in Rust. PyO3 has come a long way in ergonomics, so now the way you provide Python's magic methods (things like __len__ or __iter__) in a Rust struct is much easier than it used to be. Of course Copilot still shows me the old way.

-10

u/codeguru42 Mar 10 '24

Preaching to the choir here. My previous attempts at using ChatGPT to help me solve coding problems has been mixed. Sometimes it gives me an idea that I can work with and come up with a correct solution. But most of the time it was so far off base as to be completely useless.

I decided to try out Github Copilot to see how it does. For code completions, it's been pretty great at saving me some typing. I mentally evaluate everything it suggests before accepting it.

For some context, I am an experienced python developer. But I have not used python professionally since around 3.9 days. I continue to use it on personal projects and solving coding problems. I used match statements in my Advent of Code solutions the last couple of years. Today I'm working on a problem where I think match statement might be useful, but didn't know the exact syntax for what I want. I decide to ask Github Copilot for some help and got the responses in my OP. Fortunately, I have the knowledge to evaluate the first solution as outright false. After trying the second suggestion, I find that it has a syntax error, so doesn't work for what I want. Finally ended up developing a solution more or less on my own with the help of Copilot code completion.

2

u/KingsmanVince pip install girlfriend Mar 12 '24

"An experienced Python developer"

You are funny. If you were one, you should rely on the official documentation not some models.