{"data":{"slug":"neelsjain-baseline-defenses","name":"baseline-defenses","tagline":"Official Code for \"Baseline Defenses for Adversarial Attacks Against Aligned Language Models\"","github_url":"https://github.com/neelsjain/baseline-defenses","owner":"neelsjain","repo":"baseline-defenses","owner_avatar_url":"https://avatars.githubusercontent.com/u/90730659?v=4","primary_language":"Python","stars":34,"forks":1,"topics":[],"archived":false,"github_pushed_at":"2023-10-26T22:00:06+00:00","maintenance_label":"Dormant","url":"https://www.graphcanon.com/tools/neelsjain-baseline-defenses","markdown_url":"https://www.graphcanon.com/tools/neelsjain-baseline-defenses.md","api_url":"https://www.graphcanon.com/api/graphcanon/tools/neelsjain-baseline-defenses","graph_url":"https://www.graphcanon.com/api/graphcanon/graph?tool=neelsjain-baseline-defenses","description":"Official Code for \"Baseline Defenses for Adversarial Attacks Against Aligned Language Models\"","homepage_url":null,"license":null,"open_issues":0,"watchers":1,"ai_summary":null,"readme_excerpt":"# Baseline Defenses for Adversarial Attacks Against Aligned Language Models\nOfficial Code for \"Baseline Defenses for Adversarial Attacks Against Aligned Language Models\"\n\n## Overview\nWe evaluate several baseline defense strategies against leading adversarial attacks on LLMs, discussing the various settings in which each is feasible and effective. Particularly, we look at three types of defenses: detection (perplexity based), input preprocessing (paraphrase and retokenization), and adversarial training. The paper can be found [here](https://arxiv.org/abs/2309.00614).\n\nThe repository only contains the code for the perplexity filter and paraphrase attack. The retokenization defenses is conducted directly via altering tokenizer via BPE-dropout. For LLaMA model, see the `tokenizer.sp_model.encode(input_text, alpha=bt_alpha, enable_sampling=True)` function, and for other models, BPE-dropout is set by `tokenizer._tokenizer.model.dropout=bt_alpha`, where `bt_alpha` is the dropout rate.\n\n## Perplexity Filter\n\nThe perplexity filter in the code consists of two filters, a perplexity filter which as also been proposed in concurrent work by [Alon et al.](https://arxiv.org/abs/2308.14132) and a windowed perplexity filter, which consists of checking the perplexity of a window of $n$ tokens.\n\n## Paraphrase Defense\n\nThe paraphrase defense is rewriting the prompt. For our experiments, we used ChatGPT. Note while this defense is effective it might come at high performance cost.\n\n## Limitations\nAs in all research work, we were limited to the settings we explored in the paper.","github_created_at":"2023-10-26T21:41:28+00:00","created_at":"2026-07-11T23:41:25.359046+00:00","updated_at":"2026-07-11T23:41:31.684405+00:00","categories":[{"slug":"computer-vision","name":"Computer Vision","url":"https://www.graphcanon.com/categories/computer-vision","markdown_url":"https://www.graphcanon.com/categories/computer-vision.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/computer-vision"},{"slug":"llm-frameworks","name":"LLM Frameworks","url":"https://www.graphcanon.com/categories/llm-frameworks","markdown_url":"https://www.graphcanon.com/categories/llm-frameworks.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/llm-frameworks"},{"slug":"model-training","name":"Model Training","url":"https://www.graphcanon.com/categories/model-training","markdown_url":"https://www.graphcanon.com/categories/model-training.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/model-training"}],"tags":[{"slug":"python","name":"python"}],"trust":{"provenance":{"is_fork":false,"github_id":710521062,"owner_type":"User","methodology":"github_public_v1","parent_repo":null,"near_duplicate_slugs":[]},"computed_at":"2026-07-11T23:41:27.975Z","maintenance":{"label":"Dormant","score":18,"methodology":"github_public_v1","releases_90d":0,"days_since_push":989,"last_release_at":null},"security_summary":{"status":"no_lockfile","scanner":null,"low_count":0,"high_count":0,"last_scan_at":"2026-07-11T23:41:28.765Z","medium_count":0,"scan_profile":"none","critical_count":0}},"capability_facts":{"scan":{"source":"repo_scan","observed_at":"2026-07-11T23:41:27.401Z"},"languages":{"value":["python"],"source":"github.language","observed_at":"2026-07-11T23:41:27.401Z"}}}}