Skip to content

Commit

Permalink
upd: utils module
Browse files Browse the repository at this point in the history
  • Loading branch information
jindongwang committed Oct 27, 2023
1 parent d496621 commit 46d441f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions promptbench/utils/dataprocess.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

class DataProcessor:
def __init__(self):
self.INPUT_PROCESS_MAP = {
Expand Down
6 changes: 3 additions & 3 deletions promptbench/utils/defense.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@


class Defense(object):
def __init__(self, lang='en', defense_method='autocorrect'):
def __init__(self, defense_method='spellcorrect', lang='en'):
self.defense_method = defense_method
if self.defense_method == 'autocorrect':
if self.defense_method == 'spellcorrect':
self.spell = Speller(lang=lang)

def __call__(self, text):
if self.defense_method == 'autocorrect':
if self.defense_method == 'spellcorrect':
return self.spell(text)
else:
raise NotImplementedError
Expand Down
2 changes: 1 addition & 1 deletion promptbench/utils/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Visualizer:

def __init__(self) -> None:
def __init__(self, model) -> None:
self.model = model

def vis_by_grad(self, tokenizer, input_sentence, label):
Expand Down
6 changes: 6 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
output_t5 = model_t5("Translate English to German: 'Hello World'")
print(output_t5)

# test visualization, not tested yet
from promptbench.utils import Visualizer
x = Visualizer('google/flan-t5-large')
print(x)

# test defense of prompt input using spell correct
from promptbench.utils import Defense
x = Defense('spellcorrect')
print(x('I am a student at the Univrsity of California, Berkeey.'))

0 comments on commit 46d441f

Please sign in to comment.