AI Prompt Engineering · درس

المطالبات السلبية والاستبعادات

ما ينبغي استبعاده: ضبابي، وعلامة مائية، وقبيح، ومشوّه — صياغة مطالبات سلبية فعّالة

الدرس 3 من 413 خطوة

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

ما المقصود بالمطالبات السلبية؟

تخبر المطالبات السلبية نموذج الصور بما يجب ألا يدرجه في الصورة المولّدة. وهي منفصلة عن المطالبة الإيجابية، وتوجّه التوليد بعيداً عن العيوب والأساليب والعناصر غير المرغوب فيها. وقد نشأ هذا المفهوم كميزة في Stable Diffusion، ثم انتشر في نماذج توليد الصور الأخرى.

صياغة المطالبة السلبية في Stable Diffusion

في Stable Diffusion، تُمرَّر المطالبات السلبية كمعلمة منفصلة. ويتعامل النموذج معها بوصفها توجيهاً عكسياً؛ إذ تُبعَد المفاهيم الواردة في المطالبة السلبية بنشاط أثناء التوليد.

import requests

SD_API_URL = 'http://localhost:7860/sdapi/v1/txt2img'

def generate_sd_image(positive_prompt, negative_prompt, steps=30, cfg_scale=7):
    payload = {
        'prompt': positive_prompt,
        'negative_prompt': negative_prompt,
        'steps': steps,
        'cfg_scale': cfg_scale,  # 7-12 recommended
        'width': 512,
        'height': 512,
        'sampler_name': 'DPM++ 2M Karras'
    }
    response = requests.post(SD_API_URL, json=payload)
    return response.json()

# Example call with negative prompt
positive = (
    'portrait of a young woman, soft natural light, '
    'professional photography, sharp focus, elegant'
)
negative = (
    'blurry, watermark, text, logo, ugly, distorted, '
    'deformed, extra fingers, extra limbs, bad anatomy, '
    'low quality, low resolution, grainy, noisy, '
    'oversaturated, harsh shadows'
)

result = generate_sd_image(positive, negative)
print('Generated:', len(result.get('images', [])), 'images')

المطالبة السلبية العامة لتحسين الجودة

تحسّن مجموعة قياسية من مصطلحات المطالبات السلبية جودة المخرجات مع معظم الموضوعات تقريباً. احفظ هذه المجموعة أو اجعلها نقطة البداية الافتراضية لك.

# Universal quality negative prompt
QUALITY_NEGATIVES = [
    # Technical quality issues
    'blurry', 'out of focus', 'low quality', 'low resolution',
    'pixelated', 'grainy', 'noisy', 'compressed artifacts', 'jpeg artifacts',

    # Anatomical distortions (common AI failure mode)
    'extra fingers', 'extra limbs', 'extra arms', 'deformed hands',
    'bad anatomy', 'malformed', 'mutated', 'disfigured',

    # Unwanted elements
    'watermark', 'text', 'logo', 'signature', 'caption',
    'border', 'frame', 'username',

    # Stylistic failures
    'ugly', 'poorly drawn', 'amateur', 'sketch',
    'unfinished', 'rough draft',

    # Color problems
    'oversaturated', 'washed out', 'overexposed', 'underexposed'
]

UNIVERSAL_NEGATIVE = ', '.join(QUALITY_NEGATIVES)
print('Universal negative prompt:')
print(UNIVERSAL_NEGATIVE[:200], '...')

المطالبات السلبية الخاصة بالتشريح والجسم

تشتهر نماذج توليد الصور بالذكاء الاصطناعي بصعوبة التعامل مع اليدين والأصابع. وتقلل المطالبات السلبية التشريحية المحددة هذه العيوب بدرجة ملحوظة عند توليد أشكال بشرية.

ANATOMY_NEGATIVES = [
    # Hand and finger issues
    'extra fingers', 'missing fingers', 'deformed fingers',
    'fused fingers', 'too many fingers', 'six fingers',
    'wrong number of fingers', 'extra hands', 'floating hand',

    # Face issues
    'distorted face', 'asymmetrical face', 'multiple faces',
    'merged faces', 'duplicate head', 'two heads',
    'extra eyes', 'missing eyes', 'heterochromia (if not desired)',

    # Body proportions
    'extra legs', 'extra arms', 'floating limbs',
    'bad proportions', 'unrealistic body proportions',
    'torso too long', 'missing torso',

    # Skin
    'skin blemishes', 'skin texture issues'
]

BODY_NEGATIVE = ', '.join(ANATOMY_NEGATIVES)

# Full portrait negative prompt combining quality + anatomy
PORTRAIT_NEGATIVE = UNIVERSAL_NEGATIVE + ', ' + BODY_NEGATIVE
print('Portrait negative length:', len(PORTRAIT_NEGATIVE.split(',')), 'terms')

استبعاد الأسلوب باستخدام المطالبات السلبية

يمكن للمطالبات السلبية استبعاد الأساليب غير المرغوب فيها — وهذا مفيد عندما تجذب مصطلحات الأسلوب في المطالبة الإيجابية أساليب قريبة تريد تجنّبها. ومن الاستبعادات الأسلوبية الشائعة:

style_exclusion_examples = [
    {
        'goal': 'Oil painting portrait without cartoonish look',
        'positive': 'oil painting portrait, classical technique, highly detailed',
        'negative': 'cartoon, anime, illustration, flat colors, cel-shaded, vector'
    },
    {
        'goal': 'Photorealistic image without HDR over-processing',
        'positive': 'photorealistic landscape, natural light, DSLR quality',
        'negative': 'HDR, hyper-saturated, over-processed, Instagram filter, tone-mapped'
    },
    {
        'goal': 'Dark fantasy without gore',
        'positive': 'dark fantasy warrior, dramatic lighting, detailed armor',
        'negative': 'gore, blood, violence, disturbing content, horror'
    },
    {
        'goal': 'Vintage look without actual age degradation',
        'positive': 'vintage 1960s photograph, film grain, warm tones',
        'negative': 'deteriorated, damaged, torn, stains, yellowed, faded'
    }
]

for ex in style_exclusion_examples[:2]:
    print(f'Goal: {ex["goal"]}')
    print(f'Negative: {ex["negative"][:60]}...')
    print()

صياغة التجنّب في DALL-E

لا يحتوي DALL-E 3 على حقل منفصل للمطالبة السلبية. وبدلاً من ذلك، تُكتب الاستبعادات بصورة طبيعية داخل المطالبة الإيجابية باستخدام عبارات مثل 'avoid' أو 'without' أو 'no' أو 'do not include'.

import openai

client = openai.OpenAI(api_key='YOUR_API_KEY')

# DALL-E 3: exclusions in the positive prompt
dalle_prompt_with_exclusions = (
    'A professional portrait photograph of a businesswoman in a modern office. '
    'Natural window light, shallow depth of field, warm tones. '
    'Do not include: any text, watermarks, logos, or captions. '
    'Avoid: cartoon or illustrated style, anime, artificial-looking skin. '
    'The image should have no distracting background elements. '
    'Realistic and natural — not over-processed or filtered.'
)

response = client.images.generate(
    model='dall-e-3',
    prompt=dalle_prompt_with_exclusions,
    size='1024x1024',
    quality='hd',
    n=1
)

image_url = response.data[0].url
print('Generated image URL:', image_url[:60], '...')

قوة المطالبة السلبية ومقياس CFG

في Stable Diffusion، يتحكم مقياس CFG (Classifier-Free Guidance) في مدى قوة تأثير المطالبة، الإيجابية والسلبية معاً، في التوليد. ويعني ارتفاع CFG التزاماً أقوى بالمطالبة، لكنه قد يسبب عيوباً.

# CFG scale guide for Stable Diffusion
cfg_guide = {
    3: 'Very loose adherence, creative/random, may ignore negative prompts',
    5: 'Balanced: creative but follows prompts generally',
    7: 'Standard: good balance of quality and adherence (recommended default)',
    10: 'Strong adherence: follows both positive and negative prompts closely',
    12: 'Very strong: highly literal, may oversaturate colors or cause artifacts',
    15: 'Extreme: usually causes artifacts, rarely useful'
}

# Parenthetical weighting in Stable Diffusion
# Surround a term with () to increase its weight
# surround with [] to decrease its weight
weighted_negative = (
    '(blurry:1.3), (extra fingers:1.5), watermark, '
    '[slight noise:0.5], text'
    # extra fingers gets 1.5x negative weight (most important to avoid)
    # blurry gets 1.3x negative weight
    # slight noise gets reduced 0.5x weight (tolerate a little)
)

print('CFG=7 (recommended default) balances quality and prompt adherence')
print('Weighted negative example:', weighted_negative[:80], '...')

إنشاء مكتبة للمطالبات السلبية

تحتاج حالات الاستخدام المختلفة إلى مجموعات مختلفة من المطالبات السلبية. أنشئ مكتبة من المطالبات السلبية الخاصة بكل مجال، بحيث يمكن تركيبها معاً لأي مهمة توليد.

NEGATIVE_PROMPT_LIBRARY = {
    'quality_base': (
        'blurry, low quality, low resolution, pixelated, '
        'watermark, text, logo, signature'
    ),
    'anatomy': (
        'extra fingers, deformed hands, bad anatomy, '
        'extra limbs, distorted face'
    ),
    'portrait_specific': (
        'double chin exaggerated, skin blemishes, '
        'red eye, harsh shadows on face'
    ),
    'landscape_specific': (
        'overcast flat light, washed out colors, '
        'lens flare, chromatic aberration'
    ),
    'product_photo': (
        'shadow on product, uneven background, '
        'reflection glare, dust spots'
    ),
    'no_style_bleed': (
        'anime, cartoon, illustration, painting, '
        'sketch (when photorealism is desired)'
    )
}

def compose_negative(*keys):
    return ', '.join(NEGATIVE_PROMPT_LIBRARY[k] for k in keys)

# Portrait generation
portrait_neg = compose_negative('quality_base', 'anatomy', 'portrait_specific')
print('Portrait negative:', portrait_neg[:100], '...')

# Product photo generation
product_neg = compose_negative('quality_base', 'product_photo', 'no_style_bleed')
print('Product negative:', product_neg[:100], '...')

متى تفشل المطالبات السلبية

لا تضمن المطالبات السلبية النتيجة — فهي تقلل احتمال ظهور العناصر غير المرغوب فيها، لكنها لا تزيلها تماماً. ويساعد فهم الحالات التي تفشل فيها على وضع توقعات واقعية.

negative_prompt_limitations = {
    'Failure: Concept too abstract': {
        'problem': '"bad" is too vague for the model to act on',
        'fix': 'Use specific concrete terms: "blurry", "deformed", "watermark"'
    },
    'Failure: Contradiction with positive prompt': {
        'problem': 'Positive: "detailed painting" | Negative: "painting"',
        'fix': 'Narrow negative to the specific aspect: negative: "amateur painting, rough sketch"'
    },
    'Failure: Too many negative terms dilute effect': {
        'problem': '200-word negative prompt where each term gets minimal weight',
        'fix': 'Limit to 15-20 terms. Use weighting for most critical: "(extra fingers:1.5)"'
    },
    'Failure: Watermarks still appear': {
        'problem': 'Some model checkpoints are strongly trained on watermarked data',
        'fix': 'Use a different model checkpoint or use an inpainting pass to remove'
    }
}

for failure, info in negative_prompt_limitations.items():
    print(f'{failure}')
    print(f'  Problem: {info["problem"]}')
    print(f'  Fix: {info["fix"]}')
    print()

اختبار فعالية المطالبات السلبية

اختبر بصورة منهجية المطالبات السلبية التي تحسّن النتائج فعلاً في حالة استخدامك المحددة. ولّد الصور باستخدام المطالبات السلبية ومن دونها، ثم قارن المخرجات باستخدام بذرة ثابتة.

import requests

SD_API_URL = 'http://localhost:7860/sdapi/v1/txt2img'

def test_negative_prompts(positive, negative_variants, seed=42, steps=30):
    results = []
    for label, negative in negative_variants.items():
        payload = {
            'prompt': positive,
            'negative_prompt': negative,
            'seed': seed,  # fixed seed for fair comparison
            'steps': steps,
            'cfg_scale': 7
        }
        response = requests.post(SD_API_URL, json=payload)
        results.append({
            'label': label,
            'negative': negative[:60] + '...',
            'image_count': len(response.json().get('images', []))
        })
    return results

# Test different negative prompt levels
variants = {
    'no_negative': '',
    'quality_only': 'blurry, low quality, watermark',
    'anatomy_added': 'blurry, low quality, watermark, extra fingers, bad anatomy',
    'full_library': compose_negative('quality_base', 'anatomy', 'portrait_specific')
}

print('Testing negative prompt variants with fixed seed...')
print('Compare output images to identify which negative terms have the most impact.')

معامل --no في Midjourney

يستخدم Midjourney المعامل --no بديلاً عن المطالبة السلبية. وتختلف الصياغة، لكن المفهوم مطابق: أضف --no [term1] [term2] في نهاية المطالبة.

# Midjourney negative prompt syntax using --no parameter
midjourney_prompts = [
    # Basic exclusion
    'professional headshot portrait, soft studio lighting, --no text watermark logo background',

    # Style exclusion
    'oil painting of a medieval castle, dramatic lighting --no modern cars people telephone wires',

    # Anatomy
    'full body character art, hero pose --no extra fingers deformed limbs bad anatomy',

    # Content exclusion
    'children\'s book illustration of a forest --no violence scary dark horror'
]

# Midjourney also supports emphasis with :: weighting
weighted_midjourney = (
    'A serene Japanese garden::2, cherry blossoms::1.5, '
    'koi pond, stone lantern --no people tourists modern buildings::3'
    # ::2 = 2x weight on the garden
    # ::3 on the no-people exclusion = very strong exclusion
)

for prompt in midjourney_prompts[:3]:
    print('Midjourney:', prompt[:70], '...')

اختبار سريع

ما التقنية في Stable Diffusion التي تزيد تأثير مصطلح سلبي محدد مقارنةً بالمصطلحات الأخرى؟

ملخص المطالبات السلبية

تُعد المطالبات السلبية أداة قوية لتوجيه توليد الصور بعيداً عن الصفات غير المرغوب فيها:

  • Stable Diffusion: معلمة negative_prompt منفصلة؛ وتدعم الترجيح بين قوسين
  • DALL-E 3: استخدم 'avoid' و'without' و'do not include' داخل المطالبة الإيجابية
  • Midjourney: أضف --no [terms] إلى نهاية المطالبة
  • المطالبات السلبية العامة: blurry، low quality، watermark، text، extra fingers
  • مقياس CFG: يتحكم في مدى قوة توجيه المطالبات الإيجابية والسلبية للتوليد
  • القيود: تقلل الاحتمال لكنها لا تضمن الاستبعاد؛ وبحد أقصى 15 إلى 20 مصطلحاً
البدء مجانًا

تعلم AI Prompt Engineering مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
53
الدروس
199

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

هل درس «المطالبات السلبية والاستبعادات» مجاني؟

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

ماذا ستتعلم في «المطالبات السلبية والاستبعادات»؟

ما ينبغي استبعاده: ضبابي، وعلامة مائية، وقبيح، ومشوّه — صياغة مطالبات سلبية فعّالة تتمرن على AI Prompt Engineering مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ AI Prompt Engineering؟

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

كم من الوقت يستغرق درس «المطالبات السلبية والاستبعادات»؟

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

هل يمكنني كتابة وتشغيل أكواد في درس AI Prompt Engineering هذا؟

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

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

  1. تشريح مطالبة إنشاء الصور
  2. تحديد الأسلوب والوسيط الفني
  3. المطالبات السلبية والاستبعادات
  4. تحسين مطالبات الصور تكراريًا
← العودة إلى AI Prompt Engineering