Skip to main content

For Kaggle playing use official vowpalwabbit package, for production use subwabbit.

subwabbit is Python wrapper around great Vowpal Wabbit tool that aims to be as fast as Vowpal itself. It is ideal for real time use, when many lines need to be scored in just few milliseconds or when high throughput is required.

Advantages:

  • more then 4x faster then official Python wrapper

  • good latency guarantees - give 10ms for prediction and it will end in 10ms

  • explainability - API for explaining prediction value

  • use just vw CLI - no compiling

  • proven by reliably running in production at Seznam.cz where it makes hundreds of thousands of predictions per second per machine

Documentation

Full documentation can be found on Read the docs.

Requirements

  • Python 3.4+

  • Vowpal Wabbit

You can install Vowpal Wabbit by running:

sudo apt-get install vowpal-wabbit

on Debian-based systems or by using Homebrew:

brew install vowpal-wabbit

You can also build Vowpal Wabbit from source, see instructions.

subwabbit will probably work on other Pythons than 3.4+ but it is not tested (contribution welcomed).

Installation

pip install subwabbit

Example use

from subwabbit import VowpalWabbitProcess, VowpalWabbitDummyFormatter

vw = VowpalWabbitProcess(VowpalWabbitDummyFormatter(), ['-q', 'ab'])

common_features = '|a common_feature1:1.5 common_feature2:-0.3'
items_features = [
    '|b item123',
    '|b item456',
    '|b item789'
]

for prediction in vw.predict(common_features, items_features, timeout=0.001):
    print(prediction)
0.4
0.5
0.6

This is the simplest use of subwabbit library. You have some common features that describe context - it can be location of user or daytime for example. Then there is collection of items to score, each item has its specific features. Use of timeout argument means “compute as many predictions as you can in 1ms”, then stop.

More advanced use

With simple implementation above you will not use key feature of subwabbit: you can format your vw lines while Vowpal is busy with computing predictions. By using this trick, you can get great speedup and VW lines formatting abstraction as a bonus.

Suppose we have features as dicts:

common_features = {
    'common_feature1': 1.5,
    'common_feature2': -0.3
}

items_features = [
    {'id': 'item123'},
    {'id': 'item456'},
    {'id': 'item789'}
]

Then implementation with use of formatter can look like this:

from subwabbit import VowpalWabbitBaseFormatter, VowpalWabbitProcess

class MyVowpalWabbitFormatter(VowpalWabbitBaseFormatter):

    def get_common_line_part(self, common_features, debug_info=None):
        return '|a ccommon_feature1:{:.2f} common_feature2:{:.2f}'.format(
            common_features['common_feature1'],
            common_features['common_feature2']
        )

    def get_item_line_part(self, common_features, item_features, debug_info=None):
        return '|b {}'.format(item_features['id'])

vw = VowpalWabbitProcess(MyVowpalWabbitFormatter(), ['-q', 'ab'])

for prediction in vw.predict(common_features, items_features, timeout=0.001):
    print(prediction)
0.4
0.5
0.6

Benchmarks

Benchmarks were made on logistic regression model with L2 regularization and with many quadratic combinations to mimic real-world use case. Real dataset containing 1000 contexts and 3000 items was used. Model was pretrained on this dataset with random labels generated. You can see used features at:

  • tests/benchmarks/requests.json

  • tests/benchmarks/items.json

# Prepare environment
pip install pandas vowpalwabbit
cd tests/benchmarks
# benchmarks depends a lot whether Vowpal is trained or just initialized
python pretrain_model.py

# Benchmark official Python client
python benchmark_pyvw.py

# Benchmark blocking implementation
python benchmark_blocking_implementation.py

# Benchmark nonblocking implementation
python benchmark_blocking_implementation.py

Benchmark results

Results on Dell Latitude E7470 with Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz.

Table shows how many lines implementation can predict in 10ms:

pyvw

subwabbit

mean

239.461000

1033.70000

min

83.000000

100.00000

25%

192.750000

650.00000

50%

240.000000

1000.00000

75%

288.000000

1350.00000

90%

316.000000

1600.00000

99%

349.000000

1900.00000

max

362.000000

2050.00000

subwabbit is in average more then 4x faster than official Python wrapper.

License

Copyright (c) 2016 - 2018, Seznam.cz, a.s. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

subwabbit-1.1.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

subwabbit-1.1.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file subwabbit-1.1.0.tar.gz.

File metadata

  • Download URL: subwabbit-1.1.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.4.3 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.5.5

File hashes

Hashes for subwabbit-1.1.0.tar.gz
Algorithm Hash digest
SHA256 034998446feb797dc2fd396de8c95436e6de12bb986f3ee846a58be66a00af97
MD5 b0bef70139cdc0d46fd3aa50ff2a546c
BLAKE2b-256 300e436e229451c535eba1fd398eb1ceda45355c88a2d5f5dad8f5f03729aef8

See more details on using hashes here.

File details

Details for the file subwabbit-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: subwabbit-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.4.3 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.5.5

File hashes

Hashes for subwabbit-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 119b2ede962e98d6b11afcb8cbf1041f88f22097ee8a7eb2e0e50dd82176fe42
MD5 eabe333805e8a902733d4105796aad61
BLAKE2b-256 9a5366317dbb8b921603325708d94885b55ea307775ec09cee0ca4d18475f085

See more details on using hashes here.

Release history Release notifications | RSS feed

2.1.0

1 file

2.0.2

1 file

2.0.0

2 files

This release

1.1.0 This release

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page