Given a Java TrainValidationSplitModel, create and return a Python wrapper of it.
        Used for ML persistence.
332125
def _from_java(cls, java_stage):
        

        # Load information from java_stage to the instance.
        bestModel = JavaParams._from_java(java_stage.bestModel())
        estimator, epms, evaluator = super(TrainValidationSplitModel,
                                           cls)._from_java_impl(java_stage)
        # Create a new instance of this stage.
        py_stage = cls(bestModel=bestModel).setEstimator(estimator)
        py_stage = py_stage.setEstimatorParamMaps(epms).setEvaluator(evaluator)

        if java_stage.hasSubModels():
            py_stage.subModels = [JavaParams._from_java(sub_model)
                                  for sub_model in java_stage.subModels()]

        py_stage._resetUid(java_stage.uid())
        return py_stage
993455
def validate_wrap(self, value):
        ''' 
        '''
        if not isinstance(value, list) and not isinstance(value, tuple):
            self._fail_validation_type(value, tuple, list)

        for field, value in izip(self.types, list(value)):
            field.validate_wrap(value)
101228
def create(model_config, batch_size, normalize=True, num_workers=0, augmentations=None):
    
    path = model_config.data_dir('mnist')

    train_dataset = datasets.MNIST(path, train=True, download=True)
    test_dataset = datasets.MNIST(path, train=False, download=True)

    augmentations = [ToArray()] + (augmentations if augmentations is not None else [])

    if normalize:
        train_data = train_dataset.train_data
        mean_value = (train_data.double() / 255).mean().item()
        std_value = (train_data.double() / 255).std().item()

        augmentations.append(Normalize(mean=mean_value, std=std_value, tags=['train', 'val']))

    augmentations.append(ToTensor())

    return TrainingData(
        train_dataset,
        test_dataset,
        num_workers=num_workers,
        batch_size=batch_size,
        augmentations=augmentations
    )
721400
def to_model
      lm = low.try(:to_model)
      hm = high.try(:to_model)
      wm = width.try(:to_model)
      model_type = type
      if @entry.at_xpath('./cda:uncertainRange', HQMF2::Document::NAMESPACES)
        model_type = 'IVL_PQ'
      end

      if generate_any_value?(lm, hm)
        # Generate AnyValue if the only elements in the range are AnyValues.
        HQMF::AnyValue.new
      elsif generate_value?(lm, hm)
        # Generate a singel value if both low and high are the same
        HQMF::Value.new(lm.type, nil, lm.value, lm.inclusive?, lm.derived?, lm.expression)
      else
        HQMF::Range.new(model_type, lm, hm, wm)
      end
    end
1267132
public final POSModel train(final TrainingParameters params) {
    // features
    if (getPosTaggerFactory() == null) {
      throw new IllegalStateException(
          "Classes derived from AbstractTrainer must "
              + " create a POSTaggerFactory features!");
    }
    // training model
    POSModel trainedModel = null;
    POSEvaluator posEvaluator = null;
    try {
      trainedModel = POSTaggerME.train(this.lang, this.trainSamples, params,
          getPosTaggerFactory());
      final POSTaggerME posTagger = new POSTaggerME(trainedModel);
      posEvaluator = new POSEvaluator(posTagger);
      posEvaluator.evaluate(this.testSamples);
    } catch (final IOException e) {
      System.err.println("IO error while loading training and test sets!");
      e.printStackTrace();
      System.exit(1);
    }
    System.out.println("Final result: " + posEvaluator.getWordAccuracy());
    return trainedModel;
  }
1223000
def from_labels(cls, labels, inputCol, outputCol=None, handleInvalid=None):
        
        sc = SparkContext._active_spark_context
        java_class = sc._gateway.jvm.java.lang.String
        jlabels = StringIndexerModel._new_java_array(labels, java_class)
        model = StringIndexerModel._create_from_java_class(
            "org.apache.spark.ml.feature.StringIndexerModel", jlabels)
        model.setInputCol(inputCol)
        if outputCol is not None:
            model.setOutputCol(outputCol)
        if handleInvalid is not None:
            model.setHandleInvalid(handleInvalid)
        return model
603817
def work_model_factory(*, validator=validators.is_work_model, **kwargs):
    
    kwargs['ld_type'] = 'AbstractWork'
    return _model_factory(validator=validator, **kwargs)
1294746
def validate_callback_data(method):
    
    @wraps(method)
    def method_wrapper(*args, **kwargs):
        """

        Parameters
        ----------
        *args
        **kwargs

        Returns
        -------
        method's output
        """
        expected = method.__code__.co_varnames

        # rename curret gam object
        if 'self' in kwargs:
            gam = kwargs['self']
            del(kwargs['self'])
            kwargs['gam'] = gam

        # loop once to check any missing
        missing = []
        for e in expected:
            if e == 'self':
                continue
            if e not in kwargs:
                missing.append(e)
        assert len(missing) == 0, 'CallBack cannot reference: {}'.\
                                  format(', '.join(missing))

        # loop again to extract desired
        kwargs_subset = {}
        for e in expected:
            if e == 'self':
                continue
            kwargs_subset[e] = kwargs[e]

        return method(*args, **kwargs_subset)

    return method_wrapper
1129267
def validate(cls, mapper_spec):
    
    if mapper_spec.input_reader_class() != cls:
      raise BadReaderParamsError("Input reader class mismatch")
    params = _get_params(mapper_spec)
    if cls.BATCH_SIZE_PARAM in params:
      try:
        batch_size = int(params[cls.BATCH_SIZE_PARAM])
        if batch_size < 1:
          raise BadReaderParamsError("Bad batch size: %s" % batch_size)
      except ValueError, e:
        raise BadReaderParamsError("Bad batch size: %s" % e)
611988
private List<OpenEngSBModel> convertSimpleModelWrapperList(List<AdvancedModelWrapper> wrappers) {
        List<OpenEngSBModel> models = new ArrayList<OpenEngSBModel>();
        for (AdvancedModelWrapper wrapper : wrappers) {
            models.add(wrapper.getUnderlyingModel());
        }
        return models;
    }
823317
def validate(tool_class, model_class):
    
    if not hasattr(tool_class, 'name'):
        raise ImproperlyConfigured("No 'name' attribute found for tool %s." % (
            tool_class.__name__
        ))

    if not hasattr(tool_class, 'label'):
        raise ImproperlyConfigured("No 'label' attribute found for tool %s." % (
            tool_class.__name__
        ))

    if not hasattr(tool_class, 'view'):
        raise NotImplementedError("No 'view' method found for tool %s." % (
            tool_class.__name__
        ))
990376
private POSTaggerCrossValidator getPOSTaggerCrossValidator(
      final TrainingParameters params) {
    final File dictPath = new File(Flags.getDictionaryFeatures(params));
    // features
    if (this.posTaggerFactory == null) {
      throw new IllegalStateException(
          "You must create the POSTaggerFactory features!");
    }
    POSTaggerCrossValidator validator = null;
    if (dictPath.getName().equals(Flags.DEFAULT_DICT_PATH)) {
      if (this.dictCutOff == Flags.DEFAULT_DICT_CUTOFF) {
        validator = new POSTaggerCrossValidator(this.lang, params, null, null,
            null, this.posTaggerFactory.getClass().getName(),
            this.listeners
                .toArray(new POSTaggerEvaluationMonitor[this.listeners.size()]));
      } else {
        validator = new POSTaggerCrossValidator(this.lang, params, null, null,
            this.dictCutOff, this.posTaggerFactory.getClass().getName(),
            this.listeners
                .toArray(new POSTaggerEvaluationMonitor[this.listeners.size()]));
      }
    } else {
      if (this.dictCutOff == Flags.DEFAULT_DICT_CUTOFF) {
        validator = new POSTaggerCrossValidator(this.lang, params, dictPath,
            null, null, this.posTaggerFactory.getClass().getName(),
            this.listeners
                .toArray(new POSTaggerEvaluationMonitor[this.listeners.size()]));
      } else {
        validator = new POSTaggerCrossValidator(this.lang, params, dictPath,
            null, this.dictCutOff, this.posTaggerFactory.getClass().getName(),
            this.listeners
                .toArray(new POSTaggerEvaluationMonitor[this.listeners.size()]));
      }
    }
    return validator;
  }
119476
def create(alphabet_size: int, output_dim: int, pretrained: bool=False, frozen: bool=False, source: TextData=None):
    
    def instantiate(**_):
        return EmbeddingInput(alphabet_size, output_dim, pretrained=pretrained, frozen=frozen, source=source)

    return ModelFactory.generic(instantiate)
821958
function(server, model, options, logger) {
      // This line must come first
      validationHelper.validateModel(model, logger)
      const Log = logger.bind(chalk.yellow('Create'))

      let collectionName = model.collectionDisplayName || model.modelName
      if (config.logRoutes) {
        Log.note('Generating Create endpoint for ' + collectionName)
      }

      options = options || {}

      let resourceAliasForRoute

      if (model.routeOptions) {
        resourceAliasForRoute = model.routeOptions.alias || model.modelName
      } else {
        resourceAliasForRoute = model.modelName
      }

      let handler = HandlerHelper.generateCreateHandler(model, options, Log)

      let createModel = joiMongooseHelper.generateJoiCreateModel(model, Log)

      if (!config.enablePayloadValidation) {
        let label = createModel._flags.label
        createModel = Joi.alternatives()
          .try(createModel, Joi.any())
          .label(label)
      }

      // EXPL: support bulk creates
      createModel = Joi.alternatives().try(
        Joi.array().items(createModel),
        createModel
      )

      let readModel = joiMongooseHelper.generateJoiReadModel(model, Log)
      let label = readModel._flags.label

      readModel = Joi.alternatives()
        .try(Joi.array().items(readModel), readModel)
        .label(label)

      if (!config.enableResponseValidation) {
        readModel = Joi.alternatives()
          .try(readModel, Joi.any())
          .label(label)
      }

      let auth = false
      let createHeadersValidation = Object.assign(headersValidation, {})

      if (config.authStrategy && model.routeOptions.createAuth !== false) {
        auth = {
          strategy: config.authStrategy
        }

        let scope = authHelper.generateScopeForEndpoint(model, 'create', Log)

        if (!_.isEmpty(scope)) {
          auth.scope = scope
          if (config.logScopes) {
            Log.debug('Scope for POST/' + resourceAliasForRoute + ':', scope)
          }
        }
      } else {
        createHeadersValidation = null
      }

      let policies = []

      if (model.routeOptions.policies && config.enablePolicies) {
        policies = model.routeOptions.policies
        policies = (policies.rootPolicies || []).concat(
          policies.createPolicies || []
        )
      }

      if (config.enableDocumentScopes && auth) {
        let authorizeDocumentCreator =
          model.routeOptions.authorizeDocumentCreator === undefined
            ? config.authorizeDocumentCreator
            : model.routeOptions.authorizeDocumentCreator
        let authorizeDocumentCreatorToRead =
          model.routeOptions.authorizeDocumentCreatorToRead === undefined
            ? config.authorizeDocumentCreatorToRead
            : model.routeOptions.authorizeDocumentCreatorToRead
        let authorizeDocumentCreatorToUpdate =
          model.routeOptions.authorizeDocumentCreatorToUpdate === undefined
            ? config.authorizeDocumentCreatorToUpdate
            : model.routeOptions.authorizeDocumentCreatorToUpdate
        let authorizeDocumentCreatorToDelete =
          model.routeOptions.authorizeDocumentCreatorToDelete === undefined
            ? config.authorizeDocumentCreatorToDelete
            : model.routeOptions.authorizeDocumentCreatorToDelete
        let authorizeDocumentCreatorToAssociate =
          model.routeOptions.authorizeDocumentCreatorToAssociate === undefined
            ? config.authorizeDocumentCreatorToAssociate
            : model.routeOptions.authorizeDocumentCreatorToAssociate

        if (authorizeDocumentCreator) {
          policies.push(restHapiPolicies.authorizeDocumentCreator(model, Log))
        }
        if (authorizeDocumentCreatorToRead) {
          policies.push(
            restHapiPolicies.authorizeDocumentCreatorToRead(model, Log)
          )
        }
        if (authorizeDocumentCreatorToUpdate) {
          policies.push(
            restHapiPolicies.authorizeDocumentCreatorToUpdate(model, Log)
          )
        }
        if (authorizeDocumentCreatorToDelete) {
          policies.push(
            restHapiPolicies.authorizeDocumentCreatorToDelete(model, Log)
          )
        }
        if (authorizeDocumentCreatorToAssociate) {
          policies.push(
            restHapiPolicies.authorizeDocumentCreatorToAssociate(model, Log)
          )
        }

        if (model.routeOptions.documentScope) {
          policies.push(restHapiPolicies.addDocumentScope(model, Log))
        }
      }

      if (config.enableCreatedBy) {
        policies.push(restHapiPolicies.addCreatedBy(model, Log))
      }

      if (config.enableDuplicateFields) {
        policies.push(
          restHapiPolicies.populateDuplicateFields(model, mongoose, Log)
        )
      }

      if (config.enableAuditLog) {
        policies.push(restHapiPolicies.logCreate(mongoose, model, Log))
      }

      server.route({
        method: 'POST',
        path: '/' + resourceAliasForRoute,
        config: {
          handler: handler,
          auth: auth,
          cors: config.cors,
          description: 'Create one or more new ' + collectionName + 's',
          tags: ['api', collectionName],
          validate: {
            payload: createModel,
            headers: createHeadersValidation
          },
          plugins: {
            model: model,
            'hapi-swagger': {
              responseMessages: [
                {
                  code: 201,
                  message: 'The resource was created successfully.'
                },
                { code: 400, message: 'The request was malformed.' },
                {
                  code: 401,
                  message:
                    'The authentication header was missing/malformed, or the token has expired.'
                },
                { code: 500, message: 'There was an unknown error.' },
                {
                  code: 503,
                  message: 'There was a problem with the database.'
                }
              ]
            },
            policies: policies
          },
          response: {
            failAction: config.enableResponseFail ? 'error' : 'log',
            schema: readModel
          }
        }
      })
    }
462673
def from_python(self, value):
        
        if isinstance(value, model.RedisModel):
            value = value._pk
        elif isinstance(value, SimpleValueRelatedFieldMixin):
            value = value.proxy_get()
        return value
470338
def to_model
      mv = value.try(:to_model)
      met = effective_time.try(:to_model)
      mtr = temporal_references.collect(&:to_model)
      mso = subset_operators.collect(&:to_model)
      field_values = retrieve_field_values_model_for_model

      retrieve_title_and_description_for_model unless @variable || @derivation_operator

      @code_list_id = nil if @derivation_operator

      # prevent json model generation of empty children and comments
      cc = children_criteria.present? ? children_criteria : nil
      comments = @comments.present? ? @comments : nil

      HQMF::DataCriteria.new(id, title, nil, description, @code_list_id, cc, derivation_operator, @definition, status,
                             mv, field_values, met, retrieve_code_system_for_model, @negation, @negation_code_list_id,
                             mtr, mso, @specific_occurrence, @specific_occurrence_const, @source_data_criteria,
                             comments, @variable)
    end
1132021
def export_model(module_spec, class_count, saved_model_dir):
  
  # The SavedModel should hold the eval graph.
  sess, in_image, _, _, _, _ = build_eval_session(module_spec, class_count)
  with sess.graph.as_default() as graph:
    tf.saved_model.simple_save(
        sess,
        saved_model_dir,
        inputs={'image': in_image},
        outputs={'prediction': graph.get_tensor_by_name('final_result:0')},
        legacy_init_op=tf.group(tf.tables_initializer(), name='legacy_init_op')
    )