vowpalwabbit 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +17 -2
- data/lib/vowpalwabbit/model.rb +29 -21
- data/lib/vowpalwabbit/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa89f06a4117a04e64013f332f75c1ebfd99542c508934430fd511b824fded94
|
4
|
+
data.tar.gz: 00d4b988b39f03ad1a5625e8eccfb427e96ef9488c964e50c7e436c8e2e4e57b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37051b8953fddd8f88bc22d2adf66003acfaf8a14beacd4314641616c2e607d5a8c59f572675e94f40759fe142ec491bf6d360493e93f910836ec9db84e909a5
|
7
|
+
data.tar.gz: 2233f54d84f06b8176cf4d37c5cd9387eeaaee06cdfdbd1402bad3fa0117e5f3d1f7df60e453aca8ac17dd5de3ececf1c6db026fb112f9eecf080ecc41e11bb3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,9 +4,11 @@
|
|
4
4
|
|
5
5
|
:fire: Uses the C API for blazing performance
|
6
6
|
|
7
|
+
[](https://travis-ci.org/ankane/vowpalwabbit)
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
|
-
First,
|
11
|
+
First, install the [Vowpal Wabbit C++ library](https://vowpalwabbit.org/start.html). For Homebrew, use:
|
10
12
|
|
11
13
|
```sh
|
12
14
|
brew install vowpal-wabbit
|
@@ -30,7 +32,7 @@ y = [1, 2, 3, 4]
|
|
30
32
|
Train a model
|
31
33
|
|
32
34
|
```ruby
|
33
|
-
model = VowpalWabbit::Regressor.new(
|
35
|
+
model = VowpalWabbit::Regressor.new(learning_rate: 100)
|
34
36
|
model.fit(x, y)
|
35
37
|
```
|
36
38
|
|
@@ -91,6 +93,12 @@ Data can be an array of arrays
|
|
91
93
|
[[1, 2, 3], [4, 5, 6]]
|
92
94
|
```
|
93
95
|
|
96
|
+
Or a Numo NArray
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
Numo::DFloat.new(3, 2).seq
|
100
|
+
```
|
101
|
+
|
94
102
|
Or an array of strings
|
95
103
|
|
96
104
|
```ruby
|
@@ -105,10 +113,17 @@ Or a path to a file
|
|
105
113
|
|
106
114
|
```ruby
|
107
115
|
model.fit("train.txt")
|
116
|
+
model.partial_fit("train.txt")
|
108
117
|
model.predict("train.txt")
|
109
118
|
model.score("train.txt")
|
110
119
|
```
|
111
120
|
|
121
|
+
Files can be compressed
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
model.fit("train.txt.gz")
|
125
|
+
```
|
126
|
+
|
112
127
|
Read more about the [input format](https://github.com/VowpalWabbit/vowpal_wabbit/wiki/Input-format)
|
113
128
|
|
114
129
|
## History
|
data/lib/vowpalwabbit/model.rb
CHANGED
@@ -51,7 +51,7 @@ module VowpalWabbit
|
|
51
51
|
bin_str = File.binread(filename)
|
52
52
|
model_data = ::FFI::MemoryPointer.new(:char, bin_str.bytesize)
|
53
53
|
model_data.put_bytes(0, bin_str)
|
54
|
-
@handle = FFI.VW_InitializeWithModel(param_str, model_data, bin_str.bytesize)
|
54
|
+
@handle = FFI.VW_InitializeWithModel(param_str(@params), model_data, bin_str.bytesize)
|
55
55
|
nil
|
56
56
|
end
|
57
57
|
|
@@ -59,12 +59,12 @@ module VowpalWabbit
|
|
59
59
|
|
60
60
|
# TODO clean-up handle
|
61
61
|
def handle
|
62
|
-
@handle ||= FFI.VW_InitializeA(param_str)
|
62
|
+
@handle ||= FFI.VW_InitializeA(param_str(@params))
|
63
63
|
end
|
64
64
|
|
65
|
-
def param_str
|
65
|
+
def param_str(params)
|
66
66
|
args =
|
67
|
-
|
67
|
+
params.map do |k, v|
|
68
68
|
check_param(k.to_s)
|
69
69
|
check_param(v.to_s)
|
70
70
|
|
@@ -108,31 +108,39 @@ module VowpalWabbit
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
# TODO support compressed files
|
112
111
|
def each_example(x, y = nil)
|
113
|
-
|
114
|
-
example = FFI.VW_ReadExampleA(handle, line)
|
115
|
-
yield example
|
116
|
-
FFI.VW_FinishExample(handle, example)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def each_line(x, y)
|
112
|
+
# path to a file
|
121
113
|
if x.is_a?(String)
|
122
114
|
raise ArgumentError, "Cannot pass y with file" if y
|
123
115
|
|
124
|
-
|
125
|
-
|
116
|
+
file_handle = FFI.VW_InitializeA(param_str(data: x, quiet: true))
|
117
|
+
FFI.VW_StartParser(file_handle)
|
118
|
+
loop do
|
119
|
+
example = FFI.VW_GetExample(file_handle)
|
120
|
+
break if example.read_pointer.null?
|
121
|
+
yield example
|
122
|
+
FFI.VW_FinishExample(file_handle, example)
|
126
123
|
end
|
124
|
+
FFI.VW_EndParser(file_handle)
|
125
|
+
FFI.VW_Finish(file_handle)
|
127
126
|
else
|
128
|
-
|
127
|
+
x = x.to_a
|
128
|
+
if y
|
129
|
+
y = y.to_a
|
130
|
+
raise ArgumentError, "x and y must have same size" if x.size != y.size
|
131
|
+
end
|
129
132
|
|
130
133
|
x.zip(y || []) do |xi, yi|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
134
|
+
line =
|
135
|
+
if xi.is_a?(String)
|
136
|
+
xi
|
137
|
+
else
|
138
|
+
"#{yi} 1 | #{xi.map.with_index { |v, i| "#{i}:#{v}" }.join(" ")}"
|
139
|
+
end
|
140
|
+
|
141
|
+
example = FFI.VW_ReadExampleA(handle, line)
|
142
|
+
yield example
|
143
|
+
FFI.VW_FinishExample(handle, example)
|
136
144
|
end
|
137
145
|
end
|
138
146
|
end
|
data/lib/vowpalwabbit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vowpalwabbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: numo-narray
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description:
|
70
84
|
email: andrew@chartkick.com
|
71
85
|
executables: []
|