pySNoW: A Python interface to SNoW
(46 total downloads)
[
Download |
User Guide ]
pySnow is a minimal python interface to the
SNoW
- Sparse Network of Winnows learning architecture. It is meant to be
faithful to the original command line interface and provides access to the
train, test, evaluate, interactive and server modes directly from python.
pySnow requires SNoW version 3.2.0. Please report any questions
or problems to nnshah2@uiuc.edu.
The pySnow module provides 3 functions (train, test, evaluate) and 1
type SnowSession) corresponding to the different modes of the original command
line SNoW.
Functions
train(args)
Equivalent to running SNoW in training mode. Command line arguments are
passed in as a dictionary of key,value pairs. In addition to the supported
output modes of SNoW the command can also redirect output to a string
that is returned as the result of the command. This is the default.
Example:
| |
## original snow command:
## ../snow -train -I $train_file -F $net_file -A $arch_file
## becomes:
import snow
args = {'I':train_file, 'F':net_file, 'A':arch_file}
result = snow.train(args)
|
|
test(args)
Equivalent to running SNoW in testing mode. Command line arguments are
passed in as a dictionary of key,value pairs. In addition to the supported
output modes of SNoW the command can also redirect output to a string
that is returned as the result of the command. This is the default.
Example:
| |
## original snow command:
## ../snow -test -I $test_file -F $net_file
## becomes:
import snow
args = {'I':test_file, 'F':net_file}
result = snow.test(args)
|
|
evaluate(args)
Equivalent to running SNoW in evaluate mode. Command line arguments are
passed in as a dictionary of key,value pairs. In addition to the supported
output modes of SNoW the command can also redirect output to a string
that is returned as the result of the command. This is the default.
SnowSession
In addition to the basic "one-shot" modes described above pySnow also
provides an interface to SNoW's "interactive" and "server" modes
through the SnowSession type. The SnowSession constructor takes two arguments,
the runMode and the command line arguments (as above). SnowSession provides
two methods "update" (for interactive mode) and "evaluateExample" (for server
mode).
Interactive Mode
To use SNoW's interactive mode, instantiate SnowSession type as
follows:
| |
args = {'I':test_file, 'F':net_file}
session = snow.SnowSession(snow.MODE_INTERACTIVE,args)
|
|
To update the network or evaluate an example use the "update" method:
| |
testdata = open(test_file,"r")
for ex in testdata:
result=session.update('e,'+ex)
print result
|
|
Server Mode
To use SNoW's server mode, instantiate SnowSession type as follows:
| |
args = {'I':test_file, 'F':net_file}
session = snow.SnowSession(snow.MODE_SERVER,args)
|
|
To evaluate an example use the "evaluateExample" method:
| |
testdata = open(test_file,"r")
for ex in testdata:
result=session.evaluateExample(ex)
print result
|
|
Note while this mode has the semantics of the traditional server mode, there
is no socket communication and no additional thread.
Participants: