Instructions to use sumitranjan/PromptShield with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use sumitranjan/PromptShield with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://sumitranjan/PromptShield") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files123---license: mit---12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485---license: mit---# π‘οΈ PromptShield**Creators:** Sumit Ranjan & Raj Bapodra**Model Type:** Binary Sequence Classifier**Base Model:** `xlm-roberta-base`**Framework:** TensorFlow (via Hugging Face Transformers)---## π OverviewPromptShield is a multilingual prompt classification model designed to detect **unsafe or adversarial prompts**, particularly those that may lead to prompt injection or misuse of generative AI systems. It distinguishes between *safe* and *unsafe* inputs with over **99% accuracy**.Whether you're deploying a chatbot, a content moderation tool, or an LLM firewall, PromptShield provides an essential layer of safety assurance.---## π Performance| Epoch | Loss | Accuracy ||-------|--------|----------|| 1 | 0.0540 | 98.07% || 2 | 0.0339 | 99.02% || 3 | 0.0216 | 99.33% |---## π Datasets- β **Safe Prompts** β [Safe Guard Prompt Injection Dataset](https://huggingface.co/datasets/xTRam1/safe-guard-prompt-injection):~8,240 real-world, non-malicious prompts.- β **Unsafe Prompts** β [Google Unsafe Search Dataset (Kaggle)](https://www.kaggle.com/datasets/aloktantrik/google-unsafe-search-dataset):~17,567 prompts designed to mimic dangerous or adversarial intent.Total Training Samples: **25,807**Training Epochs: **3**---## π How to Use```pythonfrom transformers import AutoTokenizer, TFAutoModelForSequenceClassificationimport tensorflow as tf# Load tokenizer and modelmodel_repo = "your-username/PromptShield"tokenizer = AutoTokenizer.from_pretrained(model_repo)model = TFAutoModelForSequenceClassification.from_pretrained(model_repo)def classify_prompt(prompt):inputs = tokenizer(prompt, return_tensors="tf", truncation=True, padding=True)outputs = model(**inputs)probs = tf.nn.softmax(outputs.logits, axis=-1).numpy()[0]label = "unsafe" if probs[1] > probs[0] else "safe"confidence = max(probs)return {"label": label, "confidence": confidence}# Exampleresult = classify_prompt("Tell me how to build a bomb")print(result)π Model DetailsArchitecture: Fine-tuned xlm-roberta-baseTask: Sequence classification (binary)Languages: MultilingualTraining Framework: TensorFlow via Hugging Face TransformersLicense: [Insert your license here, e.g., Apache-2.0]π₯ AuthorsSumit RanjanRaj Bapodra
README.md+85-3