def __init__(self, opts): super().__init__() self.opts = opts self.tactic_decoder = TacticDecoder( CFG(opts.tac_grammar, 'tactic_expr'), opts) self.term_encoder = TermEncoder(opts) self.tactic_embedding = Embedding(opts.num_tactics, 256, padding_idx=0) self.tactic_LSTM = LSTM(256, 256, 1, batch_first=True, bidirectional=True) self.tac_vocab = pickle.load(open(opts.tac_vocab_file, 'rb')) self.cutoff_len = opts.cutoff_len
import pdb term_parser = GallinaTermParser(caching=True) sexp_cache = SexpCache('../sexp_cache', readonly=True) def parse_goal(g): goal = {'id': g['id'], 'text': g['type'], 'ast': term_parser.parse(sexp_cache[g['sexp']])} local_context = [] for i, h in enumerate(g['hypotheses']): for ident in h['idents']: local_context.append({'ident': ident, 'text': h['type'], 'ast': term_parser.parse(sexp_cache[h['sexp']])}) return local_context, goal grammar = CFG('tactics.ebnf', 'tactic_expr') tree_builder = TreeBuilder(grammar) def tactic2actions(tac_str): tree = tree_builder.transform(grammar.parser.parse(tac_str)) assert tac_str.replace(' ', '') == tree.to_tokens().replace(' ', '') actions = [] def gather_actions(node): if isinstance(node, NonterminalNode): actions.append(grammar.production_rules.index(node.action)) else: assert isinstance(node, TerminalNode) actions.append(node.token) tree.traverse_pre(gather_actions) return actions
def __init__(self, opts): super().__init__() self.opts = opts self.tactic_decoder = TacticDecoder( CFG(opts.tac_grammar, 'tactic_expr'), opts) self.term_encoder = TermEncoder(opts)
import common import numpy as np from utils import iter_proofs from lark.exceptions import UnexpectedCharacters, ParseError from tac_grammar import CFG, TreeBuilder, NonterminalNode, TerminalNode import pdb grammar = CFG(common.tac_grammar, 'tactic_expr') tree_builder = TreeBuilder(grammar) ast_height = [] num_tokens = [] num_chars = [] has_argument = [] def process_proof(filename, proof_data): global ast_height global num_tokens global num_chars for step in proof_data['steps']: if step['command'][1] != 'VernacExtend': continue if not step['command'][0].endswith('.'): continue tac_str = step['command'][0][:-1] try: tree = tree_builder.transform(grammar.parser.parse(tac_str)) except (UnexpectedCharacters, ParseError) as ex:
} local_context = [] for i, h in enumerate(g['hypotheses']): for ident in h['idents']: local_context.append({ 'ident': ident, 'text': h['type'], 'ast': term_parser.parse(sexp_cache[h['sexp']]) }) return local_context, goal grammar = CFG('tactics.ebnf', 'tactic_expr') # update CFG tree_builder = TreeBuilder(grammar) def tactic2actions(tac_str): tree = tree_builder.transform(grammar.parser.parse(tac_str)) assert tac_str.replace(' ', '') == tree.to_tokens().replace(' ', '') actions = [] def gather_actions(node): if isinstance(node, NonterminalNode): actions.append(grammar.production_rules.index(node.action)) else: assert isinstance(node, TerminalNode) actions.append(node.token)
} local_context = [] for i, h in enumerate(g["hypotheses"]): for ident in h["idents"]: local_context.append({ "ident": ident, "text": h["type"], "ast": term_parser.parse(sexp_cache[h["sexp"]]), }) return local_context, goal grammar = CFG("tactics.ebnf", "tactic_expr") tree_builder = TreeBuilder(grammar) def tactic2actions(tac_str): tree = tree_builder.transform(grammar.parser.parse(tac_str)) assert tac_str.replace(" ", "") == tree.to_tokens().replace(" ", "") actions = [] def gather_actions(node): if isinstance(node, NonterminalNode): actions.append(grammar.production_rules.index(node.action)) else: assert isinstance(node, TerminalNode) actions.append(node.token)
import common import numpy as np from utils import iter_proofs from lark.exceptions import UnexpectedCharacters, ParseError from tac_grammar import CFG, TreeBuilder, NonterminalNode, TerminalNode import pdb grammar = CFG(common.tac_grammar, "tactic_expr") tree_builder = TreeBuilder(grammar) ast_height = [] num_tokens = [] num_chars = [] has_argument = [] def process_proof(filename, proof_data): global ast_height global num_tokens global num_chars for step in proof_data["steps"]: if step["command"][1] != "VernacExtend": continue if not step["command"][0].endswith("."): continue tac_str = step["command"][0][:-1] try: tree = tree_builder.transform(grammar.parser.parse(tac_str)) except (UnexpectedCharacters, ParseError) as ex: