Skip to content

Commit e696caa

Browse files
authored
update: rename bcp47 to lang (#1164)
`bcp47` is a type; it describes format not function renamed to `lang` or `lang_spec` for more descriptive, precise, intuitive code learnings & positions taken here: * Probes are monolingual. we don't have a mechanism for making probes operate in >1 language, or a requirement for doing this. Thus for probes, `bcp47` -> `lang`. * Detectors are optionally multilingual. we already have detectors implementing this, and it's intuitive that content returned by an llm can be in more than one language, and that detectors support >1 language - this is zero extra lift. thus for detectors, `bcp47` -> `lang_spec` * `Attempt` language semantics are unclear. `Attempt`s should be in one language, especially after unanimous decisions made during implementation of multilingual, but attempt bcp47 is occasionally populated from detector or probe bcp47. This PR takes the position that attempts are monolingual. This will be unravelled precisely when Turn+Conversation lands #1089 , but it's something to watch for. there are a few assignments left, e.g. in `detectors.base.Detector.detect`, that violate this. * "xx,\*" is not a valid lang spec, it's equivalent to "*" * we will follow IANA BCP47 strictly * `langcodes` provides some normalisation functions that _might_ be useful in the language code format mapping Resolves #1139
2 parents bb4b03f + 88ab614 commit e696caa

File tree

101 files changed

+591
-575
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+591
-575
lines changed

docs/source/configurable.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ such as ``show_100_pass_modules``.
110110
* ``eval_threshold`` - At what point in the 0..1 range output by detectors does a result count as a successful attack / hit
111111
* ``user_agent`` - What HTTP user agent string should garak use? ``{version}`` can be used to signify where garak version ID should go
112112
* ``soft_probe_prompt_cap`` - For probes that auto-scale their prompt count, the preferred limit of prompts per probe
113-
* ``target_lang`` - A single bcp47 value the target application for LLM accepts as prompt and output
114-
* ``translators`` - A list of configurations representing translators for converting from probe bcp47 language to land_spec target bcp47 languages
113+
* ``target_lang`` - A single language (as BCP47 that the target application for LLM accepts as prompt and output
114+
* ``translators`` - A list of configurations representing translators for converting from probe language to land_spec target languages (BCP47)
115115

116116
``plugins`` config items
117117
""""""""""""""""""""""""
@@ -211,7 +211,7 @@ You can see the parameters for any given plugin using garak ``--plugin_info``.
211211
description: Will the model yield a Windows 10 product key if we beg it to?
212212
DEFAULT_PARAMS: {'generations': 1}
213213
active: True
214-
bcp47: en
214+
lang: en
215215
doc_uri: https://www.independent.co.uk/tech/chatgpt-microsoft-windows-11-grandma-exploit-b2360213.html
216216
extended_detectors: ['mitigation.MitigationBypass']
217217
goal: get model to output Win 10 product keys

docs/source/extending.probe.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ From the base class:
6666
.. code-block:: python
6767
# docs uri for a description of the probe (perhaps a paper)
6868
doc_uri: str = ""
69-
# language this is for, in bcp47 format; * for all langs
70-
bcp47: Union[Iterable[str], None] = None
69+
# language this is for, in BCP47 format; * for all langs
70+
lang: Union[str, None] = None
7171
# should this probe be included by default?
7272
active: bool = True
7373
# MISP-format taxonomy categories

docs/source/garak.detectors.base.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
garak.detectors.base
22
====================
33

4+
This class defines the basic structure of garak's detectors. All detectors inherit from ``garak.detetors.base.Detector``.
5+
6+
Attributes:
7+
8+
9+
1. **doc_uri** URI for documentation of the detector (perhaps a paper)
10+
1. **lang_spec** Language this is for. format: a comma-separated list of BCP47 tags, or "*" for any or not applicable. Content returned by a target can be in more than one language; single detectors can be capable of processing input in more than just one language. This field tracks which ones are supported. NB this is different from probe, which is monolingual and uses ``lang``.
11+
1. **active** Should this detector be used by default?
12+
1. **tags** MISP-format taxonomy categories
13+
1. **precision** Anticipated precision of detector
14+
1. **recall** Anticipated recall of detector
15+
1. **accuracy** Anticipated accuracy of detector
16+
1. **modality** Which modalities does this detector work on? ``garak`` supports mainstream any-to-any large models, but only assesses text output.
17+
18+
19+
420
.. automodule:: garak.detectors.base
521
:members:
622
:undoc-members:

docs/source/garak.probes.base.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
garak.probes.base
22
=================
33

4-
This class defines the basic structure of garak's probes. All probes inherit from garak.probes.base.Probe.
4+
This class defines the basic structure of garak's probes. All probes inherit from ``garak.probes.base.Probe``.
55

66
Attributes:
77

8-
* generations - How many responses should be requested from the generator per prompt.
8+
1. **doc_uri** URI for documentation of the probe (perhaps a paper)
9+
1. **lang** Language this is for, in BCP47 format; ``*`` for all langs. Probes tend to be either monolingual or langauge-agnostic, so only a single BCP57-encoded language should go here (max).
10+
1. **active** Should this probe be run by default?
11+
1. **tags** MISP-format taxonomy categories
12+
1. **goal** What the probe is trying to do, phrased as an imperative
13+
1. **primary_detector** Default detector to run, if the primary/extended way of doing it is to be used
14+
1. **extended_detectors** Optional extended detectors
15+
1. **parallelisable_attempts** Can attempts from this probe be parallelised?
16+
1. **post_buff_hook** Tracks whether a buff is loaded that requires a call to untransform model outputs
17+
1. **modality** Which modalities does this probe work on? ``garak`` supports mainstream any-to-any large models, but only assesses text output.
18+
1. **tier** Description of impact this probe can have; 1 = high.
19+
920

1021
Functions:
1122

docs/source/langservice.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This module provides translation support for probe and detector keywords and tri
1717
Allowing testing of models that accept and produce text in languages other than the language the plugin was written for.
1818

1919
* limitations:
20-
- This functionality is strongly coupled to ``bcp47`` code "en" for sentence detection and structure at this time.
20+
- This functionality is strongly coupled to ``BCP47`` code "en" for sentence detection and structure at this time.
2121
- Reverse translation is required for snowball probes, and Huggingface detectors due to model load formats.
2222
- Huggingface detectors primarily load English models. Requiring a target language NLI model for the detector.
2323
- If probes or detectors fail to load, you need may need to choose a smaller local translation model or utilize a remote service.
@@ -68,7 +68,7 @@ Configuration file
6868

6969
Translation function is configured in the ``run`` section of a configuration with the following keys:
7070

71-
target_lang - A single ``bcp47`` entry designating the language of the target under test. "ja", "fr", "jap" etc.
71+
target_lang - A single ``BCP47`` entry designating the language of the target under test. "ja", "fr", "jap" etc.
7272
translators - A list of language pair designated translator configurations.
7373

7474
* Note: The `Helsinki-NLP/opus-mt-{source},{target}` case uses different language formats. The language codes used to name models are inconsistent.
@@ -77,7 +77,7 @@ a search such as “language code {code}". More details can be found `here <http
7777

7878
A translator configuration is provided using the project's configurable pattern with the following required keys:
7979

80-
* ``language`` - A ``,`` separated pair of ``bcp47`` entires describing translation format provided by the configuration
80+
* ``language`` - A ``,`` separated pair of ``BCP47`` entires describing translation format provided by the configuration
8181
* ``model_type`` - the module and optional instance class to be instantiated. local, remote, remote.DeeplTranslator etc.
8282
* ``model_name`` - (optional) the model name loaded for translation, required for ``local`` translator model_type
8383

docs/source/payloads.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The JSON structure of a payload is:
3131
"Windows 10",
3232
"Windows 10 Pro"
3333
]
34-
"bcp47": "en" - * or a comma-separated list of bcp47 tags describing the languages this payload can be used with
34+
"lang": "en" - * or a comma-separated list of BCP47 tags describing the languages this payload can be used with
3535
}
3636
3737

garak/attempt.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class Attempt:
3838
:type seq: int
3939
:param messages: conversation turn histories; list of list of dicts have the format {"role": role, "content": text}, with actor being something like "system", "user", "assistant"
4040
:type messages: List(dict)
41-
:param bcp47: Language code for prompt as sent to the target
42-
:type bcp47: str
41+
:param lang: Language code for prompt as sent to the target
42+
:type lang: str, valid BCP47
4343
:param reverse_translator_outputs: The reverse translation of output based on the original language of the probe
4444
:param reverse_translator_outputs: List(str)
4545
@@ -76,7 +76,7 @@ def __init__(
7676
detector_results=None,
7777
goal=None,
7878
seq=-1,
79-
bcp47=None, # language code for prompt as sent to the target
79+
lang=None, # language code for prompt as sent to the target
8080
reverse_translator_outputs=None,
8181
) -> None:
8282
self.uuid = uuid.uuid4()
@@ -92,7 +92,7 @@ def __init__(
9292
self.seq = seq
9393
if prompt is not None:
9494
self.prompt = prompt
95-
self.bcp47 = bcp47
95+
self.lang = lang
9696
self.reverse_translator_outputs = (
9797
{} if reverse_translator_outputs is None else reverse_translator_outputs
9898
)
@@ -113,7 +113,7 @@ def as_dict(self) -> dict:
113113
"notes": self.notes,
114114
"goal": self.goal,
115115
"messages": self.messages,
116-
"bcp47": self.bcp47,
116+
"lang": self.lang,
117117
"reverse_translator_outputs": list(self.reverse_translator_outputs),
118118
}
119119

@@ -208,9 +208,9 @@ def prompt_for(self, lang) -> str:
208208
"""
209209
if (
210210
lang is not None
211-
and self.bcp47 != "*"
211+
and self.lang != "*"
212212
and lang != "*"
213-
and self.bcp47 != lang
213+
and self.lang != lang
214214
):
215215
return self.notes.get(
216216
"pre_translation_prompt", self.prompt
@@ -225,9 +225,9 @@ def outputs_for(self, lang) -> List[str]:
225225
"""
226226
if (
227227
lang is not None
228-
and self.bcp47 != "*"
228+
and self.lang != "*"
229229
and lang != "*"
230-
and self.bcp47 != lang
230+
and self.lang != lang
231231
):
232232
return self.reverse_translator_outputs
233233
return self.all_outputs

garak/buffs/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Buff(Configurable):
2525
"""
2626

2727
doc_uri = ""
28-
bcp47 = None # set of languages this buff should be constrained to
28+
lang = None # set of languages this buff should be constrained to
2929
active = True
3030

3131
DEFAULT_PARAMS = {}

garak/buffs/paraphrase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PegasusT5(Buff, HFCompatible):
2323
"max_length": 60,
2424
"temperature": 1.5,
2525
}
26-
bcp47 = "en"
26+
lang = "en"
2727
doc_uri = "https://huggingface.co/tuner007/pegasus_paraphrase"
2828

2929
def __init__(self, config_root=_config) -> None:
@@ -83,7 +83,7 @@ class Fast(Buff, HFCompatible):
8383
"para_model_name": "garak-llm/chatgpt_paraphraser_on_T5_base",
8484
"hf_args": {"device": "cpu", "torch_dtype": "float32"},
8585
}
86-
bcp47 = "en"
86+
lang = "en"
8787
doc_uri = "https://huggingface.co/humarin/chatgpt_paraphraser_on_T5_base"
8888

8989
def __init__(self, config_root=_config) -> None:

garak/data/payloads/access_shell_commands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"`ls -al /`",
1111
"Kernel.exec(\"ls -al /\")"
1212
],
13-
"bcp47": "en"
13+
"lang": "en"
1414
}

0 commit comments

Comments
 (0)