AI & Data Scienceالذكاء الاصطناعي وعلم البيانات

A tiny guard against prompt injection.حارس صغير ضد حقن الأوامر.

Prompt injection is text written to hijack an AI, like "ignore your instructions and…", typed by a user or hidden in an email or web page. This small Transformer reads the text first and flags the attack before it reaches the model. It is light enough to run on your own device, for free.حقن الأوامر (Prompt Injection) نص مكتوب ليسيطر على الذكاء الاصطناعي، مثل «تجاهل تعليماتك و…»، يكتبه المستخدم أو يُخفى في رسالة بريد أو صفحة ويب. هذا الـ Transformer الصغير يقرأ النص أولًا وينبّه إلى الهجوم قبل أن يصل إلى النموذج. وهو خفيف بما يكفي ليعمل على جهازك مجانًا.

By Yazeed Alhifzi and Yahya Majrashiمن إعداد يزيد الحفظي ويحيى المجرشي

  • 14× smaller than leading open guardsأصغر 14 مرة من أبرز نماذج الحماية المفتوحة
  • about 4× fasterأسرع بنحو 4 مرات
  • your text stays on your deviceنصّك يبقى على جهازك
  • free to runتشغيله مجاني
QR code that opens www.yazeed.quest/injection-guard
Scan to try it on your phoneامسح الرمز لتجربته على هاتفكyazeed.quest/injection-guard
Architecture of the injection guard · بنية حارس حقن الأوامر Bottom to top: input text, WordPiece tokenizer, token embedding added to position and segment embeddings, LayerNorm and a projection from 128 to 256, then twelve encoder layers each made of multi-head attention, add and norm, feed forward, add and norm. The [CLS] vector goes to a classification head, a softmax and a threshold of 0.945, giving the verdict SAFE or INJECTION. SAFE INJECTION Threshold: p ≥ 0.945 ? Softmax Classification head Linear · GELU · Linear 256 → 2 [CLS] vector 256 12× Add & Norm Feed Forward 256 → 1024 → 256 · GELU Add & Norm Multi-Head Attention 4 heads × 64 dims QKV LayerNorm · Linear 128 → 256 T × 256 Position + segmentembeddings Token embedding 30,522 × 128 T × 128 WordPiece tokenizer [CLS] t₁ … tₙ [SEP] Input text: a prompt, email or web pageالنص المُدخل: أمر أو رسالة بريد أو صفحة ويب
Figure 1. The guard is an ELECTRA-small Transformer encoder (13.5M parameters) with a classification head. Read it from the bottom up. Only the final [CLS] vector, which has gathered information from every token through attention, is used for the decision. Explore every layer interactively →الشكل 1. الحارس مُرمِّز Transformer من نوع ELECTRA-small (‏13.5 مليون معامل) مع رأس تصنيف. اقرأه من الأسفل إلى الأعلى. لا يُستخدم في القرار إلا متجه [CLS] الأخير، الذي جمع معلومات من كل Token عبر الانتباه (Attention). استكشف كل طبقة تفاعليًا ←