From 19a42a546df4a8cc884e5be4b63537cf77092123 Mon Sep 17 00:00:00 2001 From: mai <mai@cl.uni-heidelberg.de> Date: Sat, 11 Mar 2023 11:10:31 +0100 Subject: [PATCH] New script for attacking --- test.py | 3 ++- utils/attack.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 utils/attack.py diff --git a/test.py b/test.py index 136c6dd..3b778d3 100644 --- a/test.py +++ b/test.py @@ -45,8 +45,9 @@ for post in dataset(test_ids): detokenized = TreebankWordDetokenizer().detokenize(post["post_tokens"]) # ATTACK HERE + batch = attack(detokenized) - inputs = tokenizer(detokenized, return_tensors="pt", padding=True).to(device) + inputs = tokenizer(batch, return_tensors="pt", padding=True).to(device) prediction_logits, _ = model(input_ids=inputs['input_ids'],attention_mask=inputs['attention_mask']) softmax = torch.nn.Softmax(dim=1) probs = softmax(prediction_logits) diff --git a/utils/attack.py b/utils/attack.py new file mode 100644 index 0000000..5b456b3 --- /dev/null +++ b/utils/attack.py @@ -0,0 +1,4 @@ +import transformers + +def attack(sentence, model): + -- GitLab