當前位置: 首頁>>代碼示例>>Python>>正文


Python Vocabulary.from_files方法代碼示例

本文整理匯總了Python中allennlp.data.Vocabulary.from_files方法的典型用法代碼示例。如果您正苦於以下問題:Python Vocabulary.from_files方法的具體用法?Python Vocabulary.from_files怎麽用?Python Vocabulary.from_files使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在allennlp.data.Vocabulary的用法示例。


在下文中一共展示了Vocabulary.from_files方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from allennlp.data import Vocabulary [as 別名]
# 或者: from allennlp.data.Vocabulary import from_files [as 別名]
def __init__(
        self,
        config: Config,
        models: Dict[str, Type[nn.Module]],
        gpu_ids: List[int] = [0],
        cpu_workers: int = 0,
    ):
        self._C = config

        if self._C.PHASE != "program_prior":
            raise ValueError(
                f"Trying to initialize a ProgramPriorEvaluator, expected config PHASE to be "
                f"program_prior, found {self._C.PHASE}"
            )

        # Initialize vocabulary, dataloader and model.
        self._vocabulary = Vocabulary.from_files(self._C.DATA.VOCABULARY)

        dataset = ProgramPriorDataset(self._C.DATA.VAL_TOKENS)
        dataloader = DataLoader(dataset, batch_size=self._C.OPTIM.BATCH_SIZE)

        super().__init__(config=config, dataloader=dataloader, models=models, gpu_ids=gpu_ids)

        # This will be a part of `self._models`, keep this handle for convenience.
        self._program_prior = self._models["program_prior"] 
開發者ID:kdexd,項目名稱:probnmn-clevr,代碼行數:27,代碼來源:program_prior_evaluator.py

示例2: _load

# 需要導入模塊: from allennlp.data import Vocabulary [as 別名]
# 或者: from allennlp.data.Vocabulary import from_files [as 別名]
def _load(cls,
              config        ,
              serialization_dir     ,
              weights_file      = None,
              cuda_device      = -1)           :
        u"""
        Instantiates an already-trained model, based on the experiment
        configuration and some optional overrides.
        """
        weights_file = weights_file or os.path.join(serialization_dir, _DEFAULT_WEIGHTS)

        # Load vocabulary from file
        vocab_dir = os.path.join(serialization_dir, u'vocabulary')
        vocab = Vocabulary.from_files(vocab_dir)

        model_params = config.get(u'model')

        # The experiment config tells us how to _train_ a model, including where to get pre-trained
        # embeddings from.  We're now _loading_ the model, so those embeddings will already be
        # stored in our weights.  We don't need any pretrained weight file anymore, and we don't
        # want the code to look for it, so we remove it from the parameters here.
        remove_pretrained_embedding_params(model_params)
        model = Model.from_params(vocab=vocab, params=model_params)
        model_state = torch.load(weights_file, map_location=util.device_mapping(cuda_device))
        model.load_state_dict(model_state)

        # Force model to cpu or gpu, as appropriate, to make sure that the embeddings are
        # in sync with the weights
        if cuda_device >= 0:
            model.cuda(cuda_device)
        else:
            model.cpu()

        return model 
開發者ID:plasticityai,項目名稱:magnitude,代碼行數:36,代碼來源:model.py

示例3: from_config

# 需要導入模塊: from allennlp.data import Vocabulary [as 別名]
# 或者: from allennlp.data.Vocabulary import from_files [as 別名]
def from_config(cls, config: Config):
        r"""Instantiate this class directly from a :class:`~probnmn.config.Config`."""

        _C = config
        return cls(
            vocabulary=Vocabulary.from_files(_C.DATA.VOCABULARY),
            input_size=_C.QUESTION_RECONSTRUCTOR.INPUT_SIZE,
            hidden_size=_C.QUESTION_RECONSTRUCTOR.HIDDEN_SIZE,
            num_layers=_C.QUESTION_RECONSTRUCTOR.NUM_LAYERS,
            dropout=_C.QUESTION_RECONSTRUCTOR.DROPOUT,
        ) 
開發者ID:kdexd,項目名稱:probnmn-clevr,代碼行數:13,代碼來源:question_reconstructor.py

示例4: from_config

# 需要導入模塊: from allennlp.data import Vocabulary [as 別名]
# 或者: from allennlp.data.Vocabulary import from_files [as 別名]
def from_config(cls, config: Config):
        r"""Instantiate this class directly from a :class:`~probnmn.config.Config`."""

        _C = config
        return cls(
            vocabulary=Vocabulary.from_files(_C.DATA.VOCABULARY),
            input_size=_C.PROGRAM_GENERATOR.INPUT_SIZE,
            hidden_size=_C.PROGRAM_GENERATOR.HIDDEN_SIZE,
            num_layers=_C.PROGRAM_GENERATOR.NUM_LAYERS,
            dropout=_C.PROGRAM_GENERATOR.DROPOUT,
        ) 
開發者ID:kdexd,項目名稱:probnmn-clevr,代碼行數:13,代碼來源:program_generator.py

示例5: from_config

# 需要導入模塊: from allennlp.data import Vocabulary [as 別名]
# 或者: from allennlp.data.Vocabulary import from_files [as 別名]
def from_config(cls, config: Config):
        r"""Instantiate this class directly from a :class:`~probnmn.config.Config`."""

        _C = config
        return cls(  # type: ignore
            vocabulary=Vocabulary.from_files(_C.DATA.VOCABULARY),
            image_feature_size=tuple(_C.NMN.IMAGE_FEATURE_SIZE),
            module_channels=_C.NMN.MODULE_CHANNELS,
            class_projection_channels=_C.NMN.CLASS_PROJECTION_CHANNELS,
            classifier_linear_size=_C.NMN.CLASSIFIER_LINEAR_SIZE,
        ) 
開發者ID:kdexd,項目名稱:probnmn-clevr,代碼行數:13,代碼來源:nmn.py

示例6: from_config

# 需要導入模塊: from allennlp.data import Vocabulary [as 別名]
# 或者: from allennlp.data.Vocabulary import from_files [as 別名]
def from_config(cls, config: Config):
        r"""Instantiate this class directly from a :class:`~probnmn.config.Config`."""

        _C = config
        return cls(
            vocabulary=Vocabulary.from_files(_C.DATA.VOCABULARY),
            input_size=_C.PROGRAM_PRIOR.INPUT_SIZE,
            hidden_size=_C.PROGRAM_PRIOR.HIDDEN_SIZE,
            num_layers=_C.PROGRAM_PRIOR.NUM_LAYERS,
            dropout=_C.PROGRAM_PRIOR.DROPOUT,
        ) 
開發者ID:kdexd,項目名稱:probnmn-clevr,代碼行數:13,代碼來源:program_prior.py

示例7: __init__

# 需要導入模塊: from allennlp.data import Vocabulary [as 別名]
# 或者: from allennlp.data.Vocabulary import from_files [as 別名]
def __init__(
        self,
        config: Config,
        models: Dict[str, Type[nn.Module]],
        gpu_ids: List[int] = [0],
        cpu_workers: int = 0,
    ):
        self._C = config

        if self._C.PHASE != "joint_training":
            raise ValueError(
                f"Trying to initialize a JointTrainingEvaluator, expected config PHASE to be "
                f"joint_training, found {self._C.PHASE}"
            )

        # Initialize vocabulary, dataloader and model.
        self._vocabulary = Vocabulary.from_files(self._C.DATA.VOCABULARY)

        # There is no notion of "supervision" during evaluation.
        dataset = JointTrainingDataset(self._C.DATA.VAL_TOKENS, self._C.DATA.VAL_FEATURES)
        dataloader = DataLoader(
            dataset, batch_size=self._C.OPTIM.BATCH_SIZE, num_workers=cpu_workers
        )

        super().__init__(config=config, dataloader=dataloader, models=models, gpu_ids=gpu_ids)

        # These will be a part of `self._models`, keep these handles for convenience.
        self._program_generator = self._models["program_generator"]
        self._nmn = self._models["nmn"] 
開發者ID:kdexd,項目名稱:probnmn-clevr,代碼行數:31,代碼來源:joint_training_evaluator.py


注:本文中的allennlp.data.Vocabulary.from_files方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。