̽̽

Author

Clayton Cafiero

Published

2025-01-31

Example: One-shot / few-shot learning

It’s often helpful to use something akin to one-shot learning or few-shot learning when engineering prompts. This approach involves providing a concrete example or a few concrete examples to show the model what you’d like in its response.

First, we’ll provide a naïve prompt, show where it goes astray, and then see how we can improve our results by providing a single example.

Say you’re teaching a first course in linear algebra, and you’d like some problems either for classroom demonstration or as an assignment.

The naïve prompt

Naïve prompt


Can you give me three problems that require Gauss-Jordan reduction?

ChatGPT’s response to the naïve prompt

ChatGPT’s response


Sure! Here are three problems that require Gauss-Jordan elimination for their solutions:

Problem 1: Solving a System of Linear Equations

Solve the following system of equations using Gauss-Jordan elimination:

2x + 3y - z = 5

4x - y + 5z = 6

-2x + 4y + 3z = 7

Problem 2: Finding the Inverse of a Matrix

Find the inverse of the following matrix using Gauss-Jordan elimination:

A = \begin{bmatrix} 1 & 2 & 3 \\ 0 & 1 & 4 \\ 5 & 6 & 0 \end{bmatrix}

(Hint: Augment ( A ) with the identity matrix and row-reduce.)

Problem 3: Determining Linear Dependence of Vectors

Determine whether the following vectors are linearly dependent using Gauss-Jordan elimination:

v_1 = (1, 2, 3, 4), \quad v_2 = (2, 4, 6, 8), \quad v_3 = (3, 6, 9, 12)

(Hint: Form a matrix with these vectors as rows and row-reduce to check for a row of zeros.)

Would you like me to go through the solutions as well?

Commentary on ChatGPT’s response to the naïve prompt

This is interesting. It’s not incorrect, and for some, this might be exactly the answer they were looking for: what kinds of problems can I solve using Gauss-Jordan elimination?

However, if the instructor is looking for a few elementary examples of solving systems of linear equations, they’d need some prompt engineering.

Claude’s response to the naïve prompt

Claude’s response


I’ll provide three problems that can be solved using Gauss-Jordan reduction, arranged in increasing order of complexity.

  1. System of Linear Equations: Solve the following system:
2x + y - z = 4
3x - y + 2z = 1
x + y + z = 6
  1. Matrix Inverse: Find the inverse of the following matrix, if it exists:
[2  1  0]
[1  3  1]
[0  1  2]
  1. Finding Basis for Nullspace: Find a basis for the nullspace of the following matrix:
[1  2  1  -1]
[2  4  0   2]
[3  6  1   1]

For each of these, Gauss-Jordan reduction would be used differently: - For the system of equations, we’d reduce the augmented matrix to row echelon form - For the matrix inverse, we’d use the augmented matrix [A|I] and reduce to [I|A⁻¹] - For the nullspace basis, we’d reduce to row echelon form and then use the free variables to find vectors in the nullspace

Would you like me to demonstrate the solution process for any of these problems?

Commentary on Claude’s response to the naïve prompt

Claude’s response is remarkably similar to that of ChatGPT.

A better prompt

Adding a single example is sufficient to get a much more focused response.

Prompt with single example


Here’s an example of what I’m after:

Solve:

x + y - 2z = -2 \\ y + 3z = 7 \\ x - z = -1

Can you solve this, and then produce three more problems of similar difficulty and number of variables?

ChatGPT’s response

ChatGPT’s response


The solution to the given system:

x + y - 2z = -2

y + 3z = 7

x - z = -1

is:

x = 1, \quad y = 1, \quad z = 2


Here are three more problems of similar difficulty:

Problem 1:

Solve the system using Gauss-Jordan elimination:

x + 2y - z = 3

2x - y + 3z = 4

3x + y + 2z = 5


Problem 2:

Solve the system using Gauss-Jordan elimination:

2x - y + 3z = 7

x + 3y - 2z = -4

3x + y + z = 5


Problem 3:

Solve the system using Gauss-Jordan elimination:

x - 2y + z = 4

3x + y - 4z = -3

2x - y + 3z = 5

Would you like me to solve these as well?

Claude’s response

Claude’s response


I’ll solve this example step by step, then give you three similar problems.

First, let’s solve the given system using Gauss-Jordan reduction:

The augmented matrix is:

[1  1  -2 | -2]
[0  1   3 |  7]
[1  0  -1 | -1]

Step 1: Subtract row 1 from row 3 to eliminate x

[1  1  -2 | -2]
[0  1   3 |  7]
[0 -1   1 |  1]

Step 2: Add row 2 to row 3 to eliminate y

[1  1  -2 | -2]
[0  1   3 |  7]
[0  0   4 |  8]

Step 3: Solve for z using row 3: z = 2

Step 4: Substitute z = 2 into row 2: y + 3(2) = 7, so y = 1

Step 5: Substitute z = 2 and y = 1 into row 1: x + 1 - 4 = -2, so x = 1

Solution: x = 1, y = 1, z = 2

Here are three similar problems:

  1. Solve: x + 2y - z = 3 2y + 3z = 8 x + z = 2

  2. Solve: 2x - y + z = 4 y - 2z = -3 x + y = 5

  3. Solve: x + y + z = 6 2y - z = 1 x - z = 2

Each of these systems has: - Three variables (x, y, z) - Three equations - Integer coefficients that are small (-3 to 3) - Solutions with reasonable numbers - Similar complexity in the reduction process

Would you like me to solve any of these new problems?

Commentary on responses by ChatGPT and Claude

By providing a single example in the prompt we get more-or-less exactly what we were after.

Claude’s response includes augmented matrices which is nice but not essential.

Reuse