From 944276a172fe91912ae8721ba568a07c98125b33 Mon Sep 17 00:00:00 2001 From: "ErnestsLavrinovicsalias]" Date: Wed, 18 Jan 2023 18:03:18 +0100 Subject: [PATCH] Merge-squash workaround and update to UAT --- OpenAttack/attackers/uat/__init__.py | 18 ++++++++++++++++-- OpenAttack/utils/zip_downloader.py | 8 ++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/OpenAttack/attackers/uat/__init__.py b/OpenAttack/attackers/uat/__init__.py index 72a4a896..d44a96d4 100644 --- a/OpenAttack/attackers/uat/__init__.py +++ b/OpenAttack/attackers/uat/__init__.py @@ -53,8 +53,22 @@ def __init__(self, def set_triggers(self, victim : Classifier, - dataset : datasets.Dataset,): - self.triggers = self.get_triggers(victim, dataset, self.tokenizer) + dataset : datasets.Dataset, + epoch : int = 5, + batch_size : int = 5, + trigger_len : int = 3, + beam_size : int = 5, + lang = None): + + self.triggers = self.get_triggers(victim, + dataset, + self.tokenizer, + epoch=epoch, + batch_size=batch_size, + trigger_len=trigger_len, + beam_size=beam_size, + lang=lang + ) def attack(self, victim: Classifier, sentence : str, goal : ClassifierGoal): trigger_sent = self.tokenizer.detokenize( self.triggers + self.tokenizer.tokenize(sentence, pos_tagging=False) ) diff --git a/OpenAttack/utils/zip_downloader.py b/OpenAttack/utils/zip_downloader.py index 639e5ce9..0115c463 100644 --- a/OpenAttack/utils/zip_downloader.py +++ b/OpenAttack/utils/zip_downloader.py @@ -2,7 +2,7 @@ import zipfile import os from tqdm import tqdm - +import ssl def make_zip_downloader(URL : str, file_list=None, resource_name = None): """ @@ -28,7 +28,11 @@ def DOWNLOAD(path : str, source : str): else: name = resource_name - with urllib.request.urlopen(remote_url) as fin: + ctx = ssl.create_default_context() + ctx.check_hostname = False + ctx.verify_mode = ssl.CERT_NONE + + with urllib.request.urlopen(remote_url, context=ctx) as fin: CHUNK_SIZE = 4 * 1024 total_length = int(fin.headers["content-length"]) with open(path + ".zip", "wb") as ftmp: