0Pricing
AI Prompt Engineering · บทเรียน

การแทรกอภิธานศัพท์และภววิทยาเฉพาะโดเมน

ฝังคำศัพท์และความรู้เฉพาะโดเมนลงในพรอมต์ระบบ

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

ปัญหาการแยกความหมาย

ภาษาประจำสาขาเต็มไปด้วยความกำกวม 'อัตราผลตอบแทน' หมายถึงอัตราผลตอบแทนพันธบัตรในแวดวงการเงิน และหมายถึงผลผลิตพืชในภาคการเกษตร 'ความละเอียด' หมายถึงความละเอียดของหน้าจอในส่วนติดต่อผู้ใช้ และหมายถึงการแก้ไขปัญหาในงานสนับสนุน หากไม่มีบริบทของสาขา โมเดลจะเลือกความหมายทั่วไปที่พบบ่อยที่สุด ซึ่งไม่ถูกต้องในสาขาเฉพาะทาง

รูปแบบการแทรกอภิธานศัพท์

แทรกอภิธานศัพท์เฉพาะสาขาโดยตรงลงในพรอมต์ระบบ วิธีนี้จะแทนที่คลังคำศัพท์เริ่มต้นของโมเดล และทำให้มั่นใจว่าคำศัพท์เฉพาะสาขาจะได้รับการตีความอย่างถูกต้องตลอดทั้งเซสชัน

FINANCE_GLOSSARY = '''
DOMAIN GLOSSARY (these definitions override general language meaning):
- yield: bond yield (annual return as percentage of bond price), NOT crop or harvest
- duration: interest rate sensitivity measure (modified duration), NOT time length
- spread: yield spread between two bonds, NOT physical spreading
- convexity: second-order price sensitivity to interest rate changes, NOT geometry
- tenor: remaining time to maturity of a financial instrument, NOT musical pitch
- floor: minimum interest rate in a rate agreement, NOT building floor
- cap: maximum interest rate, NOT a hat or market capitalization
- swap: exchange of cash flows between counterparties, NOT physical exchange
- basis: difference between spot and futures price, NOT foundation
'''

FINANCE_SYSTEM_PROMPT = (
    'You are a fixed income analyst.\n\n'
    + FINANCE_GLOSSARY +
    '\nAlways use these domain definitions when answering questions.'
)

import anthropic
client = anthropic.Anthropic(api_key='YOUR_API_KEY')

response = client.messages.create(
    model='claude-opus-4-5', max_tokens=500,
    system=FINANCE_SYSTEM_PROMPT,
    messages=[{'role': 'user', 'content': 'What is the yield of a 10-year bond?'}]
)
print(response.content[0].text)

การสร้างไฟล์อภิธานศัพท์เฉพาะสาขา

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

# glossaries/fixed_income.yaml
glossary:
  yield:
    domain_meaning: Annual return on a bond as a percentage of its current market price
    general_meaning: Crop or harvest output
    use_domain: true
    examples:
      - 'The 10-year Treasury yield rose to 4.5%'
      - 'Current yield = annual coupon / market price'

  duration:
    domain_meaning: |
      Measure of a bond's price sensitivity to interest rate changes.
      Modified duration = -dP/P / dr
    general_meaning: Length of time
    use_domain: true

  basis:
    domain_meaning: Difference between spot price and futures price of the same instrument
    general_meaning: Foundation or base
    use_domain: true

# glossaries/load.py
import yaml

def load_glossary(domain):
    with open(f'glossaries/{domain}.yaml') as f:
        data = yaml.safe_load(f)
    lines = ['DOMAIN GLOSSARY:']
    for term, info in data['glossary'].items():
        lines.append(f'- {term}: {info["domain_meaning"].strip()}')
    return '\n'.join(lines)

การแทรกออนโทโลยีสำหรับสาขาที่ซับซ้อน

ออนโทโลยีมีขอบเขตกว้างกว่าอภิธานศัพท์ เพราะกำหนดความสัมพันธ์ระหว่างแนวคิดต่าง ๆ เช่น ลำดับชั้น ข้อจำกัด และกฎ การแทรกออนโทโลยีช่วยให้โมเดลเข้าใจว่าแนวคิดใดอยู่ในหมวดหมู่ใด และแนวคิดเหล่านั้นเกี่ยวข้องกันอย่างไร

MEDICAL_ONTOLOGY_SNIPPET = '''
CLINICAL ONTOLOGY (use these relationships in all analysis):

Diagnosis Hierarchy:
- Condition > Category > Specific Diagnosis
- "Hypertension" is a specific diagnosis under "Cardiovascular Conditions"
- "Type 2 Diabetes" is under "Endocrine / Metabolic Conditions"

Medication Classes:
- ACE inhibitors (e.g., lisinopril) -> used for: hypertension, heart failure, CKD
- Beta-blockers (e.g., metoprolol) -> used for: hypertension, angina, heart failure
- Statins (e.g., atorvastatin) -> used for: hyperlipidemia, cardiovascular risk

Measurement Rules:
- "BP" means Blood Pressure, format: systolic/diastolic (e.g., 130/85 mmHg)
- "A1c" means glycated hemoglobin; > 6.5% is diagnostic for Type 2 Diabetes
- "eGFR" means estimated Glomerular Filtration Rate; < 60 mL/min/1.73m2 = CKD

Always use ICD-10 categories when classifying diagnoses.
'''

print(MEDICAL_ONTOLOGY_SNIPPET[:300])

การสร้างอภิธานศัพท์แบบไดนามิก

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

import json

# master_glossary.json — full domain glossary
MASTER_GLOSSARY = {
    'yield': 'Bond yield: annual return as percentage of current market price',
    'duration': 'Modified duration: bond price sensitivity to rate changes',
    'convexity': 'Second-order rate sensitivity measure',
    'swap': 'Exchange of fixed and floating cash flows',
    'option': 'Contract giving right (not obligation) to buy/sell an asset',
    'beta': 'Stock volatility relative to market index',
    'alpha': 'Excess return over benchmark after adjusting for risk',
    # ... hundreds more
}

def focused_glossary(user_query, master_glossary, max_terms=10):
    '''Select glossary terms most relevant to the user query.'''
    query_lower = user_query.lower()
    relevant = {}
    for term, definition in master_glossary.items():
        if term.lower() in query_lower or any(
            word in query_lower for word in definition.lower().split()[:5]
        ):
            relevant[term] = definition
        if len(relevant) >= max_terms:
            break
    lines = ['RELEVANT DOMAIN TERMS:']
    for t, d in relevant.items():
        lines.append(f'- {t}: {d}')
    return '\n'.join(lines)

query = 'What is the duration and convexity of this bond portfolio?'
print(focused_glossary(query, MASTER_GLOSSARY))

การแยกความหมายระหว่างหลายสาขา

คำถามบางข้อครอบคลุมหลายสาขา ควรแทรกบริบทของทุกสาขาที่เกี่ยวข้อง และกำชับให้โมเดลแยกความหมายโดยพิจารณาจากบริบทของบทสนทนา

MULTI_DOMAIN_SYSTEM = '''
This system serves both agricultural and financial users.
The domain is determined by context cues in the user message.

Domain disambiguation rules:
- If the user mentions "crops", "harvest", "acres", "soil", "planting":
  Use AGRICULTURAL definitions: yield = crop output, spread = physical spreading
- If the user mentions "bonds", "portfolio", "maturity", "coupon", "treasuries":
  Use FINANCIAL definitions: yield = bond yield, spread = yield spread
- If the domain is ambiguous:
  Ask the user to clarify: "Are you asking about agricultural or financial yields?"

AGRICULTURAL GLOSSARY:
- yield: crop output per unit area (e.g., bushels per acre)
- basis: difference between local cash price and futures price for a commodity

FINANCIAL GLOSSARY:
- yield: annual bond return as percentage of current price
- basis: yield spread between two financial instruments
'''

print('Multi-domain system prompt loaded.')
print('The model will ask for clarification when domain is ambiguous.')

ผลลัพธ์ที่จำกัดด้วยออนโทโลยี

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

SUPPORT_ONTOLOGY_SYSTEM = '''
You are a support ticket classifier for a B2B SaaS company.

TICKET CATEGORY ONTOLOGY (use ONLY these exact category names):
Level 1 Categories:
- Billing > Sub-categories: Invoice Error, Subscription Change, Refund Request, Payment Failure
- Technical > Sub-categories: Bug Report, Performance Issue, Integration Error, Feature Not Working
- Account > Sub-categories: Access Request, User Management, Security Concern, Password Reset
- Feature Request > Sub-categories: New Feature, Enhancement, UI/UX Improvement

CLASSIFICATION RULES:
1. Always return exactly one Level 1 category and one Sub-category.
2. If ticket spans multiple categories, choose the PRIMARY issue.
3. If uncertain, use the category that would route to the most qualified team.
4. Return format: {"category": "Technical", "subcategory": "Bug Report", "confidence": "HIGH"}
   Confidence: HIGH (clear), MEDIUM (likely), LOW (ambiguous)
'''

def classify_ticket(ticket_text):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=100,
        system=SUPPORT_ONTOLOGY_SYSTEM,
        messages=[{'role': 'user', 'content': f'Classify: {ticket_text}'}]
    )
    return json.loads(response.content[0].text)

การแทรกออนโทโลยีด้านกฎหมาย

ออนโทโลยีด้านกฎหมายกำหนดลำดับชั้นของข้อสัญญา ความสัมพันธ์ระหว่างคู่สัญญา และประเภทของภาระผูกพัน การแทรกสิ่งเหล่านี้ช่วยให้การจัดหมวดหมู่มีความสม่ำเสมอในงานวิเคราะห์สัญญาทั้งหมด

LEGAL_ONTOLOGY = '''
CONTRACT CLAUSE ONTOLOGY:

Obligation Types:
- SHALL: mandatory obligation (enforceable duty)
- MAY: permissive right (optional action)
- SHALL NOT: mandatory prohibition
- WILL: future intention (weaker than SHALL)

Clause Risk Hierarchy:
- CRITICAL: financial exposure > $1M or termination rights
- HIGH: material business impact, IP rights, indemnification
- MEDIUM: operational restrictions, notice requirements
- LOW: administrative provisions, definitions

Party References (standardize to these canonical forms):
- "the Company", "we", "us" -> VENDOR
- "Customer", "Client", "you" -> CUSTOMER
- "third party", "subcontractor" -> THIRD_PARTY

Always use these canonical party names in your analysis.
Do not use the actual company names — replace with canonical form.
'''

print('Legal ontology loaded. Party names will be canonicalized in all analysis.')

เครื่องมือตรวจสอบความสม่ำเสมอของคำศัพท์

หลังจากได้รับผลลัพธ์จากโมเดล ให้ตรวจสอบว่ามีการใช้คำศัพท์เฉพาะสาขาอย่างสม่ำเสมอ และไม่มีการย้อนกลับไปใช้ความหมายทั่วไป การตรวจสอบหลังการประมวลผลช่วยจับการเปลี่ยนแปลงของการใช้คำศัพท์

PROHIBITED_GENERAL_MEANINGS = {
    # In fixed income context: these general meanings should not appear
    'yield': ['harvest', 'crop', 'produce', 'give way', 'surrender'],
    'duration': ['how long', 'length of time', 'period of time'],
    'floor': ['ground floor', 'building floor', 'floor plan'],
    'cap': ['hat', 'market cap', 'bottle cap'],
}

def check_terminology_consistency(text, domain_term):
    text_lower = text.lower()
    prohibited = PROHIBITED_GENERAL_MEANINGS.get(domain_term, [])
    violations = []
    for general_phrase in prohibited:
        if general_phrase in text_lower:
            # Find context window around the violation
            idx = text_lower.index(general_phrase)
            context = text[max(0, idx-50):idx+80]
            violations.append({'phrase': general_phrase, 'context': context})
    return violations

# Usage after LLM call
output = 'The yield of the bond is 4.5% per annum based on current market price.'
violations = check_terminology_consistency(output, 'yield')
if violations:
    print('Terminology violation detected:', violations)
else:
    print('Terminology consistency: PASS')

การจัดการเวอร์ชันของอภิธานศัพท์

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

# Glossary versioning with impact tracking
GLOSSARY_VERSIONS = {
    '1.0.0': {
        'yield': 'Bond yield: annual coupon / face value (current yield)',
        'duration': 'Macaulay duration'
    },
    '2.0.0': {
        'yield': 'Bond yield: annual return as % of current market price (yield to maturity)',
        'duration': 'Modified duration (more precise for risk management)',
        'convexity': 'Second-order rate sensitivity (new in v2)'  # new term
    }
}

def get_affected_prompts(old_version, new_version, prompt_registry):
    '''Find prompts that use terms changed between glossary versions.'''
    old_terms = set(GLOSSARY_VERSIONS[old_version].keys())
    new_terms = set(GLOSSARY_VERSIONS[new_version].keys())
    changed_terms = old_terms ^ new_terms  # symmetric difference

    affected = []
    for prompt_id, artifact in prompt_registry.items():
        if any(term in artifact['template'] for term in changed_terms):
            affected.append(prompt_id)
    return affected

print('Prompts affected by glossary v1.0.0 -> v2.0.0 update:', ['rate-analysis-v1', 'bond-report'])

ออนโทโลยีแบบลำดับชั้นที่มีความสัมพันธ์แม่-ลูก

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

PRODUCT_ONTOLOGY = '''
PRODUCT CATEGORY ONTOLOGY (use for all product classification tasks):

Electronics
  Computing
    Laptops
      Gaming Laptops
      Ultrabooks
      Workstations
    Desktops
    Tablets
  Consumer Electronics
    Smartphones
    Smart Speakers
    Wearables
      Smartwatches
      Fitness Trackers

CLASSIFICATION RULES:
1. Always classify to the most specific level where evidence exists.
2. If a product matches multiple branches, use the primary use case.
3. Use exact taxonomy names from above — do not invent new categories.
4. If a product does not fit, use the nearest parent category and
   add "[NON-STANDARD: <reason>]" after the category name.
'''

print('Product ontology ready. 4-level hierarchy loaded.')

ตรวจสอบความเข้าใจ

โมเดลถูกนำไปใช้งานเพื่อวิเคราะห์พอร์ตพันธบัตร หากไม่มีการแทรกอภิธานศัพท์ โมเดลตีความ 'What is the yield on this instrument?' ด้วยการอธิบายผลผลิตพืช สาเหตุรากฐานคืออะไร และควรแก้ไขอย่างไร

สรุปการแทรกอภิธานศัพท์และออนโทโลยี

การแทรกอภิธานศัพท์และออนโทโลยีเฉพาะสาขาช่วยแก้ความกำกวมของคำศัพท์ในระดับระบบ:

  • การแทรกอภิธานศัพท์: กำหนดความหมายเฉพาะสาขาในพรอมต์ระบบสำหรับคำศัพท์ที่กำกวม
  • การแทรกออนโทโลยี: ระบุลำดับชั้นของแนวคิด กฎความสัมพันธ์ และข้อจำกัดในการจัดหมวดหมู่
  • อภิธานศัพท์แบบไดนามิก: เลือกเฉพาะคำศัพท์ที่เกี่ยวข้องจากอภิธานศัพท์หลัก เพื่อให้หน้าต่างบริบทมีข้อมูลกระชับ
  • การแยกความหมายระหว่างหลายสาขา: แทรกกฎสำหรับตรวจจับสาขาตามบริบท
  • การจัดการเวอร์ชัน: อภิธานศัพท์ต้องจัดการเวอร์ชัน และต้องประเมินพรอมต์ใหม่เมื่อคำศัพท์เปลี่ยนแปลง
  • การตรวจสอบความสม่ำเสมอ: ประมวลผลผลลัพธ์ภายหลังเพื่อตรวจจับการเปลี่ยนแปลงของการใช้คำศัพท์

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

บทเรียน “การแทรกอภิธานศัพท์และภววิทยาเฉพาะโดเมน” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “การแทรกอภิธานศัพท์และภววิทยาเฉพาะโดเมน”

ฝังคำศัพท์และความรู้เฉพาะโดเมนลงในพรอมต์ระบบ คุณปฏิบัติ AI Prompt Engineering ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

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

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

บทเรียน “การแทรกอภิธานศัพท์และภววิทยาเฉพาะโดเมน” ใช้เวลานานแค่ไหน

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

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

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

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

  1. รูปแบบพรอมต์สำหรับงานกฎหมาย
  2. การเขียนพรอมต์ด้านการแพทย์และคลินิก
  3. พรอมต์ด้านการเงินและเชิงปริมาณ
  4. การแทรกอภิธานศัพท์และภววิทยาเฉพาะโดเมน
← กลับไปที่ AI Prompt Engineering