rumale-torch 0.1.0 → 0.2.0

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: 0ec07a29a0bfa24f06e95a9cd8ca4e80eb61ffcb80d66caa2fc29b9f288bbb70
4
- data.tar.gz: 4831243f51051c809c73d090424341fffec4b194f9f6e8fb83e648ab5ba4619e
3
+ metadata.gz: 42a236e4bcb36616d0ae30c45848786a6765c1c143ccd33c6b1674a960eabedb
4
+ data.tar.gz: 4cb6612a18e0d80027dce99feeb60e1af10eda8fde28d53570e258ce86031ecc
5
5
  SHA512:
6
- metadata.gz: 053ed2b73a9edb5bb44631ed815555ca9bea25dab6de0edaa88bbd3358de07ea488d9c830ed083a99cb62007691512beb8cf68b0380fa440ecdfd22d5c1457c6
7
- data.tar.gz: 1c483667b49e6bab0d2bd9cf8665b1f5d1f2e7a58f3e70b01800f50dc89d98b3cedd03ad30cb59c441c4c8bb355d63556863bb238081e304e20dfc15cd2d478c
6
+ metadata.gz: 5752fcc6806297cbc3cf2157414aba1c9d7c284a5cecb86b447419a01c0122acf1a44341099505bfa5f1cf676489f6a8bb541acdad542b2739867b0b09a6315a
7
+ data.tar.gz: 13a317eac5078834e3a2d046561ca6b1cde0ab5cd8c802dec0f070aa47f2538dae3b970a48753fd9b3271228a9fb5dcdf8b7300c07f119e599a0a7be0598e5b6
data/CHANGELOG.md CHANGED
@@ -1,2 +1,9 @@
1
+ # 0.2.0
2
+ - Refactor to support the new Rumale API.
3
+
4
+ # 0.1.1
5
+ - Refator codes and config files.
6
+ - Introduce commitlint and rubocop.
7
+
1
8
  # 0.1.0
2
9
  - First release.
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020 Atsushi Tatsuma
1
+ Copyright (c) 2020-2023 Atsushi Tatsuma
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build Status](https://github.com/yoshoku/rumale-torch/workflows/build/badge.svg)](https://github.com/yoshoku/rumale-torch/actions?query=workflow%3Abuild)
4
4
  [![Gem Version](https://badge.fury.io/rb/rumale-torch.svg)](https://badge.fury.io/rb/rumale-torch)
5
5
  [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/rumale-torch/blob/main/LICENSE.txt)
6
- [![Documentation](http://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/rumale-torch/doc/)
6
+ [![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/rumale-torch/doc/)
7
7
 
8
8
  Rumale::Torch provides the learning and inference by the neural network defined in [torch.rb](https://github.com/ankane/torch.rb)
9
9
  with the same interface as [Rumale](https://github.com/yoshoku/rumale).
@@ -211,12 +211,10 @@ $ ruby cv.rb
211
211
 
212
212
  ## Contributing
213
213
 
214
- Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/rumale-torch. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yoshoku/rumale-torch/blob/master/CODE_OF_CONDUCT.md).
214
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/rumale-torch.
215
+ This project is intended to be a safe, welcoming space for collaboration,
216
+ and contributors are expected to adhere to the [Contributor Covenant](https://contributor-covenant.org) code of conduct.
215
217
 
216
218
  ## License
217
219
 
218
220
  The gem is available as open source under the terms of the [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause).
219
-
220
- ## Code of Conduct
221
-
222
- Everyone interacting in the Rumale::Torch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/rumale-torch/blob/master/CODE_OF_CONDUCT.md).
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rumale/base/base_estimator'
3
+ require 'rumale/base/estimator'
4
4
  require 'rumale/base/classifier'
5
5
  require 'rumale/preprocessing/label_encoder'
6
6
  require 'rumale/model_selection/function'
@@ -38,9 +38,8 @@ module Rumale
38
38
  #
39
39
  # classifier.predict(x)
40
40
  #
41
- class NeuralNetClassifier
42
- include Base::BaseEstimator
43
- include Base::Classifier
41
+ class NeuralNetClassifier < Rumale::Base::Estimator
42
+ include Rumale::Base::Classifier
44
43
 
45
44
  # Return the class labels.
46
45
  # @return [Numo::Int32] (size: n_classes)
@@ -80,6 +79,7 @@ module Rumale
80
79
  def initialize(model:, device: nil, optimizer: nil, loss: nil,
81
80
  batch_size: 128, max_epoch: 10, shuffle: true, validation_split: 0,
82
81
  verbose: false, random_seed: nil)
82
+ super()
83
83
  @model = model
84
84
  @device = device || ::Torch.device('cpu')
85
85
  @optimizer = optimizer || ::Torch::Optim::Adam.new(model.parameters)
@@ -193,9 +193,13 @@ module Rumale
193
193
 
194
194
  def display_epoch(train_loader, test_loader, epoch)
195
195
  if test_loader.nil?
196
- puts(format("epoch: %#{max_epoch.to_s.length}d/#{max_epoch} - loss: %.4f - accuracy: %.4f", epoch, *evaluate(train_loader)))
196
+ puts(format("epoch: %#{max_epoch.to_s.length}d/#{max_epoch} - loss: %.4f - accuracy: %.4f",
197
+ epoch, *evaluate(train_loader)))
197
198
  else
198
- puts(format("epoch: %#{max_epoch.to_s.length}d/#{max_epoch} - loss: %.4f - accuracy: %.4f - val_loss: %.4f - val_accuracy: %.4f", epoch, *evaluate(train_loader), *evaluate(test_loader)))
199
+ # rubocop:disable Layout/LineLength
200
+ puts(format("epoch: %#{max_epoch.to_s.length}d/#{max_epoch} - loss: %.4f - accuracy: %.4f - val_loss: %.4f - val_accuracy: %.4f",
201
+ epoch, *evaluate(train_loader), *evaluate(test_loader)))
202
+ # rubocop:enable Layout/LineLength
199
203
  end
200
204
  end
201
205
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rumale/base/base_estimator'
3
+ require 'rumale/base/estimator'
4
4
  require 'rumale/base/regressor'
5
5
  require 'rumale/model_selection/shuffle_split'
6
6
 
@@ -36,9 +36,8 @@ module Rumale
36
36
  #
37
37
  # regressor.predict(x)
38
38
  #
39
- class NeuralNetRegressor
40
- include Base::BaseEstimator
41
- include Base::Regressor
39
+ class NeuralNetRegressor < Rumale::Base::Estimator
40
+ include Rumale::Base::Regressor
42
41
 
43
42
  # Return the neural nets defined with torch.rb.
44
43
  # @return [Torch::NN::Module]
@@ -74,6 +73,7 @@ module Rumale
74
73
  def initialize(model:, device: nil, optimizer: nil, loss: nil,
75
74
  batch_size: 128, max_epoch: 10, shuffle: true, validation_split: 0,
76
75
  verbose: false, random_seed: nil)
76
+ super()
77
77
  @model = model
78
78
  @device = device || ::Torch.device('cpu')
79
79
  @optimizer = optimizer || ::Torch::Optim::Adam.new(model.parameters)
@@ -182,7 +182,8 @@ module Rumale
182
182
  if test_loader.nil?
183
183
  puts(format("epoch: %#{max_epoch.to_s.length}d/#{max_epoch} - loss: %.4f", epoch, evaluate(train_loader)))
184
184
  else
185
- puts(format("epoch: %#{max_epoch.to_s.length}d/#{max_epoch} - loss: %.4f - val_loss: %.4f", epoch, evaluate(train_loader), evaluate(test_loader)))
185
+ puts(format("epoch: %#{max_epoch.to_s.length}d/#{max_epoch} - loss: %.4f - val_loss: %.4f",
186
+ epoch, evaluate(train_loader), evaluate(test_loader)))
186
187
  end
187
188
  end
188
189
 
@@ -6,6 +6,6 @@ module Rumale
6
6
  # the neural nets defined in torch.rb with the same interface as Rumale.
7
7
  module Torch
8
8
  # The version of Rumale::Torch you are using.
9
- VERSION = '0.1.0'
9
+ VERSION = '0.2.0'
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,29 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rumale-torch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-29 00:00:00.000000000 Z
11
+ date: 2023-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rumale
14
+ name: rumale-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.24'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.24'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rumale-model_selection
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.24'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.24'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rumale-preprocessing
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.24'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.24'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: torch-rb
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -38,28 +66,23 @@ dependencies:
38
66
  - - ">="
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
- description: Rumale::Torch provides the learning and inference by the neural network
69
+ description: 'Rumale::Torch provides the learning and inference by the neural network
42
70
  defined in torch.rb with the same interface as Rumale
71
+
72
+ '
43
73
  email:
44
74
  - yoshoku@outlook.com
45
75
  executables: []
46
76
  extensions: []
47
77
  extra_rdoc_files: []
48
78
  files:
49
- - ".github/workflows/build.yml"
50
- - ".gitignore"
51
- - ".rspec"
52
79
  - CHANGELOG.md
53
- - CODE_OF_CONDUCT.md
54
- - Gemfile
55
80
  - LICENSE.txt
56
81
  - README.md
57
- - Rakefile
58
82
  - lib/rumale/torch.rb
59
83
  - lib/rumale/torch/neural_net_classifier.rb
60
84
  - lib/rumale/torch/neural_net_regressor.rb
61
85
  - lib/rumale/torch/version.rb
62
- - rumale-torch.gemspec
63
86
  homepage: https://github.com/yoshoku/rumale-torch
64
87
  licenses:
65
88
  - BSD-3-Clause
@@ -68,7 +91,8 @@ metadata:
68
91
  source_code_uri: https://github.com/yoshoku/rumale-torch
69
92
  changelog_uri: https://github.com/yoshoku/rumale-torch/blob/main/CHANGELOG.md
70
93
  documentation_uri: https://yoshoku.github.io/rumale-torch/doc/
71
- post_install_message:
94
+ rubygems_mfa_required: 'true'
95
+ post_install_message:
72
96
  rdoc_options: []
73
97
  require_paths:
74
98
  - lib
@@ -83,8 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
107
  - !ruby/object:Gem::Version
84
108
  version: '0'
85
109
  requirements: []
86
- rubygems_version: 3.1.4
87
- signing_key:
110
+ rubygems_version: 3.3.26
111
+ signing_key:
88
112
  specification_version: 4
89
113
  summary: Rumale::Torch provides the learning and inference by the neural network defined
90
114
  in torch.rb with the same interface as Rumale
@@ -1,33 +0,0 @@
1
- name: build
2
- on: [push, pull_request]
3
- jobs:
4
- build:
5
- runs-on: ubuntu-20.04
6
- strategy:
7
- matrix:
8
- ruby: [ '2.5', '2.6', '2.7' ]
9
- env:
10
- LIBTORCH_VERSION: 1.7.1
11
- steps:
12
- - uses: actions/checkout@v2
13
- - name: Set up Ruby ${{ matrix.ruby }}
14
- uses: actions/setup-ruby@v1
15
- with:
16
- ruby-version: ${{ matrix.ruby }}
17
- - uses: actions/cache@v2
18
- with:
19
- path: ~/libtorch
20
- key: libtorch-${{ env.LIBTORCH_VERSION }}
21
- id: cache-libtorch
22
- - name: Download LibTorch
23
- if: steps.cache-libtorch.outputs.cache-hit != 'true'
24
- run: |
25
- cd ~
26
- wget -q -O libtorch.zip https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-$LIBTORCH_VERSION%2Bcpu.zip
27
- unzip -q libtorch.zip
28
- - name: Build and test with Rake
29
- run: |
30
- gem install bundler
31
- bundle config build.torch-rb --with-torch-dir=$HOME/libtorch
32
- bundle install
33
- bundle exec rake
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
12
-
13
- .DS_Store
14
- .ruby-version
15
- tags
16
- Gemfile.lock
17
- *.swp
18
- *.bundle
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at yoshoku@outlook.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in rumale-torch.gemspec
6
- gemspec
7
-
8
- gem 'rake', '~> 13.0'
9
- gem 'rspec', '~> 3.0'
10
- gem 'simplecov', '~> 0.19'
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
data/rumale-torch.gemspec DELETED
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/rumale/torch/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'rumale-torch'
7
- spec.version = Rumale::Torch::VERSION
8
- spec.authors = ['yoshoku']
9
- spec.email = ['yoshoku@outlook.com']
10
-
11
- spec.summary = 'Rumale::Torch provides the learning and inference by the neural network defined in torch.rb with the same interface as Rumale'
12
- spec.description = 'Rumale::Torch provides the learning and inference by the neural network defined in torch.rb with the same interface as Rumale'
13
- spec.homepage = 'https://github.com/yoshoku/rumale-torch'
14
- spec.license = 'BSD-3-Clause'
15
-
16
- spec.metadata['homepage_uri'] = spec.homepage
17
- spec.metadata['source_code_uri'] = spec.homepage
18
- spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/rumale-torch/blob/main/CHANGELOG.md'
19
- spec.metadata['documentation_uri'] = 'https://yoshoku.github.io/rumale-torch/doc/'
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
- end
26
- spec.bindir = 'exe'
27
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
- spec.require_paths = ['lib']
29
-
30
- spec.add_runtime_dependency 'rumale'
31
- spec.add_runtime_dependency 'torch-rb'
32
- end