def load(self, *args, **kwargs): """reads the slotfilling info from RASA-styled dataset""" domain_path = Path(self.load_path, MD_YAML_DialogsDatasetReader.DOMAIN_FNAME) nlu_path = Path(self.load_path, MD_YAML_DialogsDatasetReader.NLU_FNAME) domain_knowledge = DomainKnowledge(read_yaml(domain_path)) # todo: rewrite MD_YAML_DialogsDatasetReader so that public methods are enough _, slot_name2text2value = MD_YAML_DialogsDatasetReader._read_intent2text_mapping(nlu_path, domain_knowledge) self._slot_vals = slot_name2text2value
def __init__(self, gobot_config_path): gobot_config = read_json(f"{gobot_config_path}/gobot_config.json") domain_yml_path = "dp_minimal_demo_dir/domain.yml" self.response_templates = read_yaml(domain_yml_path)["responses"] self.gobot = build_model(gobot_config) self.DATABASE, self.PREV_UPDATE_TIME = self._update_database()
def from_yaml(cls, domain_yml_fpath: Union[str, Path] = "domain.yml"): """ Parses domain.yml domain config file into the DomainKnowledge object Args: domain_yml_fpath: path to the domain config file, defaults to domain.yml Returns: the loaded DomainKnowledge obect """ return cls(read_yaml(domain_yml_fpath))
def read(cls, data_path: str, dialogs: bool = False) -> Dict[str, List]: """ Parameters: data_path: path to read dataset from dialogs: flag which indicates whether to output list of turns or list of dialogs Returns: dictionary that contains ``'train'`` field with dialogs from ``'stories-trn.md'``, ``'valid'`` field with dialogs from ``'stories-val.md'`` and ``'test'`` field with dialogs from ``'stories-tst.md'``. Each field is a list of tuples ``(x_i, y_i)``. """ domain_fname = "domain.yml" nlu_fname = "nlu.md" stories_fnames = tuple( cls._data_fname(dt) for dt in cls.VALID_DATATYPES) required_fnames = stories_fnames + (nlu_fname, domain_fname) for required_fname in required_fnames: required_path = Path(data_path, required_fname) if not required_path.exists(): log.error( f"INSIDE MLU_MD_DialogsDatasetReader.read(): " f"{required_fname} not found with path {required_path}") domain_knowledge = DomainKnowledge( read_yaml(Path(data_path, domain_fname))) intent2slots2text, slot_name2text2value = cls._read_intent2text_mapping( Path(data_path, nlu_fname), domain_knowledge) short2long_subsample_name = { "trn": "train", "val": "valid", "tst": "test" } data = { short2long_subsample_name[subsample_name_short]: cls._read_story( Path(data_path, cls._data_fname(subsample_name_short)), dialogs, domain_knowledge, intent2slots2text, slot_name2text2value) for subsample_name_short in cls.VALID_DATATYPES } return data
def __init__(self, load_path: Union[str, Path], nemo_params_path: Union[str, Path], **kwargs) -> None: """Initializes NeuralModuleFactory on CPU or GPU and reads nemo modules params from yaml. Args: load_path: Path to a directory with pretrained checkpoints for NeMo modules. nemo_params_path: Path to a file containig NeMo modules params. """ super(NeMoBase, self).__init__(save_path=None, load_path=load_path, **kwargs) placement = nemo.core.DeviceType.GPU if torch.cuda.is_available( ) else nemo.core.DeviceType.CPU self.neural_factory = nemo.core.NeuralModuleFactory( placement=placement) self.modules_to_restore = [] self.nemo_params = read_yaml(expand_path(nemo_params_path))