Beispiel #1
0
    def wake_generative_with_pyccg(self,
                    grammar, tasks, 
                    maximumFrontier=None,
                    enumerationTimeout=None,
                    CPUs=None,
                    solver=None,
                    evaluationTimeout=None):
        """
        Dreamcoder wake_generative using PYCCG enumeration to guide exploration.

        Enumerates from PyCCG with a timeout and blindly from the EC grammar.
        Updates PyCCG using both sets of discovered meanings.
        Converts the meanings into EC-style frontiers to be handed off to EC.
        """
        # Enumerate PyCCG meanings and update the word learner.
        pyccg_meanings = {t : [] for t in tasks}
        if self.use_pyccg_enum:
            pyccg_meanings = self._update_pyccg_with_distant_batch(tasks, enumerationTimeout)
       
        # Enumerate the remaining tasks using EC-style blind enumeration.
        unsolved_tasks = [task for task in tasks if len(pyccg_meanings[task]) == 0]
        fallback_frontiers, fallback_times = [], None
        if self.use_blind_enum:
            fallback_frontiers, fallback_times = multicoreEnumeration(grammar, unsolved_tasks, 
                                                       maximumFrontier=maximumFrontier,
                                                       enumerationTimeout=enumerationTimeout,
                                                       CPUs=CPUs,
                                                       solver=solver,
                                                       evaluationTimeout=evaluationTimeout)

        # Log enumeration results.
        print("PyCCG model parsing results")
        self._describe_pyccg_results(pyccg_meanings)
        print("Non-language generative model enumeration results:")
        print(Frontier.describe(fallback_frontiers))

        # Update PyCCG model with fallback discovered frontiers.
        self._update_pyccg_with_supervised_batch(fallback_frontiers) # TODO(catwong, jgauthier): does not yet update.

        # Convert and consolidate PyCCG meanings and fallback frontiers for handoff to EC.
        pyccg_frontiers = self._pyccg_meanings_to_ec_frontiers(pyccg_meanings)
        fallback_frontiers = {frontier.task : frontier for frontier in fallback_frontiers}
        all_frontiers = {t : pyccg_frontiers[t] if t in pyccg_frontiers else fallback_frontiers[t] for t in tasks}
        all_times = {t : enumerationTimeout if t in pyccg_frontiers else fallback_times[t] for t in tasks}

        return list(all_frontiers.values()), all_times