Text Classification
Keras
English
Azerbaijani
prompt-injection
security
llm-security
document-security
retvec
cnn
tensorflow
fastapi
Eval Results (legacy)
Instructions to use MegrurNiftiyev/MyGuard-Prompt-Injection-Detector with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use MegrurNiftiyev/MyGuard-Prompt-Injection-Detector with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://MegrurNiftiyev/MyGuard-Prompt-Injection-Detector") - Notebooks
- Google Colab
- Kaggle
Download app/ml/preprocessing/chunking.py from MegrurNiftiyev/MyGuard-Prompt-Injection-Detector: direct link, hf CLI and curl.
- Browser
- Download file 880 Bytes
-
https://huggingface.co/MegrurNiftiyev/MyGuard-Prompt-Injection-Detector/resolve/main/app/ml/preprocessing/chunking.py
- Command line
-
hf download hf://MegrurNiftiyev/MyGuard-Prompt-Injection-Detector/app/ml/preprocessing/chunking.py
-
curl -L -o chunking.py https://huggingface.co/MegrurNiftiyev/MyGuard-Prompt-Injection-Detector/resolve/main/app/ml/preprocessing/chunking.py
880 Bytes
| """ | |
| Shared text chunking logic for training and inference. | |
| """ | |
| def chunk_text(text: str, chunk_size: int = 60, overlap: int = 30) -> list[str]: | |
| """Chunk text into sliding word windows while preserving line breaks. | |
| Args: | |
| text: Raw document text input. | |
| chunk_size: Maximum words per chunk (default: 60). | |
| overlap: Word overlap between consecutive chunks (default: 30). | |
| Returns: | |
| List of text chunk strings. | |
| """ | |
| lines = [line.strip() for line in text.split("\n") if line.strip()] | |
| chunks = [] | |
| for line in lines: | |
| words = line.split() | |
| if len(words) <= chunk_size: | |
| chunks.append(line) | |
| else: | |
| i = 0 | |
| while i < len(words): | |
| c = " ".join(words[i:i + chunk_size]) | |
| chunks.append(c) | |
| i += chunk_size - overlap | |
| return chunks | |