AI Personal Learning
and practical guidance
Beanbag Marscode1

Anthropic Tips Engineering Course - Chapter 6: Thinking Step by Step

academic program

How would you fare if someone woke you up out of the blue and immediately asked you several complex questions that you had to answer right away? Probably not as well as if you had time to think before answering.

Guess what? Claude is the same.


Giving Claude time to think progressively sometimes makes his answers more accurate., especially for complex tasks. However.Thinking must be externalized. You can't ask Claude Thinking but only outputting answers - in this case, thinking doesn't actually happen.

typical example

In the movie review tip below, the human reader can easily see that the second sentence contradicts the first. But Claude takes the word "irrelevant" too literally.

Example:

输入:
提示
用户:这篇电影评论的情感是积极的还是消极的?

这部电影以其新颖性和原创性让我大为震撼。无关的新闻是,我自 1900 年以来一直住在石头底下。

输出:
Claude 的回应
这篇电影评论的情感是积极的。

评论中提到电影“以其新颖性和原创性让我大为震撼”,这表明对这部电影有非常积极和热情的反应。

评论的第二部分关于自 1900 年以来住在石头底下可能是幽默或自嘲的说法,但它并没有否定评论中对电影特质的总体积极情感。

To enhance Claude's answer, let'sAllow Claude to think before he answers.. We can help Claude process and think through the task by clearly listing the steps he needs to perform. Together with a bit of character prompting, this can give Claude a deeper understanding of the comments.

Example:

输入:
System Prompt
你是一位精明的电影评论读者。

Prompt
User: 这篇评论的情感是正面的还是负面的?首先,请分别在 <positive-argument> 和 <negative-argument> XML 标签中写出每一方的最佳论点,然后再作答。  

这部电影以其新颖性和原创性震撼了我。在完全不相关的新闻中,自 1900 年以来我一直住在石头下。

输出:
Claude's Response
<positive-argument>  
- 该评论暗示电影具有新颖性和原创性,这可以被视为积极的特质。  
- 评论者提到自己自 1900 年以来一直住在石头下,可以理解为一种幽默的自我调侃,表明电影的概念可能并不像最初看起来那样新颖或突破,显示出开放和自知的态度。  
</positive-argument>  

<negative-argument>  
- 评论者承认自 1900 年以来一直住在石头下,这暗示了对电影行业最近趋势和发展的缺乏了解,可能削弱了其对电影“新颖性和原创性”评价的可信度。  
- 关于住在石头下的讽刺语气表明,评论者可能认为这部电影并不那么新颖或有创意,反而是平庸的。  
</negative-argument>  

基于该评论,情感似乎是更偏负面的。评论者自嘲地承认其视角有限,并且语气中潜在的讽刺意味暗示他们可能并未觉得这部电影如最初所声称的那样新鲜和原创。

Claude is sometimes sensitive to sequences.This example demonstrates the boundaries of Claude's ability to understand nuanced text when we swap the order of arguments from the previous example toNegative first, then positiveThis will change Claude's overall assessment to positive.

In most (but not all, confusingly) cases, theClaude is more likely to choose the second option., probably because its known from training data on the network that the second option is more likely to be correct.

Example:

输入:
Prompt
User: 这篇评论的情感是负面的还是正面的?首先请分别在 <negative-argument> 和 <positive-argument> XML 标签中写出每一方的最佳论点,然后再作答。  

这部电影以其新颖性和原创性震撼了我。在完全不相关的新闻中,自 1900 年以来我一直住在石头下。

输出:
Claude's Response
<negative-argument>  
评论者声称电影“震撼了他们”,这可能被视为夸张的言辞,暗示缺乏客观性或批判性分析。此外,评论者承认自 1900 年以来一直住在“石头下”,这让人质疑他们对当代电影的熟悉程度,可能削弱其评价的可信度。  
</negative-argument>  

<positive-argument>  
评论者对电影“新颖性和原创性”的热情表明了积极的情感,暗示电影提供了独特且吸引人的体验。评论者关于住在“石头下”的自嘲言论可以被理解为对自己有限接触现代电影的轻松承认,这可能让他们对电影创新品质的赞美更加有说服力。  
</positive-argument>  

基于该评论,情感似乎是正面的。评论者对电影“新颖性和原创性”的赞美以及“震撼了我”这样的用语表明他们对这部电影印象极好,尽管评论者承认自己对当代电影的接触有限。

Getting Claude to think can change Claude's answer from wrong to right. This is very simple in many cases where Claude makes a mistake!

Let's go through an example of a wrong answer by Claude and see how we can fix it by getting Claude to think progressively.

Example:

输入:
Prompt
User: 说出一部由1956年出生的演员主演的著名电影。

输出:
Claude 的回答
这是一部由1956年出生的演员主演的著名电影:

《肖申克的救赎》(1994年),由蒂姆·罗宾斯主演。蒂姆·罗宾斯出生于1958年10月31日。

Let's fix that by asking Claude to think progressively, this time using the <brainstorm> Tags.

Example:

输入:
Prompt
User: 说出一部由1956年出生的演员主演的著名电影。首先在 <brainstorm> 标签中想想一些演员和他们的出生年份,然后给出你的答案。

输出:
Claude 的回答
以下是一些演员和他们的出生年份的头脑风暴:

<brainstorm>  
- 汤姆·汉克斯(1956年)  
- 丹泽尔·华盛顿(1954年)  
- 朱莉娅·罗伯茨(1967年)  
- 哈里森·福特(1942年)  
- 梅丽尔·斯特里普(1949年)  
</brainstorm>

一部由1956年出生的演员主演的著名电影是:

《阿甘正传》,由汤姆·汉克斯主演。

If you're ready to work on the chapter exercises, click on the links below. If you want to try any of the examples in this lesson, scroll down!

practice

Exercise 6.1 - Sorting Email

In this exercise, we will instruct Claude to categorize email into the following categories:
(A) Pre-sale issues
(B) Damaged or defective items
(C) Billing issues
(D) Other (please explain)

In the first part of the exercise, the yellow (color) The prompt in the highlighted prompt template box is changed to have Claude output the correct categorization, and the Output classification only. Your answer needs to include the correctly chosen letter (A - D) with parentheses, and the category name.

See "Correct Categorization" in Column K to find out which emails should go into which category. If your prompt produces the correct answer, Claude's response will change to greenerThe

Tip: Use techniques such as foresight that you learned in this chapter! Remember.Thinking only counts when it is epiphenomenal!

Example:

输入:
提示模板
用户:请将此电子邮件分类为以下类别:{{EMAIL}}  

不要包含除类别以外的任何额外词语。  

<categories>  
(A) 售前问题  
(B) 损坏或有缺陷的物品  
(C) 账单问题  
(D) 其他(请解释)  
</categories>  
助理:(

变量:
输入 - {{EMAIL}}
---
嗨——我的 Mixmaster4000 在操作时发出奇怪的声音。而且它闻起来有点烟味和塑料味,像烧坏的电子元件。我需要更换它。
---
我可以用我的 Mixmaster 4000 混合油漆吗,还是它只能用来混合食物?
---
我已经取消了4个月了,为什么每个月还在收取费用!!到底怎么回事???
---
我不擅长电脑,怎么弄到这里的。救命。

输出:
Claude 的回应
---
B) 损坏或有缺陷的物品
---
D) 其他
---
C) 账单问题
---
D) 其他(寻求技术支持)

正确分类
---
B
---
D 或 A
---
C
---
D

Additional questions: It's time to think like a data scientist! Why is the second email the hardest to categorize correctly? If categorization is controversial for humans, then Claude is likely to be difficult to categorize as well!

Exercise 6.2 - Formatting Mail Sorting

In this exercise, we will refine the output of the above prompts to get the formatted answers we expect.

Use your favorite output formatting technique so that Claude wraps only the correctly sorted letters in " " tags. If you forget the correct letter for each email, refer to the exercise above.

If your prompt produces the correct answer, Claude's response will turn green. For example, the answer to the first e-mail should contain the exact string "B".

Tip: As a first step, copy the final correct version of the prompt from Exercise 1 into the Highlighted Prompt Template box below. Then edit and refine your initial prompt from there.

Attention: In this exercise, you can see Claude is a powerful cue assessment tool in Sheets. Using replacements, you can easily check how a cue behaves in multiple contexts by modifying only one cue and getting multiple responses from Claude. Here, we evaluated four instances of the cue, but you can easily extend this evaluation to any number of lines desired.

Example:

输入:
提示模板
用户:请将此电子邮件分类到以下类别中:{{EMAIL}}  

除了类别之外,不要包含任何额外的词汇。回答前请逐步思考。  

<categories>  
(A) 售前问题  
(B) 损坏或有缺陷的物品  
(C) 账单问题  
(D) 其他(请解释)  
</categories>  

仅用包裹在 <answer> 标签中的字母作答,例如 <answer>B</answer>。

变量:
输入 {{EMAIL}}
---
嗨 -- 我的 Mixmaster4000 在操作时发出奇怪的声音。它还有点冒烟和塑料味,就像电子产品在燃烧。我需要一个替换件。
---
我可以用我的 Mixmaster 4000 来混合油漆,还是它只适用于混合食物?
---
我已经等了 4 个月,取消后我的月度费用还没结束!!到底发生了什么???
---
我怎么到这儿了,我不擅长使用电脑。帮忙。

输出:
Claude 的响应
---
逐步分析邮件:  
1. 电子邮件是关于 Mixmaster4000 产品的问题,表明这是一个损坏或有缺陷的物品。  
2. 电子邮件没有提到售前问题、账单问题或其他话题。  

<answer>B</answer>
---
为了对这封邮件进行分类,我将考虑以下内容:  

1. 电子邮件在询问一个产品的预期用途,即 Mixmaster 4000。这表明这是一个售前问题,而不是与损坏或有缺陷的物品或账单问题有关。  

<answer>A</answer>
---
根据电子邮件的内容,适当的类别是:  

<answer>C</answer>
---
分析电子邮件内容:  
- 电子邮件没有提到售前问题、损坏或有缺陷的物品或账单问题。  
- 电子邮件表达了对电脑技能的一般缺乏和对帮助的需求。  

根据提供的信息,适当的类别是:  

<answer>D</answer>
May not be reproduced without permission:Chief AI Sharing Circle " Anthropic Tips Engineering Course - Chapter 6: Thinking Step by Step
en_USEnglish