Downloads ยท 30 days
19
18% of all-time downloads
debashis2007/security-mistral-lora
security-mistral-lora is a text generation model from debashis2007. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
A fine-tuned Mistral 7B model optimized for cybersecurity questions and answers using LoRA (Low-Rank Adaptation).
Downloads ยท 30 days
19
18% of all-time downloads
All-time downloads
105
Public
Repo size
14.1 MB
Likes
0
Public
Click a slice to open those files.
.safetensors13.6 MB ยท 77%
From the Hugging Face model README
A fine-tuned Mistral 7B model optimized for cybersecurity questions and answers using LoRA (Low-Rank Adaptation).
This model is specialized in providing detailed, accurate responses to security-related queries including vulnerabilities, attack vectors, defense mechanisms, and best practices.
| Property | Value |
|---|---|
| Base Model | mistralai/Mistral-7B-Instruct-v0.1 |
| Fine-tuning Method | LoRA (r=8, ฮฑ=16) |
| Training Data | 24 security Q&A pairs (JSONL format) |
| Model Size | 7B parameters (base) |
| LoRA Adapter Size | ~50-100 MB |
| Framework | Transformers + PEFT |
| License | Same as Mistral (Apache 2.0) |
This model is designed for:
# Install required packages
pip install transformers peft torch
# (Optional) For GPU support
pip install torch --index-url https://download.pytorch.org/whl/cu118
from peft import AutoPeftModelForCausalLM
from transformers import AutoTokenizer
# Load the model
model = AutoPeftModelForCausalLM.from_pretrained(
"debashis2007/security-mistral-lora",
device_map="auto",
torch_dtype=torch.float16,
)
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
# Prepare input (Mistral format)
prompt = "[INST] What is SQL injection and how do you prevent it? [/INST]"
inputs = tokenizer(prompt, return_tensors="pt")
# Generate response
with torch.no_grad():
outputs = model.generate(
**inputs,
max_length=256,
temperature=0.7,
top_p=0.9,
)
# Decode and print
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
from peft import AutoPeftModelForCausalLM
from transformers import AutoTokenizer
import torch
# Load model with specific settings
model = AutoPeftModelForCausalLM.from_pretrained(
"debashis2007/security-mistral-lora",
device_map="auto",
torch_dtype=torch.float16,
load_in_8bit=True, # Optional: 8-bit quantization for memory efficiency
)
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
# Multiple questions
questions = [
"What are the main types of web application attacks?",
"How do you implement CSRF protection?",
"Explain the principle of least privilege",
]
for question in questions:
prompt = f"[INST] {question} [/INST]"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_length=512,
temperature=0.7,
top_p=0.95,
do_sample=True,
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(f"Q: {question}\nA: {response}\n" + "="*60 + "\n")
| Parameter | Value |
|---|---|
| Learning Rate | 2e-4 |
| Epochs | 1 |
| Batch Size | 1 |
| Gradient Accumulation | 4 |
| Max Token Length | 256 |
| Optimizer | paged_adamw_8bit |
| Precision | FP16 |
| LoRA Rank (r) | 8 |
| LoRA Alpha | 16 |
| LoRA Dropout | 0.05 |
| Target Modules | ["q_proj", "v_proj"] |
Example data point:
{
"instruction": "What is SQL injection and how do you prevent it?",
"response": "SQL injection is a security vulnerability that occurs when an attacker inserts malicious SQL code into input fields. It exploits improperly validated or unescaped user input. Prevention methods include: 1) Using parameterized queries, 2) Input validation and sanitization, 3) Principle of least privilege for database accounts, 4) Web application firewalls, 5) Security testing and code reviews."
}
prompt = "[INST] What is a buffer overflow vulnerability? [/INST]"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_length=256, temperature=0.7)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Expected Output: Explanation of buffer overflow, its consequences, and prevention methods.
prompt = "[INST] What are the best practices for password storage? [/INST]"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_length=256, temperature=0.7)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Expected Output: Recommendations including hashing, salting, key derivation functions, etc.
prompt = "[INST] How would an attacker exploit an unpatched software vulnerability? [/INST]"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_length=256, temperature=0.7)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Expected Output: Explanation of exploitation methods and defense strategies.
The model uses:
LoraConfig(
r=8, # Rank
lora_alpha=16, # Scaling factor
lora_dropout=0.05, # Dropout probability
bias="none", # Don't train bias
task_type="CAUSAL_LM", # Causal language modeling
target_modules=["q_proj", "v_proj"], # Adapted modules
inference_mode=False, # Training mode
)
The model was evaluated on:
To fine-tune this model further on your own data:
from peft import LoraConfig, get_peft_model
from transformers import AutoModelForCausalLM, TrainingArguments, Trainer
from datasets import load_dataset
# Load base model with adapter
model = AutoPeftModelForCausalLM.from_pretrained("debashis2007/security-mistral-lora")
# Merge with base model if you want to continue training
model = model.merge_and_unload()
# Or create new LoRA config for additional training
lora_config = LoraConfig(
r=8,
lora_alpha=16,
target_modules=["q_proj", "v_proj"],
lora_dropout=0.05,
bias="none",
task_type="CAUSAL_LM",
)
model = get_peft_model(model, lora_config)
# Define training arguments
training_args = TrainingArguments(
output_dir="./security-mistral-lora-v2",
num_train_epochs=3,
per_device_train_batch_size=1,
gradient_accumulation_steps=4,
learning_rate=2e-4,
fp16=True,
save_steps=10,
logging_steps=5,
)
# Create trainer
trainer = Trainer(
model=model,
args=training_args,
train_dataset=dataset,
)
# Train
trainer.train()
This model is based on:
Modifications using LoRA are provided as-is. Please comply with the original Mistral license.
If you use this model, please cite:
@misc{security-mistral-lora,
title={Security-Focused Mistral 7B LoRA},
author={debashis2007},
year={2024},
howpublished={\url{https://huggingface.co/debashis2007/security-mistral-lora}}
}
Found an issue or have suggestions? Feel free to open an issue on the model repository.
This model is for educational and research purposes only.
For questions about this model:
| Version | Date | Changes |
|---|---|---|
| v1.0 | 2024-12 | Initial release with 24 security examples |
This model is part of a security-focused AI training project. It demonstrates:
Last Updated: December 2024
Model Status: Active
Maintained By: debashis2007