0Pricing
Prompt Engineering & LLM Optimization for Developers · درس

اكتشاف الهلوسات والحد منها

هلوسات النماذج هي مخرجات LLM واثقة لكنها زائفة. تعلّم سبب حدوثها، وكيفية اكتشافها، والتقنيات العملية لتقليلها في بيئة الإنتاج.

اكتشاف الهلوسات والحد منها درس مجاني في Prompt Engineering & LLM Optimization for Developers على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Prompt Engineering & LLM Optimization for Developers، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Prompt Engineering & LLM Optimization for Developers 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

What is a Hallucination?

A hallucination is when an LLM produces text that is fluent and confident but factually wrong or unsupported by any source.

Because the output looks authoritative, hallucinations are dangerous in user-facing apps.

Why They Happen

LLMs predict the most likely next token, not the truth. With no grounding, they fill gaps with plausible-sounding inventions.

  • Missing knowledge in training data
  • Ambiguous or leading prompts
  • Pressure to always answer

Types of Hallucination

Two broad categories:

  • Factual: wrong dates, fake citations, invented APIs
  • Faithfulness: answer contradicts the provided context (common in RAG)

Grounding with Context

The strongest defense is grounding: give the model trusted source text and instruct it to answer only from that text.

Answer ONLY using the context below.
If the answer is not in the context, say "I do not know".

Context:
{retrieved_docs}

Forcing Citations

Ask the model to cite which passage supports each claim. Unsupported sentences become easy to spot and verify.

For each sentence, add a [doc_id] citation.
Do not make claims you cannot cite.

Lowering Temperature

Higher temperature increases creativity — and invention. For factual tasks, set a low temperature so the model stays close to high-probability, well-grounded tokens.

const res = await client.chat.completions.create({
  model: "gpt-4o-mini",
  temperature: 0,
  messages
});

Self-Consistency Checks

Generate the answer several times. If the model gives different facts each run, the claim is likely a hallucination. Agreement is a weak but useful signal of reliability.

LLM-as-a-Judge Verification

Use a second model call to check whether the answer is supported by the context. The judge returns a faithfulness verdict you can act on.

Does the ANSWER follow only from the CONTEXT?
Reply: SUPPORTED, PARTIAL, or UNSUPPORTED.

Programmatic Validation

When outputs are structured, validate them. A cited URL should resolve, a quoted number should match the source, a JSON field should match a schema.

function validateCitation(cit, docs) {
  return docs.some(d => d.id === cit.doc_id);
}

Letting the Model Abstain

Give the model permission to say I do not know. Removing the pressure to always answer measurably reduces fabricated content.

Human Review for High Stakes

For medical, legal, or financial outputs, route low-confidence or uncited answers to a human before showing them to users. Automation plus oversight beats either alone.

Quick Check

Test your understanding.

Recap

You learned to fight hallucinations: ground answers in trusted context, force citations, lower temperature, use self-consistency and LLM-as-a-judge checks, validate outputs programmatically, allow abstention, and add human review for high-stakes cases.

الأسئلة الشائعة

هل درس «اكتشاف الهلوسات والحد منها» مجاني؟

نعم — نص درس «اكتشاف الهلوسات والحد منها» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Prompt Engineering & LLM Optimization for Developers، انتقل إلى CoddyKit PRO. تتضمن دورة Prompt Engineering & LLM Optimization for Developers 4 دروس في المجموع.

ماذا ستتعلم في «اكتشاف الهلوسات والحد منها»؟

هلوسات النماذج هي مخرجات LLM واثقة لكنها زائفة. تعلّم سبب حدوثها، وكيفية اكتشافها، والتقنيات العملية لتقليلها في بيئة الإنتاج. تتمرن على Prompt Engineering & LLM Optimization for Developers مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Prompt Engineering & LLM Optimization for Developers؟

لا تُشترط خبرة سابقة. Prompt Engineering & LLM Optimization for Developers على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «اكتشاف الهلوسات والحد منها»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Prompt Engineering & LLM Optimization for Developers هذا؟

نعم. كل درس في Prompt Engineering & LLM Optimization for Developers يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. مقاييس ومعايير تقييم LLM
  2. أنظمة الملاحظات مع إشراك الإنسان
  3. حقن المطالبات وأفضل ممارسات الأمان
  4. اكتشاف الهلوسات والحد منها
← العودة إلى Prompt Engineering & LLM Optimization for Developers