Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from frx/streaming_vw
Some VW improvements and python examples
- Loading branch information
Showing
12 changed files
with
145 additions
and
11 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
examples/undocumented/python_modular/streaming_vw_createcache_modular.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from modshogun import StreamingVwFile | ||
from modshogun import StreamingVwCacheFile | ||
from modshogun import T_SVMLIGHT | ||
from modshogun import StreamingVwFeatures | ||
from modshogun import VowpalWabbit | ||
|
||
def create_cache(): | ||
"""Creates a binary cache from an ascii data file.""" | ||
|
||
# Open the input file as a StreamingVwFile | ||
input_file = StreamingVwFile("../data/fm_train_sparsereal.dat") | ||
# Default file name will be vw_cache.dat.cache | ||
input_file.set_write_to_cache(True) | ||
|
||
# Tell VW that the file is in SVMLight format | ||
# Supported types are T_DENSE, T_SVMLIGHT and T_VW | ||
input_file.set_parser_type(T_SVMLIGHT) | ||
|
||
# Create a StreamingVwFeatures object, `True' indicating the examples are labelled | ||
features = StreamingVwFeatures(input_file, True, 1024) | ||
|
||
# Create a VW object from the features | ||
vw = VowpalWabbit(features) | ||
vw.set_no_training(True) | ||
|
||
# Train (in this case does nothing but run over all examples) | ||
vw.train() | ||
|
||
def train_from_cache(): | ||
"""Train using the generated cache file.""" | ||
|
||
# Open the input cache file as a StreamingVwCacheFile | ||
input_file = StreamingVwCacheFile("vw_cache.dat.cache"); | ||
|
||
# The rest is exactly as for normal input | ||
features = StreamingVwFeatures(input_file, True, 1024); | ||
vw = VowpalWabbit(features) | ||
vw.train() | ||
|
||
if __name__ == "__main__": | ||
print "Creating cache..." | ||
create_cache() | ||
print "Done." | ||
|
||
print "Training using the cache file..." | ||
train_from_cache() | ||
|
26 changes: 26 additions & 0 deletions
26
examples/undocumented/python_modular/streaming_vw_modular.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from modshogun import StreamingVwFile | ||
from modshogun import T_SVMLIGHT | ||
from modshogun import StreamingVwFeatures | ||
from modshogun import VowpalWabbit | ||
|
||
def run_vw(): | ||
"""Runs the VW algorithm on a toy dataset in SVMLight format.""" | ||
|
||
# Open the input file as a StreamingVwFile | ||
input_file = StreamingVwFile("../data/fm_train_sparsereal.dat") | ||
|
||
# Tell VW that the file is in SVMLight format | ||
# Supported types are T_DENSE, T_SVMLIGHT and T_VW | ||
input_file.set_parser_type(T_SVMLIGHT) | ||
|
||
# Create a StreamingVwFeatures object, `True' indicating the examples are labelled | ||
features = StreamingVwFeatures(input_file, True, 1024) | ||
|
||
# Create a VW object from the features | ||
vw = VowpalWabbit(features) | ||
|
||
# Train | ||
vw.train() | ||
|
||
if __name__ == "__main__": | ||
run_vw() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,4 +72,5 @@ void CStreamingVwFile::init() | |
|
||
set_parser_type(T_VW); | ||
write_to_cache = false; | ||
SG_REF(env); | ||
} |