Generator that yields prediction objects from an API response.
9323
def predictions(self):
        """"""
        for prediction in self.api.predictions(vid=self.vid)['prd']:
            pobj = Prediction.fromapi(self.api, prediction)
            pobj._busobj = self
            yield pobj
272836
def batch_gen(data, batch_size):
    '''
    
    '''
    data = data or []
    for i in range(0, len(data), batch_size):
        yield data[i:i + batch_size]
771734
def get_zipped_dataset_from_predictions(predictions):
  """"""
  targets = stack_data_given_key(predictions, "targets")
  outputs = stack_data_given_key(predictions, "outputs")
  num_videos, num_steps = targets.shape[:2]

  # Truncate output time-steps to match target time-steps
  outputs = outputs[:, :num_steps]

  targets_placeholder = tf.placeholder(targets.dtype, targets.shape)
  outputs_placeholder = tf.placeholder(outputs.dtype, outputs.shape)
  dataset = tf.data.Dataset.from_tensor_slices(
      (targets_placeholder, outputs_placeholder))
  iterator = dataset.make_initializable_iterator()
  feed_dict = {targets_placeholder: targets,
               outputs_placeholder: outputs}
  return iterator, feed_dict, num_videos
1497
def neural_net_predict(params, inputs):
    """"""
    for W, b in params:
        outputs = np.dot(inputs, W) + b
        inputs = np.tanh(outputs)
    return outputs - logsumexp(outputs, axis=1, keepdims=True)
879198
def evaluate_with_predictions(data_file, predictions):
    '''
    
    '''
    expected_version = '1.1'
    with open(data_file) as dataset_file:
        dataset_json = json.load(dataset_file)
        if dataset_json['version'] != expected_version:
            print('Evaluation expects v-' + expected_version +
                  ', but got dataset with v-' + dataset_json['version'],
                  file=sys.stderr)
        dataset = dataset_json['data']
    result = _evaluate(dataset, predictions)
    return result['exact_match']
740895
def user_parse(data):
        """"""
        yield 'id', data.get('uuid')
        yield 'username', data.get('username')
        yield 'last_name', data.get('display_name')
        links = data.get('links', {})
        yield 'picture', links.get('avatar', {}).get('href')
        yield 'link', links.get('html', {}).get('href')
752242
def _extract_models(cls, apis):
        ''''''
        # TODO: This would probably be much better if the info would be
        # extracted from the classes, rather than from the swagger
        # representation...
        models = set()
        for api in apis:
            for op in api.get('operations', []):
                models.add(op['type'])
                for param in op.get('parameters', []):
                    models.add(param.get('type', 'void'))
                for msg in op['responseMessages']:
                    models.add(msg.get('responseModel', 'void'))
        # Convert from swagger name representation to classes
        models = map(lambda m: Model.name_to_cls[m], models)
        ret = {}
        for model in models:
            if model.native_type:
                continue
            obj = model.schema.copy()
            obj['id'] = model.name
            ret[model.name] = obj
        return ret
1052018
def async_make_reply(msgname, types, arguments_future, major):
    """"""
    arguments = yield arguments_future
    raise gen.Return(make_reply(msgname, types, arguments, major))
914346
def predict(self, **kwargs):
        
        reformatted_predict = self.reformat_predict_data()
        results = {}
        for task_inst in self.trained_tasks:
            predict = reformatted_predict[task_inst.data_format]['predict']
            kwargs['predict']=predict
            results.update({get_task_name(task_inst) : self.execute_predict_task(task_inst, predict, **kwargs)})
        return results
93778
def _generate_features(self, feature_extractors):
        
        results = [pd.DataFrame()]
        n_ext = len(feature_extractors)

        for i, extractor in enumerate(feature_extractors):
            log.info("generating: '%s' (%d/%d)", extractor.name, i + 1, n_ext)
            cached_extractor = self._cache[extractor.name]
            if extractor.same(cached_extractor):
                log.info('pulling from cache')
                extractor = cached_extractor
            else:
                log.info('running...')
                extractor.extract()
            results.append(extractor.result)
            if self.cache_path:
                self._cache[extractor.name] = extractor

        if self.cache_path:
            with open(self.cache_path, 'wb') as f:
                pickle.dump(self._cache, f)

        return pd.concat(results, axis=1)
579090
function generateOutput(source) {
    return __awaiter(this, void 0, void 0, function () {
        var isCached, artifact, compiled, artifact, _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0: return [4 /*yield*/, caching.has(source.codeHash)];
                case 1:
                    isCached = _b.sent();
                    if (!isCached) return [3 /*break*/, 3];
                    return [4 /*yield*/, caching.get(source.codeHash)];
                case 2:
                    artifact = _b.sent();
                    return [2 /*return*/, artifact];
                case 3: return [4 /*yield*/, solc_install_1.installVersion(source.solcVersion)];
                case 4:
                    _b.sent();
                    return [4 /*yield*/, compile_1.default(source)];
                case 5:
                    compiled = _b.sent();
                    _a = {
                        compiled: compiled
                    };
                    return [4 /*yield*/, output_files_1.createJavascriptFile(source, compiled)];
                case 6:
                    _a.javascript = _b.sent();
                    return [4 /*yield*/, output_files_1.createTypescriptFile(source, compiled)];
                case 7:
                    artifact = (_a.typescript = _b.sent(),
                        _a);
                    return [4 /*yield*/, caching.set(source.codeHash, artifact)];
                case 8:
                    _b.sent();
                    return [2 /*return*/, artifact];
            }
        });
    });
}
1038374
def _expectation(self, prep_prog, operator_programs, random_seed) -> np.ndarray:
        
        if isinstance(operator_programs, Program):
            warnings.warn("You have provided a Program rather than a list of Programs. The results "
                          "from expectation will be line-wise expectation values of the "
                          "operator_programs.", SyntaxWarning)

        payload = expectation_payload(prep_prog, operator_programs, random_seed)
        response = post_json(self.session, self.sync_endpoint + "/qvm", payload)
        return np.asarray(response.json())
313504
def from_dict(doc):
        
        return ModelOutputs(
            ModelOutputFile.from_dict(doc['prediction']),
            [ModelOutputFile.from_dict(a) for a in doc['attachments']]
        )
53083
def loads(s):
    """"""
    _decoder = json.JSONDecoder()

    while s:
        s = s.strip()
        obj, pos = _decoder.raw_decode(s)
        if not pos:
            raise ValueError('no JSON object found at %i' % pos)
        yield obj
        s = s[pos:]
1114420
def generate_flattened_dict(headers, results):
    ''''''
    for name, values in results.items():
        row = []
        for header in headers:
            if header == 'name':
                row.append(name)
            elif ':' in header:
                neurite_type, metric = header.split(':')
                row.append(values[neurite_type][metric])
            else:
                row.append(values[header])
        yield row
177675
def response_builder(self, response):
        '''
        '''
        try:
            r = response.json()
            result = r['query']['results']
            response = {
                'num_result': r['query']['count'] ,
                'result': result
            }
        except (Exception,) as e:
            print(e)
            return response.content

        return response
85522
def generator(self, output, target):
        ""
        fake_pred = self.gan_model.critic(output)
        return self.loss_funcG(fake_pred, target, output)