How to use the vowpalwabbit.pyvw.vw function in vowpalwabbit

To help you get started, we’ve selected a few vowpalwabbit 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 VowpalWabbit / vowpal_wabbit / python / examples / test_search_ldf.py View on Github external
ex.set_label_string(str(p) + ':0')
        return ex

    def _run(self, sentence):   # it's called _run to remind you that you shouldn't call it directly!
        output = []
        for n in range(len(sentence)):
            pos,word = sentence[n]
            # use "with...as..." to guarantee that the example is finished properly
            ex = [ self.makeExample(word,p) for p in [DET,NOUN,VERB,ADJ] ]
            pred = self.sch.predict(examples=ex, my_tag=n+1, oracle=pos, condition=(n,'p'))
            vw.finish_example(ex)
            output.append(pred)
        return output

# initialize VW as usual, but use 'hook' as the search_task
vw = pyvw.vw("--search 0 --csoaa_ldf m --quiet --search_task hook --ring_size 1024")

# tell VW to construct your search task object
sequenceLabeler = vw.init_search_task(SequenceLabeler)

# train it on the above dataset ten times; the my_dataset.__iter__ feeds into _run above
print('training!')
i = 0
while i < 10:
    sequenceLabeler.learn(my_dataset)
    i += 1

# now see the predictions on a test sentence
print('predicting!', file=sys.stderr)
print(sequenceLabeler.predict( [(1,w) for w in "the sandwich ate a monster".split()] ))
print('should have printed: [1, 2, 3, 1, 2]')
github Kaggle / docker-python / test_build.py View on Github external
for ds in client.list_datasets(): pass
except:
    pass
httpd.shutdown()
assert fake_bq_called, "Fake server did not recieve a request from the BQ client."
assert fake_bq_header_found, "X-KAGGLE-PROXY-DATA header was missing from the BQ request."
print("bigquery proxy ok")

import shap
print("shap ok")

import kmapper
print("kmapper ok")

from vowpalwabbit import pyvw
vw = pyvw.vw(quiet=True)
ex = vw.example('1 | a b c')
vw.learn(ex)
print(vw.predict(ex))
print('vowpalwabbit ok')

import essentia
print(essentia.__version__)
print("Essentia ok")
github VowpalWabbit / vowpal_wabbit / python / examples / covington.py View on Github external
vw.finish_example(examples)

            # Reverse mapping:
            # 1 => -1
            # 2...n+1 => 0...n-1
            # n+2...N+1 => n+1...N
            output[n] = pred-2 if pred <= n + 1 else pred - 1 # have to +1 because n==m excluded

        return output

# TODO: if they make sure search=0 <==> ldf <==> csoaa_ldf

# demo the non-ldf version:

print('training non-LDF')
vw = pyvw.vw("--search 2 --search_task hook --ring_size 1024 --quiet")
task = vw.init_search_task(CovingtonDepParser)
for p in range(2): # do two passes over the training data
    task.learn(my_dataset)
print('testing non-LDF')
print(task.predict( [(w,-1) for w in "the monster ate a sandwich".split()] ))
print('should have printed [ 1 2 -1 4 2 ]')
github NatLibFi / Annif / annif / backend / vw_base.py View on Github external
def _create_model(self, project, initial_params={}):
        initial_params = initial_params.copy()  # don't mutate the original
        trainpath = os.path.join(self.datadir, self.TRAIN_FILE)
        initial_params['data'] = trainpath
        params = self._create_params(initial_params)
        if params.get('passes', 1) > 1:
            # need a cache file when there are multiple passes
            params.update({'cache': True, 'kill_cache': True})
        self.debug("model parameters: {}".format(params))
        self._model = pyvw.vw(**params)
        modelpath = os.path.join(self.datadir, self.MODEL_FILE)
        self._model.save(modelpath)
github VowpalWabbit / vowpal_wabbit / python / vowpalwabbit / sklearn_vw.py View on Github external
def get_vw(self):
        """Factory to create a vw instance on demand

        Returns
        -------
        pyvw.vw instance
        """
        if self.vw_ is None:
            self.vw_ = pyvw.vw(**self.params)

        return self.vw_

vowpalwabbit

Vowpal Wabbit Python package

BSD-3-Clause
Latest version published 4 months ago

Package Health Score

86 / 100
Full package analysis

Similar packages