[Tutor] LLM comparison

dn PythonList at DancesWithMice.info
Mon Jan 15 14:12:42 EST 2024


The latest branch of the "Debugging skills" thread involved a casual 
experiment in using ChatGPT3.5 and Claude2 to help a programmer debug 
his/her code after Python rejected lines which (s)he reasonably-expected 
to work.

If you haven't been following that thread, and this topic piques your 
interest, perhaps you'd like to review the former and add your reactions 
or comments?


Meantime, I approached the problem in (what seems to me) the more common 
mode ('what the kids are doing today'): by presenting the LLM with the 
problem itself, and asking the 'AI' to generate code.

The wording is in a slightly pompous, academic style, in order to 
extract comparative-responses:-


Question:
The requirement is a Python function which given an integer-number, will 
return a list populated with values equal to that value's index or 
relative-position in the list.
Please provide three answers: (1) code likely to be produced by a 
Python-Beginner, (2) code likely to be produced by an Intermediate-level 
programmer, and (3) code from a Python-Master.


ChatGPT3.5:
Certainly! Here are three versions of the Python function as per your 
request:

1. **Beginner Level:**
```python
def beginner_function(number):
     result_list = []
     for i in range(number):
         result_list.append(i)
     return result_list
```

2. **Intermediate Level:**
```python
def intermediate_function(number):
     return [i for i in range(number)]
```

3. **Python Master Level:**
```python
from itertools import range

def master_function(number):
     return list(range(number))
```

These implementations achieve the same result, creating a list with 
values equal to their index or relative position in the list, but differ 
in terms of simplicity, conciseness, and utilization of advanced 
features of Python.


Claude2:
  Here are three potential solutions to the given problem at different 
Python experience levels:

1. Beginner solution:

```python
def populate_list(num):
     new_list = []
     for i in range(num):
         new_list.append(i)
     return new_list
```

2. Intermediate solution:

```python
def populate_list(num):
     return list(range(num))
```

3. Expert solution:

```python
populate_list = lambda num: list(range(num))
```

The beginner creates an empty list first and uses a for loop to append 
each index.

The intermediate programmer leverages the built-in range() function and 
typecasts it to a list directly.

The expert uses a lambda function to achieve the same result as the 
intermediate solution, but in a simple one-liner expression.

In summary, the solutions showcase Pythonic techniques getting more 
advanced from basic procedural logic to built-in functions to functional 
programming.



Thus, the question elicited expected responses. What do you think?

Both of the 'Expert solutions' contained rather 'frilly bits' - perhaps 
an attempt to convince us of Mastery rather than a true demonstration 
thereof?

The first/Beginner-level responses are essentially-identical.

Would you expect that most folk improving the Beginner's 'traditional' 
for-loop approach would graduate to a list-comprehension?

There was no need for ChatGPT (response 3) to import itertools (it's not 
used anyway) - the built-in function does the job.

That Claude2 failed to suggest a list-comprehension was a surprise. What 
do you think?

Do you agree that Claude2's proposition of a lambda as "simple 
one-liner" demonstrates mastery?

Indeed is that 'better' than its own 'Intermediate solution'?

Between the two LLMs, compare their choices of names. How do they 
contribute to a reader's comprehension (ignoring the lack of docstrings, 
or indeed imagining that such are present). What do you think 
(particularly if was part of a much larger code-base)?

Other thoughts?


-- 
Regards,
=dn


More information about the Tutor mailing list