Python argparse.HelpFormatter() Examples
The following are 30 code examples for showing how to use argparse.HelpFormatter(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
argparse
, or try the search function
.
Example 1
Project: wifite2mod Author: nuncan File: args.py License: GNU General Public License v2.0 | 7 votes |
def get_arguments(self): ''' Returns parser.args() containing all program arguments ''' parser = argparse.ArgumentParser(usage=argparse.SUPPRESS, formatter_class=lambda prog: argparse.HelpFormatter( prog, max_help_position=80, width=130)) self._add_global_args(parser.add_argument_group(Color.s('{C}SETTINGS{W}'))) self._add_wep_args(parser.add_argument_group(Color.s('{C}WEP{W}'))) self._add_wpa_args(parser.add_argument_group(Color.s('{C}WPA{W}'))) self._add_wps_args(parser.add_argument_group(Color.s('{C}WPS{W}'))) self._add_pmkid_args(parser.add_argument_group(Color.s('{C}PMKID{W}'))) self._add_eviltwin_args(parser.add_argument_group(Color.s('{C}EVIL TWIN{W}'))) self._add_command_args(parser.add_argument_group(Color.s('{C}COMMANDS{W}'))) return parser.parse_args()
Example 2
Project: inferbeddings Author: uclnlp File: nli-query-cli.py License: MIT License | 6 votes |
def main(argv): def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=100, width=200) argparser = argparse.ArgumentParser('NLI Client', formatter_class=formatter) argparser.add_argument('s1', action='store', type=str) argparser.add_argument('s2', action='store', type=str) argparser.add_argument('--url', '-u', action='store', type=str, default='http://127.0.0.1:8889/v1/nli') args = argparser.parse_args(argv) sentence1 = args.s1 sentence2 = args.s2 url = args.url prediction = call_service(url=url, sentence1=sentence1, sentence2=sentence2) print(prediction)
Example 3
Project: inferbeddings Author: uclnlp File: filter.py License: MIT License | 6 votes |
def main(argv): def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=100, width=200) argparser = argparse.ArgumentParser('Filtering tool for filtering away infrequent entities from Knowledge Graphs', formatter_class=formatter) argparser.add_argument('triples', type=str, help='File containing triples') argparser.add_argument('entities', type=str, help='File containing entities') args = argparser.parse_args(argv) triples_path = args.triples entities_path = args.entities triples = read_triples(triples_path) with iopen(entities_path, mode='r') as f: entities = set([line.strip() for line in f.readlines()]) for (s, p, o) in triples: if s in entities and o in entities: print("%s\t%s\t%s" % (s, p, o))
Example 4
Project: inferbeddings Author: uclnlp File: filter.py License: MIT License | 6 votes |
def main(argv): def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=100, width=200) argparser = argparse.ArgumentParser('Filtering tool for filtering away infrequent entities from Knowledge Graphs', formatter_class=formatter) argparser.add_argument('triples', type=str, help='File containing triples') argparser.add_argument('entities', type=str, help='File containing entities') args = argparser.parse_args(argv) triples_path = args.triples entities_path = args.entities triples = read_triples(triples_path) with iopen(entities_path, mode='r') as f: entities = set([line.strip() for line in f.readlines()]) for (s, p, o) in triples: if s in entities and o in entities: print("%s\t%s\t%s" % (s, p, o))
Example 5
Project: inferbeddings Author: uclnlp File: filter.py License: MIT License | 6 votes |
def main(argv): def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=100, width=200) argparser = argparse.ArgumentParser('Filtering tool for filtering away infrequent entities from Knowledge Graphs', formatter_class=formatter) argparser.add_argument('triples', type=str, help='File containing triples') argparser.add_argument('entities', type=str, help='File containing entities') args = argparser.parse_args(argv) triples_path = args.triples entities_path = args.entities triples = read_triples(triples_path) with iopen(entities_path, mode='r') as f: entities = set([line.strip() for line in f.readlines()]) for (s, p, o) in triples: if s in entities and o in entities: print("%s\t%s\t%s" % (s, p, o))
Example 6
Project: inferbeddings Author: uclnlp File: filter.py License: MIT License | 6 votes |
def main(argv): def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=100, width=200) argparser = argparse.ArgumentParser('Filtering tool for filtering away infrequent entities from Knowledge Graphs', formatter_class=formatter) argparser.add_argument('triples', type=str, help='File containing triples') argparser.add_argument('entities', type=str, help='File containing entities') args = argparser.parse_args(argv) triples_path = args.triples entities_path = args.entities triples = read_triples(triples_path) with iopen(entities_path, mode='r') as f: entities = set([line.strip() for line in f.readlines()]) for (s, p, o) in triples: if s in entities and o in entities: print("%s\t%s\t%s" % (s, p, o))
Example 7
Project: eclcli Author: nttcom File: shell.py License: Apache License 2.0 | 6 votes |
def _find_actions(self, subparsers, actions_module): for attr in (a for a in dir(actions_module) if a.startswith('do_')): # I prefer to be hypen-separated instead of underscores. command = attr[3:].replace('_', '-') callback = getattr(actions_module, attr) desc = callback.__doc__ or '' help = desc.strip().split('\n')[0] arguments = getattr(callback, 'arguments', []) subparser = subparsers.add_parser(command, help=help, description=desc, add_help=False, formatter_class=HelpFormatter) subparser.add_argument('-h', '--help', action='help', help=argparse.SUPPRESS) self.subcommands[command] = subparser for (args, kwargs) in arguments: subparser.add_argument(*args, **kwargs) subparser.set_defaults(func=callback)
Example 8
Project: eclcli Author: nttcom File: shell.py License: Apache License 2.0 | 6 votes |
def _find_actions(self, subparsers, actions_module): for attr in (a for a in dir(actions_module) if a.startswith('do_')): # I prefer to be hyphen-separated instead of underscores. command = attr[3:].replace('_', '-') callback = getattr(actions_module, attr) desc = callback.__doc__ or '' help = desc.strip().split('\n')[0] arguments = getattr(callback, 'arguments', []) subparser = subparsers.add_parser(command, help=help, description=desc, add_help=False, formatter_class=HelpFormatter) subparser.add_argument('-h', '--help', action='help', help=argparse.SUPPRESS) self.subcommands[command] = subparser for (args, kwargs) in arguments: subparser.add_argument(*args, **kwargs) subparser.set_defaults(func=callback)
Example 9
Project: freepacktbook Author: bogdal File: __init__.py License: MIT License | 6 votes |
def download_parser(description): class SortedHelpFormatter(HelpFormatter): def add_arguments(self, actions): actions = sorted(actions, key=attrgetter("option_strings")) super(SortedHelpFormatter, self).add_arguments(actions) parser = ArgumentParser( description=description, formatter_class=SortedHelpFormatter ) parser.add_argument("--force", action="store_true", help="override existing files") parser.add_argument( "--formats", nargs="+", metavar="FORMAT", help="ebook formats (epub, mobi, pdf)" ) parser.add_argument( "--with-code-files", action="store_true", help="download code files" ) return parser
Example 10
Project: BLINK Author: facebookresearch File: params.py License: MIT License | 6 votes |
def __init__( self, add_blink_args=True, add_model_args=False, description='BLINK parser', ): super().__init__( description=description, allow_abbrev=False, conflict_handler='resolve', formatter_class=argparse.HelpFormatter, add_help=add_blink_args, ) self.blink_home = os.path.dirname( os.path.dirname(os.path.dirname(os.path.realpath(__file__))) ) os.environ['BLINK_HOME'] = self.blink_home self.add_arg = self.add_argument self.overridable = {} if add_blink_args: self.add_blink_args() if add_model_args: self.add_model_args()
Example 11
Project: spinalcordtoolbox Author: neuropoly File: utils.py License: MIT License | 6 votes |
def _split_lines(self, text, width): if text.startswith('R|'): lines = text[2:].splitlines() offsets = [re.match("^[ \t]*", l).group(0) for l in lines] wrapped = [] for i in range(len(lines)): li = lines[i] o = offsets[i] ol = len(o) init_wrap = argparse._textwrap.fill(li, width).splitlines() first = init_wrap[0] rest = "\n".join(init_wrap[1:]) rest_wrap = argparse._textwrap.fill(rest, width - ol).splitlines() offset_lines = [o + wl for wl in rest_wrap] wrapped = wrapped + [first] + offset_lines return wrapped return argparse.HelpFormatter._split_lines(self, text, width)
Example 12
Project: lbry-sdk Author: lbryio File: cli.py License: MIT License | 6 votes |
def __init__(self, *args, group_name=None, **kwargs): super().__init__(*args, formatter_class=HelpFormatter, add_help=False, **kwargs) self.add_argument( '--help', dest='help', action='store_true', default=False, help='Show this help message and exit.' ) self._optionals.title = 'Options' if group_name is None: self.epilog = ( f"Run 'lbrynet COMMAND --help' for more information on a command or group." ) else: self.epilog = ( f"Run 'lbrynet {group_name} COMMAND --help' for more information on a command." ) self.set_defaults(group=group_name, group_parser=self)
Example 13
Project: CVE-2017-1000486 Author: pimps File: primefaces.py License: GNU General Public License v3.0 | 6 votes |
def get_args(): parser = argparse.ArgumentParser( prog="primefaces.py", formatter_class=lambda prog: argparse.HelpFormatter(prog,max_help_position=50), epilog= ''' This script exploits an expression language remote code execution flaw in the Primefaces JSF framework. Primefaces versions prior to 5.2.21, 5.3.8 or 6.0 are vulnerable to a padding oracle attack, due to the use of weak crypto and default encryption password and salt. ''') parser.add_argument("target", help="Target Host") parser.add_argument("-pw", "--password", default="primefaces", help="Primefaces Password (Default = primefaces") parser.add_argument("-pt", "--path", default="/javax.faces.resource/dynamiccontent.properties.xhtml", help="Path to dynamiccontent.properties (Default = /javax.faces.resource/dynamiccontent.properties.xhtml)") parser.add_argument("-c", "--cmd", default="whoami", help="Command to execute. (Default = whoami)") parser.add_argument("-px", "--proxy", default="", help="Configure a proxy in the format http://127.0.0.1:8080/ (Default = None)") parser.add_argument("-ck", "--cookie", default="", help="Configure a cookie in the format 'COOKIE=VALUE; COOKIE2=VALUE2;' (Default = None)") parser.add_argument("-o", "--oracle", default="0", help="Exploit the target with Padding Oracle. Use 1 to activate. (Default = 0) (SLOW)") parser.add_argument("-pl", "--payload", default="", help="EL Encrypted payload. That function is meant to be used with the Padding Oracle generated payload. (Default = None) ") args = parser.parse_args() return args
Example 14
Project: faceswap Author: deepfakes File: args.py License: GNU General Public License v3.0 | 6 votes |
def _split_lines(self, text, width): """ Split the given text by the given display width. If the text is not prefixed with "R|" then the standard :func:`argparse.HelpFormatter._split_lines` function is used, otherwise raw formatting is processed, Parameters ---------- text: str The help text that is to be formatted for display width: int The display width, in characters, for the help text """ if text.startswith("R|"): text = self._whitespace_matcher_limited.sub(' ', text).strip()[2:] output = list() for txt in text.splitlines(): indent = "" if txt.startswith("L|"): indent = " " txt = " - {}".format(txt[2:]) output.extend(textwrap.wrap(txt, width, subsequent_indent=indent)) return output return argparse.HelpFormatter._split_lines(self, text, width)
Example 15
Project: telegram-messages-dump Author: Kosat File: chat_dump_settings.py License: MIT License | 5 votes |
def __init__(self, prog=''): argparse.HelpFormatter.__init__( self, prog, max_help_position=100, width=150)
Example 16
Project: python-netsurv Author: sofia-netsurv File: argparsing.py License: MIT License | 5 votes |
def _format_action_invocation(self, action): orgstr = argparse.HelpFormatter._format_action_invocation(self, action) if orgstr and orgstr[0] != "-": # only optional arguments return orgstr res = getattr(action, "_formatted_action_invocation", None) if res: return res options = orgstr.split(", ") if len(options) == 2 and (len(options[0]) == 2 or len(options[1]) == 2): # a shortcut for '-h, --help' or '--abc', '-a' action._formatted_action_invocation = orgstr return orgstr return_list = [] option_map = getattr(action, "map_long_option", {}) if option_map is None: option_map = {} short_long = {} for option in options: if len(option) == 2 or option[2] == " ": continue if not option.startswith("--"): raise ArgumentError( 'long optional argument without "--": [%s]' % (option), self ) xxoption = option[2:] if xxoption.split()[0] not in option_map: shortened = xxoption.replace("-", "") if shortened not in short_long or len(short_long[shortened]) < len( xxoption ): short_long[shortened] = xxoption # now short_long has been filled out to the longest with dashes # **and** we keep the right option ordering from add_argument for option in options: if len(option) == 2 or option[2] == " ": return_list.append(option) if option[2:] == short_long.get(option.replace("-", "")): return_list.append(option.replace(" ", "=", 1)) action._formatted_action_invocation = ", ".join(return_list) return action._formatted_action_invocation
Example 17
Project: python-netsurv Author: sofia-netsurv File: argparsing.py License: MIT License | 5 votes |
def _format_action_invocation(self, action): orgstr = argparse.HelpFormatter._format_action_invocation(self, action) if orgstr and orgstr[0] != "-": # only optional arguments return orgstr res = getattr(action, "_formatted_action_invocation", None) if res: return res options = orgstr.split(", ") if len(options) == 2 and (len(options[0]) == 2 or len(options[1]) == 2): # a shortcut for '-h, --help' or '--abc', '-a' action._formatted_action_invocation = orgstr return orgstr return_list = [] option_map = getattr(action, "map_long_option", {}) if option_map is None: option_map = {} short_long = {} for option in options: if len(option) == 2 or option[2] == " ": continue if not option.startswith("--"): raise ArgumentError( 'long optional argument without "--": [%s]' % (option), self ) xxoption = option[2:] if xxoption.split()[0] not in option_map: shortened = xxoption.replace("-", "") if shortened not in short_long or len(short_long[shortened]) < len( xxoption ): short_long[shortened] = xxoption # now short_long has been filled out to the longest with dashes # **and** we keep the right option ordering from add_argument for option in options: if len(option) == 2 or option[2] == " ": return_list.append(option) if option[2:] == short_long.get(option.replace("-", "")): return_list.append(option.replace(" ", "=", 1)) action._formatted_action_invocation = ", ".join(return_list) return action._formatted_action_invocation
Example 18
Project: ironpython2 Author: IronLanguages File: test_argparse.py License: Apache License 2.0 | 5 votes |
def test_parser(self): parser = argparse.ArgumentParser(prog='PROG') string = ( "ArgumentParser(prog='PROG', usage=None, description=None, " "version=None, formatter_class=%r, conflict_handler='error', " "add_help=True)" % argparse.HelpFormatter) self.assertStringEqual(parser, string) # =============== # Namespace tests # ===============
Example 19
Project: ask-jira Author: mrts File: smart_argparse_formatter.py License: MIT License | 5 votes |
def _split_lines(self, text, width): if text.startswith('R|'): return text[2:].splitlines() return argparse.HelpFormatter._split_lines(self, text, width)
Example 20
Project: phpsploit Author: nil0x42 File: plugin_args.py License: GNU General Public License v3.0 | 5 votes |
def help_format_network_scan(prog): kwargs = dict() kwargs['width'] = ui.output.columns() kwargs['max_help_position'] = 34 format = argparse.HelpFormatter(prog, **kwargs) return (format)
Example 21
Project: atomic-reactor Author: containerbuildsystem File: main.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, formatter_class=argparse.HelpFormatter, prog=PROG): self.parser = argparse.ArgumentParser( prog=prog, description=DESCRIPTION, formatter_class=formatter_class, ) self.build_parser = None self.bi_parser = None self.ib_parser = None self.source_types_parsers = None locale.setlocale(locale.LC_ALL, '')
Example 22
Project: black-widow Author: offensive-hub File: input_arguments.py License: GNU General Public License v3.0 | 5 votes |
def __init__(self, prog, indent_increment=2, max_help_position=36, width=None): argparse.HelpFormatter.__init__(self, prog, indent_increment, max_help_position, width) # CamelCase prefix
Example 23
Project: black-widow Author: offensive-hub File: input_arguments.py License: GNU General Public License v3.0 | 5 votes |
def add_argument(self, action, depth=0): option_strings = [] for option_string in action.option_strings: option_strings.append((' ' * depth) + option_string) action.option_strings = option_strings argparse.HelpFormatter.add_argument(self, action) # Added depth
Example 24
Project: BinderFilter Author: dxwu File: test_argparse.py License: MIT License | 5 votes |
def test_parser(self): parser = argparse.ArgumentParser(prog='PROG') string = ( "ArgumentParser(prog='PROG', usage=None, description=None, " "version=None, formatter_class=%r, conflict_handler='error', " "add_help=True)" % argparse.HelpFormatter) self.assertStringEqual(parser, string) # =============== # Namespace tests # ===============
Example 25
Project: inferbeddings Author: uclnlp File: nli-client-cli.py License: MIT License | 5 votes |
def main(argv): def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=100, width=200) argparser = argparse.ArgumentParser('NLI Client', formatter_class=formatter) argparser.add_argument('path', action='store', type=str) argparser.add_argument('--url', '-u', action='store', type=str, default='http://127.0.0.1:8889/v1/nli') args = argparser.parse_args(argv) path = args.path url = args.url nb_predictions = 0.0 nb_matching_predictions = 0.0 with gzip.open(path, 'rb') as f: for line in f: decoded_line = line.decode('utf-8') obj = json.loads(decoded_line) gold_label = obj['gold_label'] sentence1 = obj['sentence1'] sentence2 = obj['sentence2'] sentence1_parse = obj['sentence1_parse'] sentence2_parse = obj['sentence2_parse'] if gold_label in ['contradiction', 'entailment', 'neutral']: prediction = call_service(url=url, sentence1=sentence1, sentence2=sentence2) predicted_label = max(prediction, key=prediction.get) nb_predictions += 1.0 nb_matching_predictions += 1.0 if gold_label == predicted_label else 0.0 print(nb_matching_predictions / nb_predictions)
Example 26
Project: inferbeddings Author: uclnlp File: inspect-checkpoint-cli.py License: MIT License | 5 votes |
def main(argv): def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=100, width=200) argparser = argparse.ArgumentParser('Checkpoint Inspector', formatter_class=formatter) argparser.add_argument('file_name', action='store', type=str) args = argparser.parse_args(argv) file_name = args.file_name print_tensors_in_checkpoint_file(file_name=file_name, tensor_name='', all_tensors=False)
Example 27
Project: inferbeddings Author: uclnlp File: make_folds.py License: MIT License | 5 votes |
def main(argv): def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=100, width=200) argparser = argparse.ArgumentParser('K-Folder for Knowledge Graphs', formatter_class=formatter) argparser.add_argument('triples', action='store', type=str, default=None) args = argparser.parse_args(argv) triples_path = args.triples triples = read_triples(triples_path) nb_triples = len(triples) kf = KFold(n=nb_triples, n_folds=10, random_state=0, shuffle=True) triples_np = np.array(triples) for fold_no, (train_idx, test_idx) in enumerate(kf): train_valid_triples = triples_np[train_idx] test_triples = triples_np[test_idx] train_triples, valid_triples, _, _ = train_test_split(train_valid_triples, np.ones(train_valid_triples.shape[0]), test_size=len(test_triples), random_state=0) train_lines = ['{}\t{}\t{}'.format(s, p, o) for [s, p, o] in train_triples] valid_lines = ['{}\t{}\t{}'.format(s, p, o) for [s, p, o] in valid_triples] test_lines = ['{}\t{}\t{}'.format(s, p, o) for [s, p, o] in test_triples] if not os.path.exists('folds/{}'.format(str(fold_no))): os.mkdir('folds/{}'.format(str(fold_no))) with open('folds/{}/nations_train.tsv'.format(str(fold_no)), 'w') as f: f.writelines(['{}\n'.format(line) for line in train_lines]) with open('folds/{}/nations_valid.tsv'.format(str(fold_no)), 'w') as f: f.writelines(['{}\n'.format(line) for line in valid_lines]) with open('folds/{}/nations_test.tsv'.format(str(fold_no)), 'w') as f: f.writelines(['{}\n'.format(line) for line in test_lines])
Example 28
Project: inferbeddings Author: uclnlp File: make_folds.py License: MIT License | 5 votes |
def main(argv): def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=100, width=200) argparser = argparse.ArgumentParser('K-Folder for Knowledge Graphs', formatter_class=formatter) argparser.add_argument('triples', action='store', type=str, default=None) args = argparser.parse_args(argv) triples_path = args.triples triples = read_triples(triples_path) nb_triples = len(triples) kf = KFold(n=nb_triples, n_folds=10, random_state=0, shuffle=True) triples_np = np.array(triples) for fold_no, (train_idx, test_idx) in enumerate(kf): train_valid_triples = triples_np[train_idx] test_triples = triples_np[test_idx] train_triples, valid_triples, _, _ = train_test_split(train_valid_triples, np.ones(train_valid_triples.shape[0]), test_size=len(test_triples), random_state=0) train_lines = ['{}\t{}\t{}'.format(s, p, o) for [s, p, o] in train_triples] valid_lines = ['{}\t{}\t{}'.format(s, p, o) for [s, p, o] in valid_triples] test_lines = ['{}\t{}\t{}'.format(s, p, o) for [s, p, o] in test_triples] if not os.path.exists('folds/{}'.format(str(fold_no))): os.mkdir('folds/{}'.format(str(fold_no))) with open('folds/{}/nations_train.tsv'.format(str(fold_no)), 'w') as f: f.writelines(['{}\n'.format(line) for line in train_lines]) with open('folds/{}/nations_valid.tsv'.format(str(fold_no)), 'w') as f: f.writelines(['{}\n'.format(line) for line in valid_lines]) with open('folds/{}/nations_test.tsv'.format(str(fold_no)), 'w') as f: f.writelines(['{}\n'.format(line) for line in test_lines])
Example 29
Project: inferbeddings Author: uclnlp File: make_folds.py License: MIT License | 5 votes |
def main(argv): def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=100, width=200) argparser = argparse.ArgumentParser('K-Folder for Knowledge Graphs', formatter_class=formatter) argparser.add_argument('triples', action='store', type=str, default=None) args = argparser.parse_args(argv) triples_path = args.triples triples = read_triples(triples_path) nb_triples = len(triples) kf = KFold(n=nb_triples, n_folds=10, random_state=0, shuffle=True) triples_np = np.array(triples) for fold_no, (train_idx, test_idx) in enumerate(kf): train_valid_triples = triples_np[train_idx] test_triples = triples_np[test_idx] train_triples, valid_triples, _, _ = train_test_split(train_valid_triples, np.ones(train_valid_triples.shape[0]), test_size=len(test_triples), random_state=0) train_lines = ['{}\t{}\t{}'.format(s, p, o) for [s, p, o] in train_triples] valid_lines = ['{}\t{}\t{}'.format(s, p, o) for [s, p, o] in valid_triples] test_lines = ['{}\t{}\t{}'.format(s, p, o) for [s, p, o] in test_triples] if not os.path.exists('folds/{}'.format(str(fold_no))): os.mkdir('folds/{}'.format(str(fold_no))) with open('folds/{}/umls_train.tsv'.format(str(fold_no)), 'w') as f: f.writelines(['{}\n'.format(line) for line in train_lines]) with open('folds/{}/umls_valid.tsv'.format(str(fold_no)), 'w') as f: f.writelines(['{}\n'.format(line) for line in valid_lines]) with open('folds/{}/umls_test.tsv'.format(str(fold_no)), 'w') as f: f.writelines(['{}\n'.format(line) for line in test_lines])
Example 30
Project: inferbeddings Author: uclnlp File: evaluate-nli-service.py License: MIT License | 5 votes |
def main(argv): def formatter(prog): return argparse.HelpFormatter(prog, max_help_position=100, width=200) argparser = argparse.ArgumentParser('NLI Service', formatter_class=formatter) argparser.add_argument('--path', '-p', action='store', type=str, default='data/snli/snli_1.0_dev.jsonl.gz') args = argparser.parse_args(argv) path = args.path logger.debug('Reading corpus ..') instances, _, _ = SNLI.generate(train_path=path, valid_path=None, test_path=None) session = requests.Session() total, matches = 0, 0 progress_bar = tqdm(instances) for instance in progress_bar: question, support, answer = instance['question'], instance['support'], instance['answer'] res = session.post('http://127.0.0.1:8889/v1/nli', data={'sentence1': question, 'sentence2': support}) prediction = sorted(res.json().items(), key=operator.itemgetter(1), reverse=True)[0][0] total += 1 matches += 1 if answer == prediction else 0 progress_bar.set_description('Accuracy: {:.2f}'.format(matches / total))