vowpalwabbit 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd6a68e5d6103be4f6f58bd3fb6cb9785bd47382d7787b8d0ebc2c0336d87af3
4
- data.tar.gz: 2f290dfdfe0539b4daf3e73dfbb39d04fa97e2f5c9aec08d43b0ee81db1d49b2
3
+ metadata.gz: fa89f06a4117a04e64013f332f75c1ebfd99542c508934430fd511b824fded94
4
+ data.tar.gz: 00d4b988b39f03ad1a5625e8eccfb427e96ef9488c964e50c7e436c8e2e4e57b
5
5
  SHA512:
6
- metadata.gz: 7e63904cf470666bbec00e9096e1701c1824af4b7790aa9d137a8a779eefb6d6833aadf4043f7d941e2f8395dfda532349bada33ffaa5cfa8461a593b9e80088
7
- data.tar.gz: 0d6b47d922da2cfefb525f59e718e6f3be4c7e99033647f0f8814b9efde0095399b1b87c5922143cefeb8f0b7207ca4811b8c1c29505ea7b5af8cdc5c9910acc
6
+ metadata.gz: 37051b8953fddd8f88bc22d2adf66003acfaf8a14beacd4314641616c2e607d5a8c59f572675e94f40759fe142ec491bf6d360493e93f910836ec9db84e909a5
7
+ data.tar.gz: 2233f54d84f06b8176cf4d37c5cd9387eeaaee06cdfdbd1402bad3fa0117e5f3d1f7df60e453aca8ac17dd5de3ececf1c6db026fb112f9eecf080ecc41e11bb3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.1
2
+
3
+ - Added support for compressed files
4
+ - Added support for Numo
5
+
1
6
  ## 0.1.0
2
7
 
3
8
  - First release
data/README.md CHANGED
@@ -4,9 +4,11 @@
4
4
 
5
5
  :fire: Uses the C API for blazing performance
6
6
 
7
+ [![Build Status](https://travis-ci.org/ankane/vowpalwabbit.svg?branch=master)](https://travis-ci.org/ankane/vowpalwabbit)
8
+
7
9
  ## Installation
8
10
 
9
- First, [install Vowpal Wabbit](https://vowpalwabbit.org/start.html). For Homebrew, use:
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(l: 100)
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
@@ -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
- @params.map do |k, v|
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
- each_line(x, y) do |line|
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
- File.foreach(x) do |line|
125
- yield line
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
- raise ArgumentError, "x and y must have same size" if y && x.size != y.size
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
- if xi.is_a?(String)
132
- yield xi
133
- else
134
- yield "#{yi} 1 | #{xi.map.with_index { |v, i| "#{i}:#{v}" }.join(" ")}"
135
- end
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
@@ -1,3 +1,3 @@
1
1
  module VowpalWabbit
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-10-21 00:00:00.000000000 Z
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: []