How to use the srsly.pickle_loads function in srsly

To help you get started, we’ve selected a few srsly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github explosion / spaCy / tests / test_pickles.py View on Github external
def test_pickle_vocab(text1, text2):
    vocab = Vocab(lex_attr_getters={int(NORM): lambda string: string[:-1]})
    vocab.set_vector("dog", numpy.ones((5,), dtype="f"))
    lex1 = vocab[text1]
    lex2 = vocab[text2]
    assert lex1.norm_ == text1[:-1]
    assert lex2.norm_ == text2[:-1]
    data = srsly.pickle_dumps(vocab)
    unpickled = srsly.pickle_loads(data)
    assert unpickled[text1].orth == lex1.orth
    assert unpickled[text2].orth == lex2.orth
    assert unpickled[text1].norm == lex1.norm
    assert unpickled[text2].norm == lex2.norm
    assert unpickled[text1].norm != unpickled[text2].norm
    assert unpickled.vectors is not None
    assert list(vocab["dog"].vector) == [1.0, 1.0, 1.0, 1.0, 1.0]
github explosion / spaCy / tests / test_pickles.py View on Github external
def test_pickle_string_store(text1, text2):
    stringstore = StringStore()
    store1 = stringstore[text1]
    store2 = stringstore[text2]
    data = srsly.pickle_dumps(stringstore, protocol=-1)
    unpickled = srsly.pickle_loads(data)
    assert unpickled[text1] == store1
    assert unpickled[text2] == store2
    assert len(stringstore) == len(unpickled)
github explosion / thinc / thinc / extra / hpbff.py View on Github external
def train_epoch(
    model, sgd, hparams, train_X, train_y, dev_X, dev_y, device_id=-1, temperature=0.0
):
    model, sgd, hparams = srsly.pickle_loads(srsly.pickle_dumps((model, sgd, hparams)))
    if device_id >= 0:
        model.to_gpu(device_id)
        sgd.ops = model.ops
        sgd.to_gpu()
        if isinstance(train_y, numpy.ndarray):
            train_y = model.ops.asarray(train_y)
            dev_y = model.ops.asarray(dev_y)
    hparams = resample_hyper_params(hparams, temperature)
    sgd.learn_rate = hparams["learn_rate"]
    sgd.beta1 = hparams["beta1"]
    sgd.beta2 = hparams["beta2"]
    sgd.L2 = hparams["L2"]
    train_acc = 0.0
    train_n = 0
    for X, y in minibatch(
        train_X, train_y, size=hparams["batch_size"], nr_update=hparams["nr_update"]
github explosion / thinc / thinc / layers / base.py View on Github external
def __setstate__(self, state_data: bytes) -> None:
        self.__dict__ = srsly.pickle_loads(state_data)
github explosion / thinc / thinc / neural / _classes / model.py View on Github external
def __setstate__(self, state_data):
        self.__dict__ = srsly.pickle_loads(state_data)