CoolFace
Modelpublic

CodeferSystem/GPT2-Hacker-password-generator

sourceHugging Faceapache-2.0updated 6mo agoView on Hugging Face
1likes28downloads
README.md93 linesDownload Raw Back to root
1---2license: apache-2.03language:4- en5pipeline_tag: text-generation6base_model:7- openai-community/gpt28library_name: transformers9datasets:10- CodeferSystem/GPT2-Hacker-password-generator-dataset11tags:12- cybersecurity13- passwords14---15# GPT-2 Hacker password generator.16This model can generate hacker passwords.17 18# Fine-tuning results19Number of epochs: 520 21Number of steps: 312522 23Loss: 0.51960024 25Fine-tuning time: almost 34:39 on Nvidia Geforce RTX 4060 8 GB GPU (laptop)26 27Fine-tuned on 20k examples of 128 tokens.28 29# Using the model30Use this code:31 32```python33from transformers import GPT2Tokenizer, GPT2LMHeadModel34import torch35 36model_name = "CodeferSystem/GPT2-Hacker-password-generator"37 38# Load the pre-trained GPT-2 model and tokenizer from the specified directory39tokenizer = GPT2Tokenizer.from_pretrained(model_name)  # Load standard GPT-2 tokenizer40model = GPT2LMHeadModel.from_pretrained(model_name)  # Load fine-tuned GPT-2 model41 42# Function to generate an answer based on a given question43def generate_answer(question):44    # Create a prompt by formatting the question for the model45    prompt = f"Question: {question}\nAnswer:"46    47    # Encode the prompt into input token IDs suitable for the model48    input_ids = tokenizer.encode(prompt, return_tensors="pt")49 50    # Set the model to evaluation mode51    model.eval()52 53    # Generate the output without calculating gradients (for efficiency)54    with torch.no_grad():55        output = model.generate(56            input_ids,                        # Provide the input tokens57            max_length=50,                     # Set the maximum length of the generated text58            num_return_sequences=1,           # Only return one sequence of text59            no_repeat_ngram_size=2,           # Prevent repeating n-grams (sequences of n words)60            do_sample=True,                   # Enable sampling (randomized generation)61            top_k=50,                          # Limit the model's choices to the top 50 probable words62            top_p=0.95,                        # Use nucleus sampling (the cumulative probability distribution)63            temperature=2.0,                   # Control the randomness/creativity of the output64            pad_token_id=tokenizer.eos_token_id  # Specify the padding token ID (EOS token in this case)65        )66 67    # Decode the generated token IDs back to a string and strip any special tokens68    generated_text = tokenizer.decode(output[0], skip_special_tokens=True)69    70    # Extract the part after "Answer:" to get the model's generated answer71    answer = generated_text.split("Answer:")[-1].strip()72    73    return answer74 75# Example usage76question = "generate password."77print(generate_answer(question))  # Print the generated password78```79# Example passwords generation with this model:80 81### If you write a prompt like "Generate a hacker password." - the password will be something like this (5 examples):82- 0Qk=4CdPQQv0>n1K83- o4K*mQq9>Zu84- e5vx=KqE_j>kFj&*85- xD2PZ5@kz_hFq|W=86- h=rZ?^<Qp~7&z7XZ87 88## Dataset of this model89The dataset on which the model was fine-tuned was uploaded to the public.90[Dataset this model](https://huggingface.co/datasets/CodeferSystem/GPT2-Hacker-password-generator-dataset)91 92## More improved model93[GPT-2-Hacker-password-generator-Medium](https://huggingface.co/CodeferSystem/GPT2-Hacker-password-generator-Medium)