Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/multilingual #943

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b6464ea
Add Feature: translation functionality
masayaOgushi Oct 9, 2024
f94bb2e
Add Feature: probes add translation function
masayaOgushi Oct 9, 2024
2238d18
Add Feature: detector add translation capabilities
masayaOgushi Oct 9, 2024
7202e19
Add Feature: Enhance command-line interface with new translation options
masayaOgushi Oct 9, 2024
1105bb1
chore: Update dependencies in requirements.txt, pyproject.toml
masayaOgushi Oct 9, 2024
6bb7da3
docs: Add translation documentation
masayaOgushi Oct 9, 2024
717f0ff
Merge branch 'leondz:main' into feature/multilingual
SnowMasaya Oct 9, 2024
b35cc1e
Update Feature: Translator
masayaOgushi Oct 23, 2024
bbb6c76
Update Feature: Probes
masayaOgushi Oct 23, 2024
51baeb2
Update Feature: Detectors
masayaOgushi Oct 23, 2024
dc3a4ab
Update Feature: cli
masayaOgushi Oct 23, 2024
ee82261
Update Feature: config
masayaOgushi Oct 23, 2024
7cb8acc
Update Feature: conftest
masayaOgushi Oct 23, 2024
ec9b40a
Remove: library
masayaOgushi Oct 23, 2024
d50d19e
Update Doc
masayaOgushi Oct 23, 2024
808f34a
Merge branch 'feature/multilingual' of https://github.com/SnowMasaya/…
masayaOgushi Oct 23, 2024
8a41c95
Merge branch 'main' into feature/multilingual
SnowMasaya Oct 23, 2024
2fc2dd5
Fix test
masayaOgushi Oct 23, 2024
8283b65
Merge branch 'feature/multilingual' of https://github.com/SnowMasaya/…
masayaOgushi Oct 23, 2024
395840d
Update Feature Translation
masayaOgushi Oct 31, 2024
73363f9
Add Feature Probes
masayaOgushi Oct 31, 2024
57d14e5
Update Feature Detectors
masayaOgushi Oct 31, 2024
3b3b60a
Update test
masayaOgushi Oct 31, 2024
bae54d7
Add library
masayaOgushi Oct 31, 2024
022b821
Remove test code
masayaOgushi Dec 12, 2024
ad475ba
Add Feature
masayaOgushi Dec 12, 2024
a816836
Remove translation check
masayaOgushi Dec 12, 2024
e7363de
Update reverse translation
masayaOgushi Dec 12, 2024
563060b
Remove translation function
masayaOgushi Dec 12, 2024
a3922e7
Add detector test
masayaOgushi Dec 12, 2024
a3dd8de
Update probes
masayaOgushi Dec 12, 2024
4c4ad68
Update harness base
masayaOgushi Dec 12, 2024
641b851
Add probe test code
masayaOgushi Dec 12, 2024
8a0ee80
Update Translation
masayaOgushi Dec 12, 2024
b877b97
Update test translation
masayaOgushi Dec 12, 2024
5820f95
Update doc
masayaOgushi Dec 12, 2024
e53e7d2
Merge 'main' into feature/multilingual
jmartin-tech Feb 7, 2025
e5a08c7
Streamline translation use case
jmartin-tech Nov 7, 2024
6780578
Merge pull request #1 from jmartin-tech/feature/multilingual-translation
SnowMasaya Feb 14, 2025
5da27d2
cleanup imports and tests
jmartin-tech Feb 14, 2025
b44b8b7
mulitprocessing and signature fixes for remote translators
jmartin-tech Feb 19, 2025
a7f2224
extend configuration to allow hosted Riva instance
jmartin-tech Feb 19, 2025
dccaf2e
consolidate translation for `Attempt` in probe
jmartin-tech Feb 20, 2025
87e1844
remote translation input format
jmartin-tech Feb 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mulitprocessing and signature fixes for remote translators
* remote Riva do not serialize client object
* remove extra call to get_generator in atkgen

Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
  • Loading branch information
jmartin-tech committed Feb 19, 2025
commit b44b8b7496d88a60badac70ecc7b0c489cd0b4d9
2 changes: 0 additions & 2 deletions garak/probes/atkgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,3 @@ def __init__(self, config_root=_config):
msg = f"No query placeholder {TEMPLATE_PLACEHOLDER} in {self.__class__.__name__} prompt template {self.red_team_prompt_template}"
logging.critical(msg)
raise ValueError(msg)

self.translator = self.get_translator()
24 changes: 20 additions & 4 deletions garak/translators/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ class RivaTranslator(Translator):
]
# fmt: on

# avoid attempt to pickle the client attribute
def __getstate__(self) -> object:
self._clear_translator()
return dict(self.__dict__)

# restore the client attribute
def __setstate__(self, d) -> object:
self.__dict__.update(d)
self._load_translator()

def _clear_translator(self):
self.nmt_client = None

def _load_translator(self):
if not (
self.source_lang in self.bcp47_support
Expand All @@ -59,9 +72,11 @@ def _load_translator(self):
)
self.nmt_client = riva.client.NeuralMachineTranslationClient(auth)

def _translate(self, text: str, source_lang: str, target_lang: str) -> str:
def _translate(self, text: str) -> str:
try:
response = self.nmt_client.translate([text], "", source_lang, target_lang)
response = self.nmt_client.translate(
[text], "", self.source_lang, self.target_lang
)
return response.translations[0].text
except Exception as e:
logging.error(f"Translation error: {str(e)}")
Expand Down Expand Up @@ -104,10 +119,11 @@ def _load_translator(self):
if self.translator is None:
self.translator = Translator(self.api_key)

def _translate(self, text: str, source_lang: str, target_lang: str) -> str:
def _translate(self, text: str) -> str:
try:
target_lang = "EN-US" if self.target_lang == "en" else self.target_lang
return self.translator.translate_text(
text, source_lang=source_lang, target_lang=target_lang
text, source_lang=self.source_lang, target_lang=target_lang
).text
except Exception as e:
logging.error(f"Translation error: {str(e)}")
Expand Down