AI Prompt Engineering · บทเรียน

พรอมต์ให้คะแนนตามเกณฑ์ประเมิน

เกณฑ์ประเมินแบบมีโครงสร้าง: ความถูกต้อง ความลื่นไหล ความเกี่ยวข้อง และความปลอดภัย (ระดับ 1-5)

บทเรียน 2 จาก 413 ขั้นตอน

พรอมต์ให้คะแนนตามเกณฑ์ประเมิน เป็นบทเรียน AI Prompt Engineering ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AI Prompt Engineering และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AI Prompt Engineering มีบทเรียนทั้งหมด 4 บทเรียน

การให้คะแนนตามเกณฑ์คืออะไร

การให้คะแนนตามเกณฑ์จะมอบชุดเกณฑ์ที่มีโครงสร้างพร้อมคำจำกัดความที่ชัดเจนสำหรับแต่ละระดับคะแนนให้ผู้ตัดสิน LLM แทนที่จะถามว่า ‘สิ่งนี้ดีแค่ไหน’ ให้ถามว่า ‘สิ่งนี้ได้คะแนนเท่าใดในแต่ละมิติเฉพาะเหล่านี้’

เกณฑ์ช่วยลดอคติ เพิ่มความสอดคล้อง และทำให้ผลการประเมินตีความและนำไปใช้ได้

โครงสร้างของเกณฑ์การให้คะแนน

เกณฑ์ที่ออกแบบมาอย่างดีมีองค์ประกอบสามส่วน:

  1. ชื่อเกณฑ์: มิติที่ต้องประเมิน (ความถูกต้อง ความครบถ้วน ความชัดเจน)
  2. เกณฑ์อ้างอิงคะแนน: คำจำกัดความอย่างชัดเจนว่าคะแนนแต่ละระดับมีความหมายอย่างไรสำหรับเกณฑ์นั้น
  3. น้ำหนักหรือลำดับความสำคัญ: เกณฑ์ใดสำคัญที่สุดสำหรับกรณีใช้งานนี้

องค์ประกอบแต่ละส่วนช่วยจำกัดขอบเขตงานของผู้ตัดสินและทำให้สามารถทำซ้ำได้

คำสั่งเกณฑ์การให้คะแนนสามเกณฑ์

ต่อไปนี้คือแม่แบบคำสั่งเกณฑ์ที่เป็นรูปธรรมสำหรับประเมินคำตอบจากปัญญาประดิษฐ์ด้านความถูกต้อง ความครบถ้วน และความชัดเจน ผู้ตัดสินจะส่งคืนข้อมูลเจสันที่มีโครงสร้างพร้อมคะแนนแยกตามแต่ละเกณฑ์

import anthropic
import json

client = anthropic.Anthropic(api_key='sk-ant-...')

RUBRIC_PROMPT = (
    'Score this response on a scale of 1-5 for each criterion:\n\n'
    'ACCURACY: Is the response factually correct?\n'
    '  1=Contains significant factual errors\n'
    '  3=Mostly correct with minor inaccuracies\n'
    '  5=Completely accurate with no errors\n\n'
    'COMPLETENESS: Did it answer everything asked?\n'
    '  1=Missed most of the question\n'
    '  3=Answered the main question but missed sub-parts\n'
    '  5=Addressed every part of the question\n\n'
    'CLARITY: Is it easy to understand?\n'
    '  1=Confusing, hard to follow\n'
    '  3=Understandable but could be clearer\n'
    '  5=Exceptionally clear and well-organized\n\n'
    'Question: {question}\n'
    'Response: {response}\n\n'
    'Return JSON: {{"accuracy": N, "completeness": N, "clarity": N, '
    '"overall": N, "notes": "one sentence"}}'
)

def rubric_judge(question, response):
    prompt = RUBRIC_PROMPT.format(question=question, response=response)
    r = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=200,
        messages=[{'role': 'user', 'content': prompt}]
    )
    return json.loads(r.content[0].text)

result = rubric_judge(
    question='What is a REST API?',
    response='A REST API is a way for applications to communicate over HTTP.'
)
print(result)

การให้คะแนนแบบถ่วงน้ำหนัก

เกณฑ์แต่ละข้อไม่ได้มีความสำคัญเท่ากัน สำหรับบอตสนับสนุนลูกค้า ความมีประโยชน์สำคัญกว่าสไตล์การเขียนเชิงวรรณศิลป์ การให้คะแนนแบบถ่วงน้ำหนักช่วยให้คุณแสดงลำดับความสำคัญเหล่านี้ในการคำนวณคะแนนสุดท้ายได้

import anthropic
import json

client = anthropic.Anthropic(api_key='sk-ant-...')

def weighted_rubric_judge(question, response, weights):
    """
    weights: dict of criterion -> weight (should sum to 1.0)
    Example: {'accuracy': 0.5, 'completeness': 0.3, 'clarity': 0.2}
    """
    RUBRIC = (
        'Score this response 1-5 on:\n'
        'Accuracy: Is it factually correct?\n'
        'Completeness: Does it cover the full question?\n'
        'Clarity: Is it easy to understand?\n\n'
        'Q: {q}\nA: {a}\n\n'
        'Return JSON: {{"accuracy":N,"completeness":N,"clarity":N}}'
    )
    r = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=100,
        messages=[{'role': 'user', 'content': RUBRIC.format(q=question, a=response)}]
    )
    scores = json.loads(r.content[0].text)

    # Calculate weighted average
    weighted_score = sum(
        scores[criterion] * weight
        for criterion, weight in weights.items()
        if criterion in scores
    )
    print(f'Individual scores: {scores}')
    print(f'Weighted score: {weighted_score:.2f}/5')
    return weighted_score

weighted_rubric_judge(
    'How do I reverse a string in Python?',
    'Use slicing: s[::-1]',
    weights={'accuracy': 0.5, 'completeness': 0.3, 'clarity': 0.2}
)

เกณฑ์: ความถูกต้องของข้อเท็จจริง

ความถูกต้องของข้อเท็จจริงเป็นเกณฑ์ที่สำคัญที่สุดสำหรับงานที่ใช้ความรู้เป็นหลัก เกณฑ์ด้านความถูกต้องโดยเฉพาะจะกำชับให้ผู้ตัดสินตรวจสอบข้อเท็จจริงที่ผิด ข้อมูลที่ล้าสมัย และข้อกล่าวอ้างที่ไม่มีหลักฐานรองรับ

ACCURACY_RUBRIC = (
    'Evaluate FACTUAL ACCURACY of the following response.\n\n'
    'Score 1-5:\n'
    '1 = Multiple factual errors that fundamentally mislead the reader\n'
    '2 = At least one significant factual error (wrong date, number, or core fact)\n'
    '3 = Factually correct but includes minor imprecisions or over-generalizations\n'
    '4 = Factually correct with appropriate hedging of uncertain claims\n'
    '5 = Factually precise, no errors, and correctly acknowledges uncertainty where present\n\n'
    'Check specifically for:\n'
    '- Wrong dates, statistics, or numerical values\n'
    '- Misattributed quotes or inventions\n'
    '- Outdated information presented as current\n'
    '- Claims stated with false confidence (should be hedged)\n\n'
    'Q: {question}\nA: {response}\n\n'
    'Score and list any errors found:'
)
print(ACCURACY_RUBRIC[:400])

เกณฑ์: ความครบถ้วน

ความครบถ้วนตรวจสอบว่าคำตอบครอบคลุมทุกส่วนของคำถามที่มีหลายส่วนหรือไม่ เกณฑ์นี้ช่วยตรวจจับคำตอบที่ตอบคำถามแรกแต่ละเลยคำถามต่อเนื่อง หรือให้คำตอบในระดับภาพรวมทั้งที่มีการขอรายละเอียดเฉพาะเจาะจง

COMPLETENESS_RUBRIC = (
    'Evaluate COMPLETENESS of this response.\n\n'
    'First, list every distinct question or requirement in the original query.\n'
    'Then, check whether the response addressed each one.\n\n'
    'Score 1-5:\n'
    '1 = Only addressed 0-20% of what was asked\n'
    '2 = Addressed 20-50% — missed major components\n'
    '3 = Addressed 50-80% — answered main question but missed sub-parts\n'
    '4 = Addressed 80-95% — minor omissions only\n'
    '5 = Addressed 100% — every requirement was met\n\n'
    'Q: {question}\nA: {response}\n\n'
    'Requirements checklist and completeness score:'
)

# This rubric forces the judge to decompose the question first,
# which is much more reliable than asking 'was it complete?'
print(COMPLETENESS_RUBRIC[:400])

เกณฑ์: ความชัดเจน

การประเมินความชัดเจนตรวจสอบความอ่านง่าย โครงสร้าง และคำตอบสื่อความหมายให้กลุ่มเป้าหมายเข้าใจได้จริงหรือไม่ เกณฑ์นี้ช่วยตรวจจับคำตอบที่ถูกต้องทางเทคนิคแต่มีคำอธิบายไม่ดี

CLARITY_RUBRIC = (
    'Evaluate CLARITY of this response for a {audience} audience.\n\n'
    'Score 1-5:\n'
    '1 = Incomprehensible — cannot extract meaning\n'
    '2 = Very hard to follow — excessive jargon, poor structure\n'
    '3 = Understandable with effort — some confusing parts\n'
    '4 = Clear and well-organized — easy to read\n'
    '5 = Exceptionally clear — ideal structure, appropriate vocabulary, '
    'no unnecessary complexity\n\n'
    'Consider:\n'
    '- Is the vocabulary appropriate for the audience?\n'
    '- Is the response logically organized?\n'
    '- Are sentences a readable length?\n'
    '- Is the main point stated early and clearly?\n\n'
    'Q: {question}\nA: {response}\n\n'
    'Clarity score and key issues:'
)

# Parameterize the audience for context-aware clarity assessment
print(CLARITY_RUBRIC.format(
    audience='non-technical business stakeholder',
    question='What is an API?',
    response='REST APIs use HTTP to transfer data between client and server.'
)[:300])

เกณฑ์เฉพาะงาน

เกณฑ์ความถูกต้อง ความครบถ้วน และความชัดเจนแบบทั่วไปใช้ได้กับงานหลากหลายประเภท แต่เกณฑ์เฉพาะงานให้ผลการประเมินที่ดีกว่าสำหรับกรณีใช้งานเฉพาะทาง ให้ปรับเกณฑ์ให้ตรงกับสิ่งที่สำคัญจริงสำหรับแอปพลิเคชันของคุณ

# Customer support response rubric
SUPPORT_RUBRIC = (
    'Evaluate this customer support response:\n\n'
    'EMPATHY (1-5): Does it acknowledge the customer emotion?\n'
    'RESOLUTION (1-5): Does it provide a clear solution or next step?\n'
    'TONE (1-5): Is it professional, warm, and not condescending?\n'
    'EFFICIENCY (1-5): Does it avoid unnecessary words or boilerplate?\n\n'
    'Customer message: {customer_message}\n'
    'Support response: {support_response}\n\n'
    'Scores and notes (JSON):'
)

# Code review rubric
CODE_REVIEW_RUBRIC = (
    'Evaluate this code explanation:\n\n'
    'CORRECTNESS (1-5): Is the code technically correct?\n'
    'EDGE_CASES (1-5): Does it handle edge cases (empty input, errors)?\n'
    'EFFICIENCY (1-5): Is it reasonably efficient (no obvious O(n^2) where O(n) is easy)?\n'
    'READABILITY (1-5): Is the code easy to read and understand?\n\n'
    'Task: {task}\n'
    'Code: {code}\n\n'
    'Scores and notes (JSON):'
)
print('Specialized rubrics produce better signal for your domain')

การทดสอบความสอดคล้องของเกณฑ์

ทดสอบความสอดคล้องของเกณฑ์โดยส่งคำตอบเดิมห้าครั้ง พร้อมปรับถ้อยคำของคำสั่งเล็กน้อยในแต่ละครั้ง แล้วตรวจสอบว่าคะแนนยังคงที่หรือไม่ ความแปรปรวนสูงหมายความว่าเกณฑ์ระบุรายละเอียดไม่เพียงพอ

import anthropic
import json
import statistics

client = anthropic.Anthropic(api_key='sk-ant-...')

def test_rubric_consistency(rubric_prompt, question, response, n_trials=5):
    scores = []
    for i in range(n_trials):
        r = client.messages.create(
            model='claude-opus-4-5',
            max_tokens=100,
            messages=[{'role': 'user', 'content': rubric_prompt.format(
                question=question, response=response
            )}]
        )
        try:
            data = json.loads(r.content[0].text)
            overall = data.get('overall', sum(data.values()) / len(data))
            scores.append(overall)
        except Exception:
            scores.append(None)

    valid = [s for s in scores if s is not None]
    if valid:
        print(f'Scores: {valid}')
        print(f'Mean: {statistics.mean(valid):.2f}')
        print(f'Std dev: {statistics.stdev(valid):.2f}')
        if statistics.stdev(valid) > 0.5:
            print('WARNING: High variance — rubric may be underspecified')

    return valid

การส่งคืนข้อมูลเจสันจากผู้ตัดสิน

กำหนดให้ผู้ตัดสินตามเกณฑ์ส่งคืนข้อมูลเจสันที่มีโครงสร้างเสมอ วิธีนี้ทำให้เครื่องอ่านคะแนนได้ ช่วยให้รวมผลโดยอัตโนมัติ และป้องกันไม่ให้ผู้ตัดสินซ่อนรายละเอียดสำคัญไว้ในข้อความอิสระที่กระบวนการประมวลผลของคุณมองข้าม

import anthropic
import json

client = anthropic.Anthropic(api_key='sk-ant-...')

def structured_rubric_judge(question, response):
    prompt = (
        'Score this response 1-5 on three criteria and return JSON.\n\n'
        'Q: {q}\nA: {a}\n\n'
        'Return ONLY this JSON structure (no other text):\n'
        '{{\n'
        '  "accuracy": <1-5>,\n'
        '  "completeness": <1-5>,\n'
        '  "clarity": <1-5>,\n'
        '  "overall": <1-5>,\n'
        '  "primary_issue": "<what most needs improvement>",\n'
        '  "primary_strength": "<what the response does best>"\n'
        '}}'
    ).format(q=question, a=response)

    r = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=200,
        messages=[{'role': 'user', 'content': prompt}]
    )

    text = r.content[0].text.strip()
    # Strip markdown code fences if present
    if text.startswith('###'):
        text = text.split('###')[1]
        if text.startswith('json'):
            text = text[4:]
    return json.loads(text.strip())

result = structured_rubric_judge(
    'Explain big O notation.',
    'Big O describes algorithm time complexity.'
)
print(json.dumps(result, indent=2))

การปรับปรุงการออกแบบเกณฑ์

เกณฑ์จำเป็นต้องผ่านการปรับปรุงหลายรอบจึงจะทำงานได้ดี เริ่มต้นด้วยเกณฑ์สามข้อแบบง่าย ทดลองใช้กับกรณีทดสอบ 20–30 กรณี แล้วเปรียบเทียบกับการให้คะแนนของมนุษย์ ปรับปรุงคำจำกัดความของเกณฑ์ที่ผู้ตัดสินกับมนุษย์มีความเห็นไม่ตรงกันมากที่สุด

สิ่งที่มักต้องปรับปรุง ได้แก่ เกณฑ์ความถูกต้องกว้างเกินไป (แยกเป็นความถูกต้องของข้อเท็จจริงและความสอดคล้องเชิงตรรกะ) เกณฑ์ความชัดเจนรวมความอ่านง่ายกับความกระชับไว้ด้วยกัน (แยกออกจากกัน) หรือระดับคะแนน 3 มีเกณฑ์อ้างอิงไม่ชัดเจน (คำตอบส่วนใหญ่จึงกระจุกอยู่ที่ระดับนี้อย่างกำกวม)

แบบทดสอบความรู้: เกณฑ์อ้างอิงคะแนน

เหตุใดเกณฑ์การให้คะแนนจึงควรมีคำอธิบายอย่างชัดเจนว่าคะแนนแต่ละระดับมีความหมายอย่างไร (เกณฑ์อ้างอิงคะแนน)

สรุปทบทวน: คำสั่งการให้คะแนนตามเกณฑ์

การให้คะแนนตามเกณฑ์จะประเมินคำตอบตามเกณฑ์ที่มีชื่อเรียกหลายข้อ (ความถูกต้อง ความครบถ้วน ความชัดเจน) พร้อมเกณฑ์อ้างอิงคะแนนที่ระบุอย่างชัดเจนว่าคะแนนแต่ละระดับมีความหมายอย่างไร เกณฑ์อ้างอิงช่วยลดการให้คะแนนสูงเกินจริงและเพิ่มความสอดคล้อง ใช้การให้คะแนนแบบถ่วงน้ำหนักเพื่อจัดลำดับความสำคัญให้เกณฑ์ที่สำคัญที่สุดสำหรับกรณีใช้งานของคุณ เกณฑ์เฉพาะงาน (การสนับสนุน โค้ด งานสร้างสรรค์) ให้ผลดีกว่าเกณฑ์ทั่วไปสำหรับแอปพลิเคชันเฉพาะทาง ให้ผู้ตัดสินส่งคืนข้อมูลเจสันเสมอเพื่อให้ได้ผลลัพธ์ที่เครื่องอ่านได้ ทดสอบความสอดคล้องของเกณฑ์ด้วยการประเมินเดิมหลายครั้ง ความเบี่ยงเบนมาตรฐานสูงเป็นสัญญาณว่าเกณฑ์ระบุรายละเอียดไม่เพียงพอและจำเป็นต้องปรับปรุง

เริ่มต้นได้ฟรี

เรียนรู้ AI Prompt Engineering ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
53
บทเรียน
199

คำถามที่พบบ่อย

บทเรียน “พรอมต์ให้คะแนนตามเกณฑ์ประเมิน” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “พรอมต์ให้คะแนนตามเกณฑ์ประเมิน” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AI Prompt Engineering ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AI Prompt Engineering มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “พรอมต์ให้คะแนนตามเกณฑ์ประเมิน”

เกณฑ์ประเมินแบบมีโครงสร้าง: ความถูกต้อง ความลื่นไหล ความเกี่ยวข้อง และความปลอดภัย (ระดับ 1-5) คุณปฏิบัติ AI Prompt Engineering ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AI Prompt Engineering หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน AI Prompt Engineering บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “พรอมต์ให้คะแนนตามเกณฑ์ประเมิน” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน AI Prompt Engineering นี้ได้ไหม

ได้ บทเรียน AI Prompt Engineering ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ใช้ LLM ประเมินข้อมูลส่งออกของ LLM
  2. พรอมต์ให้คะแนนตามเกณฑ์ประเมิน
  3. การตัดสินเชิงเปรียบเทียบ: A กับ B
  4. การปรับเทียบและอคติในผู้ตัดสินที่เป็น LLM
← กลับไปที่ AI Prompt Engineering