Run this model with HF Jobs
Run ehsanaghaei/SecureBERT_Plus on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/ehsanaghaei/SecureBERT_Plus. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/ehsanaghaei/SecureBERT_Plus on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use ehsanaghaei/SecureBERT_Plus with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ehsanaghaei/SecureBERT_Plus with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="ehsanaghaei/SecureBERT_Plus")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("ehsanaghaei/SecureBERT_Plus") model = AutoModelForMaskedLM.from_pretrained("ehsanaghaei/SecureBERT_Plus", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Commit ·
2308937
1
Parent(s): 7221211
Update README.md
Browse files13 unmodified lines1415161718193 unmodified lines23242513 unmodified lines## DatasetOther model variants:[SecureGPT](https://huggingface.co/ehsanaghaei/SecureGPT)3 unmodified lines[SecureBERT](https://huggingface.co/ehsanaghaei/SecureBERT)13 unmodified lines1415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384853 unmodified lines899091929394959697989910010110210310410513 unmodified lines## Dataset## Load ModelSecureBER+T has been uploaded to [Huggingface](https://huggingface.co/ehsanaghaei/SecureBERT_Plus) framework.```pythonfrom transformers import RobertaTokenizer, RobertaModelimport torchtokenizer = RobertaTokenizer.from_pretrained("ehsanaghaei/SecureBERT_Plus")model = RobertaModel.from_pretrained("ehsanaghaei/SecureBERT_Plus")inputs = tokenizer("This is SecureBERT Plus!", return_tensors="pt")outputs = model(**inputs)last_hidden_states = outputs.last_hidden_state```## Fill Mask (MLM)Use the code below to predict the masked word within the given sentences:```python#!pip install transformers#!pip install torch#!pip install tokenizersimport torchimport transformersfrom transformers import RobertaTokenizer, RobertaTokenizerFasttokenizer = RobertaTokenizerFast.from_pretrained("ehsanaghaei/SecureBERT_Plus")model = transformers.RobertaForMaskedLM.from_pretrained("ehsanaghaei/SecureBERT_Plus")def predict_mask(sent, tokenizer, model, topk =10, print_results = True):token_ids = tokenizer.encode(sent, return_tensors='pt')masked_position = (token_ids.squeeze() == tokenizer.mask_token_id).nonzero()masked_pos = [mask.item() for mask in masked_position]words = []with torch.no_grad():output = model(token_ids)last_hidden_state = output[0].squeeze()list_of_list = []for index, mask_index in enumerate(masked_pos):mask_hidden_state = last_hidden_state[mask_index]idx = torch.topk(mask_hidden_state, k=topk, dim=0)[1]words = [tokenizer.decode(i.item()).strip() for i in idx]words = [w.replace(' ','') for w in words]list_of_list.append(words)if print_results:print("Mask ", "Predictions: ", words)best_guess = ""for j in list_of_list:best_guess = best_guess + "," + j[0]return wordswhile True:sent = input("Text here: \t")print("SecureBERT: ")predict_mask(sent, tokenizer, model)print("===========================\n")```Other model variants:[SecureGPT](https://huggingface.co/ehsanaghaei/SecureGPT)3 unmodified lines[SecureBERT](https://huggingface.co/ehsanaghaei/SecureBERT)# Reference@inproceedings{aghaei2023securebert,title={SecureBERT: A Domain-Specific Language Model for Cybersecurity},author={Aghaei, Ehsan and Niu, Xi and Shadid, Waseem and Al-Shaer, Ehab},booktitle={Security and Privacy in Communication Networks:18th EAI International Conference, SecureComm 2022, Virtual Event,October 2022,Proceedings},pages={39--56},year={2023},organization={Springer} }
README.md+80