transformers-rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/LICENSE.txt +203 -0
  4. data/README.md +163 -0
  5. data/lib/transformers/activations.rb +57 -0
  6. data/lib/transformers/configuration_utils.rb +285 -0
  7. data/lib/transformers/convert_slow_tokenizer.rb +90 -0
  8. data/lib/transformers/data/processors/squad.rb +115 -0
  9. data/lib/transformers/dynamic_module_utils.rb +25 -0
  10. data/lib/transformers/feature_extraction_utils.rb +110 -0
  11. data/lib/transformers/hf_hub/constants.rb +71 -0
  12. data/lib/transformers/hf_hub/errors.rb +11 -0
  13. data/lib/transformers/hf_hub/file_download.rb +764 -0
  14. data/lib/transformers/hf_hub/utils/_errors.rb +94 -0
  15. data/lib/transformers/hf_hub/utils/_headers.rb +109 -0
  16. data/lib/transformers/image_processing_base.rb +169 -0
  17. data/lib/transformers/image_processing_utils.rb +63 -0
  18. data/lib/transformers/image_transforms.rb +208 -0
  19. data/lib/transformers/image_utils.rb +165 -0
  20. data/lib/transformers/modeling_outputs.rb +81 -0
  21. data/lib/transformers/modeling_utils.rb +888 -0
  22. data/lib/transformers/models/auto/auto_factory.rb +138 -0
  23. data/lib/transformers/models/auto/configuration_auto.rb +61 -0
  24. data/lib/transformers/models/auto/feature_extraction_auto.rb +20 -0
  25. data/lib/transformers/models/auto/image_processing_auto.rb +104 -0
  26. data/lib/transformers/models/auto/modeling_auto.rb +80 -0
  27. data/lib/transformers/models/auto/tokenization_auto.rb +160 -0
  28. data/lib/transformers/models/bert/configuration_bert.rb +65 -0
  29. data/lib/transformers/models/bert/modeling_bert.rb +836 -0
  30. data/lib/transformers/models/bert/tokenization_bert.rb +115 -0
  31. data/lib/transformers/models/bert/tokenization_bert_fast.rb +52 -0
  32. data/lib/transformers/models/distilbert/configuration_distilbert.rb +63 -0
  33. data/lib/transformers/models/distilbert/modeling_distilbert.rb +616 -0
  34. data/lib/transformers/models/distilbert/tokenization_distilbert.rb +114 -0
  35. data/lib/transformers/models/distilbert/tokenization_distilbert_fast.rb +71 -0
  36. data/lib/transformers/models/vit/configuration_vit.rb +60 -0
  37. data/lib/transformers/models/vit/image_processing_vit.rb +170 -0
  38. data/lib/transformers/models/vit/modeling_vit.rb +506 -0
  39. data/lib/transformers/pipelines/_init.rb +348 -0
  40. data/lib/transformers/pipelines/base.rb +301 -0
  41. data/lib/transformers/pipelines/feature_extraction.rb +47 -0
  42. data/lib/transformers/pipelines/image_classification.rb +110 -0
  43. data/lib/transformers/pipelines/image_feature_extraction.rb +56 -0
  44. data/lib/transformers/pipelines/pt_utils.rb +53 -0
  45. data/lib/transformers/pipelines/question_answering.rb +508 -0
  46. data/lib/transformers/pipelines/text_classification.rb +123 -0
  47. data/lib/transformers/pipelines/token_classification.rb +282 -0
  48. data/lib/transformers/ruby_utils.rb +33 -0
  49. data/lib/transformers/sentence_transformer.rb +37 -0
  50. data/lib/transformers/tokenization_utils.rb +152 -0
  51. data/lib/transformers/tokenization_utils_base.rb +937 -0
  52. data/lib/transformers/tokenization_utils_fast.rb +386 -0
  53. data/lib/transformers/torch_utils.rb +25 -0
  54. data/lib/transformers/utils/_init.rb +31 -0
  55. data/lib/transformers/utils/generic.rb +107 -0
  56. data/lib/transformers/utils/hub.rb +209 -0
  57. data/lib/transformers/utils/import_utils.rb +45 -0
  58. data/lib/transformers/utils/logging.rb +52 -0
  59. data/lib/transformers/version.rb +3 -0
  60. data/lib/transformers-rb.rb +1 -0
  61. data/lib/transformers.rb +100 -0
  62. data/licenses/LICENSE-huggingface-hub.txt +201 -0
  63. data/licenses/LICENSE-sentence-transformers.txt +201 -0
  64. data/licenses/NOTICE-sentence-transformers.txt +5 -0
  65. metadata +161 -0
@@ -0,0 +1,209 @@
1
+ # Copyright 2020 The HuggingFace Team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Transformers
16
+ module Utils
17
+ module Hub
18
+ IS_OFFLINE_MODE = HfHub::HF_HUB_OFFLINE
19
+
20
+ PYTORCH_PRETRAINED_BERT_CACHE = ENV.fetch("PYTORCH_PRETRAINED_BERT_CACHE", HfHub::HF_HUB_CACHE)
21
+ PYTORCH_TRANSFORMERS_CACHE = ENV.fetch("PYTORCH_TRANSFORMERS_CACHE", PYTORCH_PRETRAINED_BERT_CACHE)
22
+ TRANSFORMERS_CACHE = ENV.fetch("TRANSFORMERS_CACHE", PYTORCH_TRANSFORMERS_CACHE)
23
+
24
+ DEFAULT_ENDPOINT = "https://huggingface.co"
25
+ HUGGINGFACE_CO_RESOLVE_ENDPOINT = ENV.fetch("HF_ENDPOINT", DEFAULT_ENDPOINT)
26
+
27
+ class << self
28
+ def is_offline_mode
29
+ IS_OFFLINE_MODE
30
+ end
31
+
32
+ def is_remote_url(url_or_filename)
33
+ url_or_filename.is_a?(URI)
34
+ end
35
+
36
+ def http_user_agent(user_agent = nil)
37
+ ua = "transformers.rb/#{Transformers::VERSION}; ruby/#{RUBY_VERSION.to_f}"
38
+ if user_agent.is_a?(Hash)
39
+ ua += "; " + user_agent.map { |k, v| "#{k}/#{v}" }.join("; ")
40
+ elsif user_agent.is_a?(String)
41
+ ua += "; " + user_agent
42
+ end
43
+ ua
44
+ end
45
+
46
+ def extract_commit_hash(resolved_file, commit_hash)
47
+ if resolved_file.nil? || !commit_hash.nil?
48
+ return commit_hash
49
+ end
50
+ search = /snapshots\/([^\/]+)/.match(resolved_file)
51
+ if search.nil?
52
+ return nil
53
+ end
54
+ commit_hash = search[1]
55
+ HfHub::REGEX_COMMIT_HASH.match(commit_hash) ? commit_hash : nil
56
+ end
57
+
58
+ def cached_file(
59
+ path_or_repo_id,
60
+ filename,
61
+ cache_dir: nil,
62
+ force_download: false,
63
+ resume_download: false,
64
+ proxies: nil,
65
+ token: nil,
66
+ revision: nil,
67
+ local_files_only: false,
68
+ subfolder: "",
69
+ repo_type: nil,
70
+ user_agent: nil,
71
+ _raise_exceptions_for_gated_repo: true,
72
+ _raise_exceptions_for_missing_entries: true,
73
+ _raise_exceptions_for_connection_errors: true,
74
+ _commit_hash: nil,
75
+ **deprecated_kwargs
76
+ )
77
+ if is_offline_mode && !local_files_only
78
+ Transformers.logger.info "Offline mode: forcing local_files_only: true"
79
+ local_files_only = true
80
+ end
81
+ if subfolder.nil?
82
+ subfolder = ""
83
+ end
84
+
85
+ path_or_repo_id = path_or_repo_id.to_s
86
+ full_filename = File.join(subfolder, filename)
87
+ if Dir.exist?(path_or_repo_id)
88
+ raise Todo
89
+ end
90
+
91
+ if cache_dir.nil?
92
+ cache_dir = TRANSFORMERS_CACHE
93
+ end
94
+ if cache_dir.is_a?(Pathname)
95
+ cache_dir = cache_dir.to_s
96
+ end
97
+
98
+ if !_commit_hash.nil? && !force_download
99
+ # If the file is cached under that commit hash, we return it directly.
100
+ resolved_file =
101
+ HfHub.try_to_load_from_cache(
102
+ path_or_repo_id, full_filename, cache_dir: cache_dir, revision: _commit_hash, repo_type: repo_type
103
+ )
104
+ if !resolved_file.nil?
105
+ if resolved_file != HfHub::CACHED_NO_EXIST
106
+ return resolved_file
107
+ elsif !_raise_exceptions_for_missing_entries
108
+ return nil
109
+ else
110
+ raise EnvironmentError, "Could not locate #{full_filename} inside #{path_or_repo_id}."
111
+ end
112
+ end
113
+ end
114
+
115
+ user_agent = http_user_agent(user_agent)
116
+
117
+ resolved_file = nil
118
+ begin
119
+ resolved_file =
120
+ HfHub.hf_hub_download(
121
+ path_or_repo_id,
122
+ filename,
123
+ subfolder: subfolder.length == 0 ? nil : subfolder,
124
+ repo_type: repo_type,
125
+ revision: revision,
126
+ cache_dir: cache_dir,
127
+ user_agent: user_agent,
128
+ force_download: force_download,
129
+ proxies: proxies,
130
+ resume_download: resume_download,
131
+ token: token,
132
+ local_files_only: local_files_only
133
+ )
134
+ rescue => e
135
+ raise e if _raise_exceptions_for_missing_entries
136
+ end
137
+ resolved_file
138
+ end
139
+
140
+ def has_file(
141
+ path_or_repo,
142
+ filename,
143
+ revision: nil,
144
+ proxies: nil,
145
+ token: nil,
146
+ local_files_only: false,
147
+ cache_dir: nil,
148
+ repo_type: nil,
149
+ **deprecated_kwargs
150
+ )
151
+ # If path to local directory, check if the file exists
152
+ if Dir.exist?(path_or_repo)
153
+ return File.exist?(File.join(path_or_repo, filename))
154
+ end
155
+
156
+ # Else it's a repo => let's check if the file exists in local cache or on the Hub
157
+
158
+ # Check if file exists in cache
159
+ # This information might be outdated so it's best to also make a HEAD call (if allowed).
160
+ cached_path = HfHub.try_to_load_from_cache(
161
+ path_or_repo,
162
+ filename,
163
+ revision: revision,
164
+ repo_type: repo_type,
165
+ cache_dir: cache_dir
166
+ )
167
+ has_file_in_cache = cached_path.is_a?(String)
168
+
169
+ # If local_files_only, don't try the HEAD call
170
+ if local_files_only
171
+ return has_file_in_cache
172
+ end
173
+
174
+ # Check if the file exists
175
+ begin
176
+ HfHub._request_wrapper(
177
+ "HEAD",
178
+ HfHub.hf_hub_url(path_or_repo, filename, revision: revision, repo_type: repo_type),
179
+ headers: HfHub.build_hf_headers(token: token, user_agent: http_user_agent),
180
+ allow_redirects: false,
181
+ proxies: proxies,
182
+ timeout: 10
183
+ )
184
+ return true
185
+ rescue HfHub::OfflineModeIsEnabled
186
+ return has_file_in_cache
187
+ rescue HfHub::GatedRepoError => e
188
+ Transformers.logger.error(e)
189
+ raise EnvironmentError,
190
+ "#{path_or_repo} is a gated repository. Make sure to request access at " +
191
+ "https://huggingface.co/#{path_or_repo} and pass a token having permission to this repo either by " +
192
+ "logging in with `huggingface-cli login` or by passing `token=<your_token>`."
193
+ rescue HfHub::RepositoryNotFoundError => e
194
+ Transformers.logger.error(e)
195
+ raise EnvironmentError,
196
+ "#{path_or_repo} is not a local folder or a valid repository name on 'https://hf.co'."
197
+ rescue HfHub::RevisionNotFoundError => e
198
+ Transformers.logger.error(e)
199
+ raise EnvironmentError,
200
+ "#{revision} is not a valid git identifier (branch name, tag name or commit id) that exists for this " +
201
+ "model name. Check the model page at 'https://huggingface.co/#{path_or_repo}' for available revisions."
202
+ rescue HfHub::EntryNotFoundError
203
+ return false # File does not exist
204
+ end
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,45 @@
1
+ # Copyright 2022 The HuggingFace Team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Transformers
16
+ module Utils
17
+ ENV_VARS_TRUE_VALUES = ["1", "ON", "YES", "TRUE"]
18
+
19
+ def self.requires_backends(obj, backends)
20
+ if !backends.is_a?(Array)
21
+ backends = [backends]
22
+ end
23
+
24
+ name = obj.is_a?(Symbol) ? obj : obj.class.name
25
+
26
+ checks = backends.map { |backend| BACKENDS_MAPPING.fetch(backend) }
27
+ failed = checks.filter_map { |available, msg| format(msg, name) if !available.call }
28
+ if failed.any?
29
+ raise Error, failed.join("")
30
+ end
31
+ end
32
+
33
+ def self.is_vision_available
34
+ defined?(Vips)
35
+ end
36
+
37
+ VISION_IMPORT_ERROR = <<~MSG
38
+ %s requires the `ruby-vips` gem
39
+ MSG
40
+
41
+ BACKENDS_MAPPING = {
42
+ "vision" => [singleton_method(:is_vision_available), VISION_IMPORT_ERROR]
43
+ }
44
+ end
45
+ end
@@ -0,0 +1,52 @@
1
+ # Copyright 2020 Optuna, Hugging Face
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Transformers
16
+ class << self
17
+ attr_accessor :logger
18
+ end
19
+
20
+ # TODO add detail
21
+ LOG_LEVELS = {
22
+ "debug" => Logger::DEBUG,
23
+ "info" => Logger::INFO,
24
+ "warning" => Logger::WARN,
25
+ "error" => Logger::ERROR,
26
+ "critical" => Logger::FATAL
27
+ }
28
+
29
+ DEFAULT_LOG_LEVEL = Logger::WARN
30
+
31
+ def self._get_default_logging_level
32
+ env_level_str = ENV["TRANSFORMERS_VERBOSITY"]
33
+ if env_level_str
34
+ if LOG_LEVELS.include?(env_level_str)
35
+ return LOG_LEVELS[env_level_str]
36
+ else
37
+ warn(
38
+ "Unknown option TRANSFORMERS_VERBOSITY=#{env_level_str}, " +
39
+ "has to be one of: #{LOG_LEVELS.keys.join(", ")}"
40
+ )
41
+ end
42
+ end
43
+ DEFAULT_LOG_LEVEL
44
+ end
45
+
46
+ self.logger = begin
47
+ logger = Logger.new(STDERR)
48
+ logger.level = _get_default_logging_level
49
+ logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }
50
+ logger
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Transformers
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1 @@
1
+ require_relative "transformers"
@@ -0,0 +1,100 @@
1
+ # dependencies
2
+ require "numo/narray"
3
+ require "safetensors"
4
+ require "tokenizers"
5
+ require "torch-rb"
6
+
7
+ # stdlib
8
+ require "cgi"
9
+ require "fileutils"
10
+ require "io/console"
11
+ require "json"
12
+ require "logger"
13
+ require "net/http"
14
+ require "pathname"
15
+ require "securerandom"
16
+ require "set"
17
+ require "uri"
18
+
19
+ # modules
20
+ require_relative "transformers/ruby_utils"
21
+ require_relative "transformers/utils/generic"
22
+ require_relative "transformers/activations"
23
+ require_relative "transformers/dynamic_module_utils"
24
+ require_relative "transformers/configuration_utils"
25
+ require_relative "transformers/convert_slow_tokenizer"
26
+ require_relative "transformers/feature_extraction_utils"
27
+ require_relative "transformers/image_utils"
28
+ require_relative "transformers/image_processing_base"
29
+ require_relative "transformers/image_processing_utils"
30
+ require_relative "transformers/image_transforms"
31
+ require_relative "transformers/modeling_outputs"
32
+ require_relative "transformers/modeling_utils"
33
+ require_relative "transformers/sentence_transformer"
34
+ require_relative "transformers/tokenization_utils_base"
35
+ require_relative "transformers/tokenization_utils"
36
+ require_relative "transformers/tokenization_utils_fast"
37
+ require_relative "transformers/torch_utils"
38
+ require_relative "transformers/version"
39
+
40
+ # data
41
+ require_relative "transformers/data/processors/squad"
42
+
43
+ # hub
44
+ require_relative "transformers/hf_hub/constants"
45
+ require_relative "transformers/hf_hub/errors"
46
+ require_relative "transformers/hf_hub/file_download"
47
+ require_relative "transformers/hf_hub/utils/_errors"
48
+ require_relative "transformers/hf_hub/utils/_headers"
49
+
50
+ # models auto
51
+ require_relative "transformers/models/auto/auto_factory"
52
+ require_relative "transformers/models/auto/configuration_auto"
53
+ require_relative "transformers/models/auto/feature_extraction_auto"
54
+ require_relative "transformers/models/auto/image_processing_auto"
55
+ require_relative "transformers/models/auto/modeling_auto"
56
+ require_relative "transformers/models/auto/tokenization_auto"
57
+
58
+ # models bert
59
+ require_relative "transformers/models/bert/configuration_bert"
60
+ require_relative "transformers/models/bert/modeling_bert"
61
+ require_relative "transformers/models/bert/tokenization_bert"
62
+ require_relative "transformers/models/bert/tokenization_bert_fast"
63
+
64
+ # models distilbert
65
+ require_relative "transformers/models/distilbert/configuration_distilbert"
66
+ require_relative "transformers/models/distilbert/modeling_distilbert"
67
+ require_relative "transformers/models/distilbert/tokenization_distilbert"
68
+ require_relative "transformers/models/distilbert/tokenization_distilbert_fast"
69
+
70
+ # models vit
71
+ require_relative "transformers/models/vit/configuration_vit"
72
+ require_relative "transformers/models/vit/image_processing_vit"
73
+ require_relative "transformers/models/vit/modeling_vit"
74
+
75
+ # pipelines
76
+ require_relative "transformers/pipelines/base"
77
+ require_relative "transformers/pipelines/feature_extraction"
78
+ require_relative "transformers/pipelines/image_classification"
79
+ require_relative "transformers/pipelines/image_feature_extraction"
80
+ require_relative "transformers/pipelines/pt_utils"
81
+ require_relative "transformers/pipelines/question_answering"
82
+ require_relative "transformers/pipelines/text_classification"
83
+ require_relative "transformers/pipelines/token_classification"
84
+ require_relative "transformers/pipelines/_init"
85
+
86
+ # utils
87
+ require_relative "transformers/utils/_init"
88
+ require_relative "transformers/utils/import_utils"
89
+ require_relative "transformers/utils/hub"
90
+ require_relative "transformers/utils/logging"
91
+
92
+ module Transformers
93
+ class Error < StandardError; end
94
+
95
+ class Todo < Error
96
+ def message
97
+ "not implemented yet"
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.