Instructions to use Canstralian/CyberAttackDetection with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Canstralian/CyberAttackDetection with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="Canstralian/CyberAttackDetection")# Load model directly from transformers import AutoModelForSequenceClassification model = AutoModelForSequenceClassification.from_pretrained("Canstralian/CyberAttackDetection", dtype="auto") - Notebooks
- Google Colab
- Kaggle
Create model.py
Browse files
model.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 2 |
+
from config import Config
|
| 3 |
+
|
| 4 |
+
class CyberAttackDetectionModel:
|
| 5 |
+
def __init__(self):
|
| 6 |
+
self.tokenizer = AutoTokenizer.from_pretrained(Config.TOKENIZER_NAME)
|
| 7 |
+
self.model = AutoModelForCausalLM.from_pretrained(Config.MODEL_NAME)
|
| 8 |
+
self.model.to(Config.DEVICE)
|
| 9 |
+
|
| 10 |
+
def predict(self, prompt):
|
| 11 |
+
inputs = self.tokenizer(prompt, return_tensors="pt", truncation=True, max_length=Config.MAX_LENGTH)
|
| 12 |
+
inputs = {key: value.to(Config.DEVICE) for key, value in inputs.items()}
|
| 13 |
+
|
| 14 |
+
outputs = self.model.generate(**inputs, max_length=Config.MAX_LENGTH)
|
| 15 |
+
return self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|