Home/Model Training/baseline-defenses
baseline-defenses logo

baseline-defenses

Enrichment pending
neelsjain/baseline-defenses

Official Code for "Baseline Defenses for Adversarial Attacks Against Aligned Language Models"

GraphCanon updated today · GitHub synced today

34
Stars
1
Forks
0
Open issues
1
Watchers
2y
Last push
PythonCreated Oct 26, 2023

Trust & integrity

Full report
Maintenance
Dormant (989d since push)
As of today · Source: github_public_v1
Provenance
Not a fork · Personal account
As of today · Source: github_public_v1
Security (OSV)
No lockfile
As of today · Source: none

Public GitHub metadata and optional OSV dependency scans. Signals, not a guarantee. Trust methodology.

Overview

Official Code for "Baseline Defenses for Adversarial Attacks Against Aligned Language Models"

Capability facts

Languages
python

Source: github.language · Jul 11, 2026

Categories

Compatibility

Sourced claims from the README excerpt - not unsourced marketing copy.

Works with ChatGPTChatGPT

Source: README excerpt (regex_v1, Jul 11, 2026)

The 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.
Source link

Tags

README

Baseline Defenses for Adversarial Attacks Against Aligned Language Models

Official Code for "Baseline Defenses for Adversarial Attacks Against Aligned Language Models"

Overview

We 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.

The 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.

Perplexity Filter

The perplexity filter in the code consists of two filters, a perplexity filter which as also been proposed in concurrent work by Alon et al. and a windowed perplexity filter, which consists of checking the perplexity of a window of $n$ tokens.

Paraphrase Defense

The 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.

Limitations

As in all research work, we were limited to the settings we explored in the paper.