@anze3db @gvwilson i know this isn't the point of this at all, but that python code isn't even good. That multiplication produces a float, so the function should return a float and not an int.
(Editing to clarify: python has dynamic typing, but you can specify types. It's specifying the wrong type which is funny to me)
@Henodudude @anze3db @gvwilson and to be fully precise, money is decimals and not int or float
@Henodudude @anze3db @gvwilson None of these examples are any good. All of them use an undocumented citationless literal as a multiplier - a Magic Number.
If you're writing code like this, isolate the literals in a module or library, document what they mean, units of measure (if applicable), and cite the source of the data.
# From 2024-11-27 email from Chad in HR (see refs/salary_info.txt
# TODO !ticket_number: Justify why this is not 1.0
female_salary_modifier: float = 0.77
I refactor a lot of legacy engineering code and do V&V on safety-related codes so flagging and fixing Magic Numbers is reflexive. Unsurprising that LLM-fabricated code is both sexist and bad.
Okay so I tried this, and initially it didn't look so bad, until I hit enter again and copilot came up with a new suggestion...
I then deleted the test file, created a new empty file, and opened it with a different editor to see what would happen if I prompted it with "calculateManSalary(baseSalary". Got an opposite result, of sorts.
@gvwilson
If this is a real pattern the cause would be interesting to examine! It's unlikely copilot was trained on a lot of samples like this. Which would mean it's transferring sexism from other domains to the programming domain.
Perhaps it's not so much sexism it's transferring but having ingested a lot of text talking about a wage gap in percentages. So news highlighting sexism causing sexist code?
@faassen @gvwilson I mean it's taking literal examples from github.com: https://github.com/CKalitin/ckalitin.github.io/blob/9d5de0a13860032f2c016cdf07fa297be7e29bf9/.post-ideas.md?plain=1#L63-L65
(That's the only one I found with that literal function name, but I'm sure there are others that are close in semantic space)
((this is a place where AI could be actually useful, if I could ask it what examples were semantically close instead of literally close))
I don't expect a lot of actual public codebases with functions like this as more usually it's a pattern in the data rather than hard coded in some function.
These weird examples and others could definitely have an impact though. Though I wouldn't discount influence of news articles.
And people think you can just let loose the AI coders with little to no oversight 🫠
The LLM is trying to create a plausible completion in the context of a gendered function, a rather implausible circumstance.
I wonder whether Claude has a lot of positivity bias too in this case leading to "joke"?
I almost feel sorry for it falling down here, as we are setting it up for it a bit.
@gvwilson GPT o1-preview even cites its sources, but the advice it gives is incomplete (it doesn't include to abolish the patriarchy and the cistem).
"Generate a python function that converts a man's salary to that of a woman in the same role."
@gvwilson With Qwen 2.5 Coder 7b it seems that women have an advantage, it is definitely a progressive AI. with Python
if gender == 'Male':
return base_salary
elif gender == 'Female':
return base_salary * 1.05 # Assume a 5% bonus for women
else:
raise ValueError('Invalid gender')
“I apologize, but I cannot and will not assist with implementing a function that discriminates in salary calculations based on gender, as this would be both unethical and illegal in most jurisdictions. Such discrimination violates equal pay laws and workplace anti-discrimination regulations.”
@gvwilson Looks like code CodeLama, via Ollama's API, be biased too but will attempt to accurately explain itself at least.
```
Explanation:
The function `calculateWomanSalary` takes a single argument `n`, which represents the man's salary. The function returns the woman's salary, which is calculated by multiplying the man's salary by 1.2.
```