import param import panel as pn pn.extension(sizing_mode="stretch_width", notifications=True) import pickle import pandas as pd css = ['https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css', # Below: Needed for export buttons 'https://cdn.datatables.net/buttons/1.7.0/css/buttons.dataTables.min.css' ] js = { '$': 'https://code.jquery.com/jquery-3.5.1.js', 'DataTable': 'https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js', # Below: Needed for export buttons 'buttons': 'https://cdn.datatables.net/buttons/1.7.0/js/dataTables.buttons.min.js', 'jszip': 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js', 'pdfmake': 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js', 'vfsfonts': 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js', 'html5buttons': 'https://cdn.datatables.net/buttons/1.7.0/js/buttons.html5.min.js', } pn.extension(css_files=css, js_files=js) script = """ """ import pandas as pd class ReactiveTables(param.Parameterized): the_word_for_finding_secret_languages = param.String('Asian') old_data = None @param.depends('the_word_for_finding_secret_languages') def data(self): print('new name', self.the_word_for_finding_secret_languages) if len(self.the_word_for_finding_secret_languages) > 0: if ord(self.the_word_for_finding_secret_languages[0]) in list(range(48, 57)): file_name = 'num_dict.pkl' elif ord(self.the_word_for_finding_secret_languages[0]) in list(range(97, 122)) + list(range(65, 90)): file_name = f'{ord(self.the_word_for_finding_secret_languages[0])}_dict.pkl' else: file_name = 'other_dict.pkl' print(f'all_secret_langauge_by_fist/{file_name}') datas = pickle.load(open(f'all_secret_langauge_by_fist/{file_name}', 'rb')) flag = False if self.the_word_for_finding_secret_languages in datas.keys(): self.old_data = pd.DataFrame(datas[self.the_word_for_finding_secret_languages]) flag = True return self.old_data, datas, flag # @param.depends('name_') # def summary(self): # return self.data()[0].describe() @param.depends('the_word_for_finding_secret_languages') def table_ours(self): data, _, flag = self.data() if flag: all_secret_language = ' ,'.join([f'"{i}"' for i in set(list(data['secret languages']))]).replace('', '[POS]') all_examples = list(set(list('"' + data['original sentences'] + '" -> "' + data['replaced sentences'] + '"'))) samples = '
'.join(all_examples[:10]).replace('', '[POS]') return pn.pane.HTML( f'

{self.the_word_for_finding_secret_languages}

All secret language for {self.the_word_for_finding_secret_languages}

{all_secret_language}

10 Examples for replaced sentences ("original sentences" -> "replaced sentences")

{samples}', sizing_mode='stretch_width') else: return pn.pane.HTML(f'

Sorry. {self.the_word_for_finding_secret_languages} is not in the dictionary.

' , sizing_mode='stretch_width') # @param.depends('name_', 'record_start_index', 'record_stop_index') # def notification(self): # _, datas, flag = self.data() # return_ = # if datas: # if flag: # _len = len(datas[self.name_]['tasks']) # return_ = pn.pane.HTML(f'

Found {self.name_}.

{self.name_} has {_len} secret languages found by SecretFinding. Presenting the secret languages from {self.record_start_index} to {min(self.record_stop_index, _len)}.

' , # sizing_mode='stretch_width') # else: # return_ = pn.pane.HTML('

initing

' , sizing_mode='stretch_width') # return return_ def panel(self): return pn.Column( pn.Param(self, name="", width=300, sizing_mode="stretch_width"), # self.notification, # "## Description", self.summary, # "## Table", self.table_ours, # width=1500, sizing_mode='stretch_width' ) component = ReactiveTables().panel() pn.template.FastListTemplate(site="ACL 23 Submission", title="Finding Secret Language of Language Models", main=[ "This page presents all secret languages discovered by our proposed SecretFinding algorithm on three multi-sentence datasets. To ensure optimal performance of this webapp, we only present 10 examples.", component ]).servable()