informers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +202 -0
- data/README.md +141 -0
- data/lib/informers.rb +9 -0
- data/lib/informers/ner.rb +91 -0
- data/lib/informers/question_answering.rb +185 -0
- data/lib/informers/sentiment_analysis.rb +56 -0
- data/lib/informers/version.rb +3 -0
- data/vendor/LICENSE-bert.txt +202 -0
- data/vendor/LICENSE-blingfire.txt +21 -0
- data/vendor/bert_base_cased_tok.bin +0 -0
- data/vendor/bert_base_tok.bin +0 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 74b7334319b613d6dc9f971572be978fe94d5ab09322e97ea88a5272b4255bd6
|
4
|
+
data.tar.gz: f2aa44acfffb821466c5ffb1a649abb1c1a1769069eaa91109a3892f2c2e3ab0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4375bc4eb4f92266398a8e88690cb2375072ca1e5a496998e375ff7f0ee0a4f59f48c2bc1b032f0d19d536834c0a6cd51e1f4d9ef90140ecebf934322d049f76
|
7
|
+
data.tar.gz: 3a602c56b2112cefce24c13d1c4efe45393d402d0c535d3d21d3682172e498f623087db1e2aebaac787a47ce5f82301c859c1899bf8900112d055a7f402ec610
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# Informers
|
2
|
+
|
3
|
+
:slightly_smiling_face: State-of-the-art natural language processing for Ruby
|
4
|
+
|
5
|
+
Supports:
|
6
|
+
|
7
|
+
- Sentiment analysis
|
8
|
+
- Question answering
|
9
|
+
- Named-entity recognition
|
10
|
+
- Text generation - *in development*
|
11
|
+
- Summarization - *in development*
|
12
|
+
- Translation - *in development*
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application’s Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'informers'
|
20
|
+
```
|
21
|
+
|
22
|
+
On Mac, also install OpenMP:
|
23
|
+
|
24
|
+
```sh
|
25
|
+
brew install libomp
|
26
|
+
```
|
27
|
+
|
28
|
+
## Getting Started
|
29
|
+
|
30
|
+
- [Sentiment analysis](#sentiment-analysis)
|
31
|
+
- [Question answering](#question-answering)
|
32
|
+
- [Named-entity recognition](#named-entity-recognition)
|
33
|
+
|
34
|
+
### Sentiment Analysis
|
35
|
+
|
36
|
+
First, download the [pretrained model](sentiment.onnx).
|
37
|
+
|
38
|
+
Predict sentiment
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
model = Informers::SentimentAnalysis.new("sentiment-analysis.onnx")
|
42
|
+
model.predict("This is super cool")
|
43
|
+
```
|
44
|
+
|
45
|
+
This returns
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
{label: "positive", score: 0.999855186578301}
|
49
|
+
```
|
50
|
+
|
51
|
+
Predict multiple at once
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
model.predict(["This is super cool", "I didn't like it"])
|
55
|
+
```
|
56
|
+
|
57
|
+
### Question Answering
|
58
|
+
|
59
|
+
First, download the [pretrained model](question-answering.onnx) and add Numo to your application’s Gemfile:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
gem 'numo-narray'
|
63
|
+
```
|
64
|
+
|
65
|
+
Ask a question with some context
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
model = Informers::QuestionAnswering.new("question-answering.onnx")
|
69
|
+
model.predict(question: "Who invented Ruby?", context: "Ruby is a programming language created by Matz")
|
70
|
+
```
|
71
|
+
|
72
|
+
This returns
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
{answer: "Matz", score: 0.9980658360049758, start: 42, end: 46}
|
76
|
+
```
|
77
|
+
|
78
|
+
### Named-Entity Recognition
|
79
|
+
|
80
|
+
First, export the [pretrained model](tools/export.md).
|
81
|
+
|
82
|
+
Get entities
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
model = Informers::NER.new("ner.onnx")
|
86
|
+
model.predict("Nat works at GitHub in San Francisco")
|
87
|
+
```
|
88
|
+
|
89
|
+
This returns
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
[
|
93
|
+
{text: "Nat", tag: "person", score: 0.9840519576513487, start: 0, end: 3},
|
94
|
+
{text: "GitHub", tag: "org", score: 0.9426134775785775, start: 13, end: 19},
|
95
|
+
{text: "San Francisco", tag: "location", score: 0.9952414982243061, start: 23, end: 36}
|
96
|
+
]
|
97
|
+
```
|
98
|
+
|
99
|
+
## Models
|
100
|
+
|
101
|
+
Task | Description | Contributor | License | Link
|
102
|
+
--- | --- | --- | --- | ---
|
103
|
+
Sentiment analysis | DistilBERT fine-tuned on SST-2 | Hugging Face | Apache-2.0 | [Link](https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english)
|
104
|
+
Question answering | DistilBERT | Hugging Face | Apache-2.0 | [Link](https://huggingface.co/distilbert-base-cased-distilled-squad)
|
105
|
+
Named-entity recognition | BERT fine-tuned on CoNLL03 | Bayerische Staatsbibliothek | In-progress | [Link](https://huggingface.co/dbmdz/bert-large-cased-finetuned-conll03-english)
|
106
|
+
|
107
|
+
Models are [quantized](https://medium.com/microsoftazure/faster-and-smaller-quantized-nlp-with-hugging-face-and-onnx-runtime-ec5525473bb7) to make them faster and smaller.
|
108
|
+
|
109
|
+
## Credits
|
110
|
+
|
111
|
+
This project uses many state-of-the-art technologies:
|
112
|
+
|
113
|
+
- [Transformers](https://github.com/huggingface/transformers) for transformer models
|
114
|
+
- [BlingFire](https://github.com/microsoft/BlingFire) and [BERT](https://github.com/google-research/bert) for high-performance text tokenization
|
115
|
+
- [ONNX Runtime](https://github.com/Microsoft/onnxruntime) for high-performance inference
|
116
|
+
|
117
|
+
Some code was ported from Transformers and is available under the same license.
|
118
|
+
|
119
|
+
## History
|
120
|
+
|
121
|
+
View the [changelog](https://github.com/ankane/informers/blob/master/CHANGELOG.md)
|
122
|
+
|
123
|
+
## Contributing
|
124
|
+
|
125
|
+
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
126
|
+
|
127
|
+
- [Report bugs](https://github.com/ankane/informers/issues)
|
128
|
+
- Fix bugs and [submit pull requests](https://github.com/ankane/informers/pulls)
|
129
|
+
- Write, clarify, or fix documentation
|
130
|
+
- Suggest or add new features
|
131
|
+
|
132
|
+
To get started with development:
|
133
|
+
|
134
|
+
```sh
|
135
|
+
git clone https://github.com/ankane/informers.git
|
136
|
+
cd informers
|
137
|
+
bundle install
|
138
|
+
|
139
|
+
export MODELS_PATH=path/to/onnx/models
|
140
|
+
bundle exec rake test
|
141
|
+
```
|
data/lib/informers.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
module Informers
|
2
|
+
class NER
|
3
|
+
def initialize(model_path)
|
4
|
+
tokenizer_path = File.expand_path("../../vendor/bert_base_cased_tok.bin", __dir__)
|
5
|
+
@tokenizer = BlingFire.load_model(tokenizer_path)
|
6
|
+
@model = OnnxRuntime::Model.new(model_path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def predict(texts)
|
10
|
+
singular = !texts.is_a?(Array)
|
11
|
+
texts = [texts] if singular
|
12
|
+
|
13
|
+
result = []
|
14
|
+
texts.each do |text|
|
15
|
+
# tokenize
|
16
|
+
tokens, start_offsets, end_offsets = @tokenizer.text_to_ids_with_offsets(text, nil, 100) # unk token
|
17
|
+
tokens.unshift(101) # cls token
|
18
|
+
tokens << 102 # sep token
|
19
|
+
|
20
|
+
# infer
|
21
|
+
input = {
|
22
|
+
input_ids: [tokens],
|
23
|
+
attention_mask: [[1] * tokens.size],
|
24
|
+
token_type_ids: [[0] * tokens.size]
|
25
|
+
}
|
26
|
+
output = @model.predict(input)
|
27
|
+
|
28
|
+
# transform
|
29
|
+
entities = output["output_0"][0]
|
30
|
+
score =
|
31
|
+
entities.map do |e|
|
32
|
+
values = e.map { |v| Math.exp(v) }
|
33
|
+
sum = values.sum
|
34
|
+
values.map { |v| v / sum }
|
35
|
+
end
|
36
|
+
|
37
|
+
labels_idx = score.map { |s| s.each_with_index.max[1] }
|
38
|
+
labels = ["O", "B-MISC", "I-MISC", "B-PER", "I-PER", "B-ORG", "I-ORG", "B-LOC", "I-LOC"]
|
39
|
+
|
40
|
+
entities = []
|
41
|
+
filtered_label_idx = labels_idx.map.with_index.reject { |v, i| v == 0 }
|
42
|
+
filtered_label_idx.each do |label_idx, idx|
|
43
|
+
entities << {
|
44
|
+
score: score[idx][label_idx],
|
45
|
+
entity: labels[label_idx],
|
46
|
+
index: idx
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
result << group_entities(entities, text, start_offsets, end_offsets)
|
51
|
+
end
|
52
|
+
|
53
|
+
singular ? result.first : result
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def group_entities(entities, text, start_offsets, end_offsets)
|
59
|
+
last_entity = {}
|
60
|
+
groups = []
|
61
|
+
entities.each do |entity|
|
62
|
+
if entity[:index] - 1 == last_entity[:index] && entity[:entity] == last_entity[:entity]
|
63
|
+
groups.last << entity
|
64
|
+
else
|
65
|
+
groups << [entity]
|
66
|
+
end
|
67
|
+
last_entity = entity
|
68
|
+
end
|
69
|
+
|
70
|
+
entity_map = {
|
71
|
+
"I-PER" => "person",
|
72
|
+
"I-ORG" => "org",
|
73
|
+
"I-LOC" => "location",
|
74
|
+
"I-MIS" => "misc"
|
75
|
+
}
|
76
|
+
|
77
|
+
groups.map do |group|
|
78
|
+
start_offset = start_offsets[group.first[:index] - 1]
|
79
|
+
end_offset = end_offsets[group.last[:index] - 1]
|
80
|
+
|
81
|
+
{
|
82
|
+
text: text[start_offset...end_offset],
|
83
|
+
tag: entity_map[group.first[:entity]],
|
84
|
+
score: group.map { |v| v[:score] }.sum / group.size,
|
85
|
+
start: start_offset,
|
86
|
+
end: end_offset
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
module Informers
|
2
|
+
class QuestionAnswering
|
3
|
+
def initialize(model_path)
|
4
|
+
# make sure Numo is available
|
5
|
+
require "numo/narray"
|
6
|
+
|
7
|
+
tokenizer_path = File.expand_path("../../vendor/bert_base_cased_tok.bin", __dir__)
|
8
|
+
@tokenizer = BlingFire.load_model(tokenizer_path)
|
9
|
+
@model = OnnxRuntime::Model.new(model_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def predict(questions)
|
13
|
+
singular = !questions.is_a?(Array)
|
14
|
+
questions = [questions] if singular
|
15
|
+
|
16
|
+
topk = 1
|
17
|
+
max_answer_len = 15
|
18
|
+
|
19
|
+
sep_pos = []
|
20
|
+
cls_pos = []
|
21
|
+
context_offsets = []
|
22
|
+
|
23
|
+
# tokenize
|
24
|
+
input_ids =
|
25
|
+
questions.map do |question|
|
26
|
+
tokens = @tokenizer.text_to_ids(question[:question], nil, 100) # unk token
|
27
|
+
sep_pos << tokens.size
|
28
|
+
tokens << 102 # sep token
|
29
|
+
context_tokens, offsets = @tokenizer.text_to_ids_with_offsets(question[:context], nil, 100) # unk token
|
30
|
+
tokens.concat(context_tokens)
|
31
|
+
context_offsets << offsets
|
32
|
+
cls_pos << tokens.size
|
33
|
+
tokens.unshift(101) # cls token
|
34
|
+
tokens << 102 # sep token
|
35
|
+
tokens
|
36
|
+
end
|
37
|
+
|
38
|
+
max_tokens = 384
|
39
|
+
raise "Large text not supported yet" if input_ids.map(&:size).max > max_tokens
|
40
|
+
|
41
|
+
attention_mask = []
|
42
|
+
input_ids.each do |ids|
|
43
|
+
zeros = [0] * (max_tokens - ids.size)
|
44
|
+
|
45
|
+
mask = ([1] * ids.size) + zeros
|
46
|
+
attention_mask << mask
|
47
|
+
|
48
|
+
ids.concat(zeros)
|
49
|
+
end
|
50
|
+
|
51
|
+
# infer
|
52
|
+
input = {
|
53
|
+
input_ids: input_ids,
|
54
|
+
attention_mask: attention_mask
|
55
|
+
}
|
56
|
+
output = @model.predict(input)
|
57
|
+
|
58
|
+
start = output["output_0"]
|
59
|
+
stop = output["output_1"]
|
60
|
+
|
61
|
+
# transform
|
62
|
+
answers = []
|
63
|
+
start.zip(stop).each_with_index do |(start_, end_), i|
|
64
|
+
start_ = Numo::DFloat.cast(start_)
|
65
|
+
end_ = Numo::DFloat.cast(end_)
|
66
|
+
|
67
|
+
# Ensure padded tokens & question tokens cannot belong to the set of candidate answers.
|
68
|
+
feature_p_mask = Numo::Int64.new(max_tokens).fill(0)
|
69
|
+
feature_p_mask[1..sep_pos[i] + 1] = 1
|
70
|
+
feature_p_mask[cls_pos[i][1]] = 1
|
71
|
+
feature_attention_mask = Numo::Int64.cast(attention_mask[i])
|
72
|
+
undesired_tokens = (feature_p_mask - 1).abs & feature_attention_mask
|
73
|
+
|
74
|
+
# Generate mask
|
75
|
+
undesired_tokens_mask = undesired_tokens.eq(0)
|
76
|
+
|
77
|
+
# Make sure non-context indexes in the tensor cannot contribute to the softmax
|
78
|
+
start_[undesired_tokens_mask] = -10000
|
79
|
+
end_[undesired_tokens_mask] = -10000
|
80
|
+
|
81
|
+
# Normalize logits and spans to retrieve the answer
|
82
|
+
start_ = Numo::DFloat::Math.exp(start_ - Numo::DFloat::Math.log(Numo::DFloat::Math.exp(start_).sum(axis: -1)))
|
83
|
+
end_ = Numo::DFloat::Math.exp(end_ - Numo::DFloat::Math.log(Numo::DFloat::Math.exp(end_).sum(axis: -1)))
|
84
|
+
|
85
|
+
# Mask CLS
|
86
|
+
start_[0] = end_[0] = 0.0
|
87
|
+
|
88
|
+
starts, ends, scores = decode(start_, end_, topk, max_answer_len)
|
89
|
+
|
90
|
+
# char_to_word
|
91
|
+
doc_tokens, char_to_word_offset = self.doc_tokens(questions[i][:context])
|
92
|
+
char_to_word = Numo::Int64.cast(char_to_word_offset)
|
93
|
+
|
94
|
+
# token_to_orig_map
|
95
|
+
token_to_orig_map = {}
|
96
|
+
map_pos = sep_pos[i] + 2
|
97
|
+
context_offsets[i].each do |offset|
|
98
|
+
token_to_orig_map[map_pos] = char_to_word_offset[offset]
|
99
|
+
map_pos += 1
|
100
|
+
end
|
101
|
+
|
102
|
+
# Convert the answer (tokens) back to the original text
|
103
|
+
starts.to_a.zip(ends.to_a, scores) do |s, e, score|
|
104
|
+
answers << {
|
105
|
+
answer: doc_tokens[token_to_orig_map[s]..token_to_orig_map[e]].join(" "),
|
106
|
+
score: score,
|
107
|
+
start: (char_to_word.eq(token_to_orig_map[s])).where[0],
|
108
|
+
end: (char_to_word.eq(token_to_orig_map[e])).where[-1]
|
109
|
+
}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
singular ? answers.first : answers
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def decode(start, stop, topk, max_answer_len)
|
119
|
+
# Ensure we have batch axis
|
120
|
+
if start.ndim == 1
|
121
|
+
start = start.expand_dims(0)
|
122
|
+
end
|
123
|
+
|
124
|
+
if stop.ndim == 1
|
125
|
+
stop = stop.expand_dims(0)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Compute the score of each tuple(start, end) to be the real answer
|
129
|
+
outer = start.expand_dims(-1).dot(stop.expand_dims(1))
|
130
|
+
|
131
|
+
# Remove candidate with end < start and end - start > max_answer_len
|
132
|
+
candidates = outer.triu.tril(max_answer_len - 1)
|
133
|
+
|
134
|
+
# Inspired by Chen & al. (https://github.com/facebookresearch/DrQA)
|
135
|
+
scores_flat = candidates.flatten
|
136
|
+
if topk == 1
|
137
|
+
idx_sort = [scores_flat.argmax]
|
138
|
+
else
|
139
|
+
raise "Not implemented yet"
|
140
|
+
end
|
141
|
+
|
142
|
+
start, stop = unravel_index(idx_sort, candidates.shape)[1..-1]
|
143
|
+
[start, stop, candidates[0, start, stop]]
|
144
|
+
end
|
145
|
+
|
146
|
+
def unravel_index(indices, shape)
|
147
|
+
indices = Numo::NArray.cast(indices)
|
148
|
+
result = []
|
149
|
+
factor = 1
|
150
|
+
shape.size.times do |i|
|
151
|
+
result.unshift(indices / factor % shape[-1 - i])
|
152
|
+
factor *= shape[-1 - i]
|
153
|
+
end
|
154
|
+
result
|
155
|
+
end
|
156
|
+
|
157
|
+
def doc_tokens(text)
|
158
|
+
doc_tokens = []
|
159
|
+
char_to_word_offset = []
|
160
|
+
prev_is_whitespace = true
|
161
|
+
|
162
|
+
text.each_char do |c|
|
163
|
+
if whitespace?(c)
|
164
|
+
prev_is_whitespace = true
|
165
|
+
else
|
166
|
+
if prev_is_whitespace
|
167
|
+
doc_tokens << c
|
168
|
+
else
|
169
|
+
doc_tokens[-1] += c
|
170
|
+
end
|
171
|
+
prev_is_whitespace = false
|
172
|
+
end
|
173
|
+
char_to_word_offset << (doc_tokens.size - 1)
|
174
|
+
end
|
175
|
+
# ensure end is correct when answer includes last token
|
176
|
+
char_to_word_offset << (doc_tokens.size - 1)
|
177
|
+
|
178
|
+
[doc_tokens, char_to_word_offset]
|
179
|
+
end
|
180
|
+
|
181
|
+
def whitespace?(c)
|
182
|
+
c == " " || c == "\t" || c == "\r" || c == "\n" || c.ord == 0x202F
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Informers
|
2
|
+
class SentimentAnalysis
|
3
|
+
def initialize(model_path)
|
4
|
+
tokenizer_path = File.expand_path("../../vendor/bert_base_tok.bin", __dir__)
|
5
|
+
@tokenizer = BlingFire.load_model(tokenizer_path)
|
6
|
+
@model = OnnxRuntime::Model.new(model_path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def predict(texts)
|
10
|
+
singular = !texts.is_a?(Array)
|
11
|
+
texts = [texts] if singular
|
12
|
+
|
13
|
+
# tokenize
|
14
|
+
input_ids =
|
15
|
+
texts.map do |text|
|
16
|
+
tokens = @tokenizer.text_to_ids(text, nil, 100) # unk token
|
17
|
+
tokens.unshift(101) # cls token
|
18
|
+
tokens << 102 # sep token
|
19
|
+
tokens
|
20
|
+
end
|
21
|
+
|
22
|
+
max_tokens = input_ids.map(&:size).max
|
23
|
+
attention_mask = []
|
24
|
+
input_ids.each do |ids|
|
25
|
+
zeros = [0] * (max_tokens - ids.size)
|
26
|
+
|
27
|
+
mask = ([1] * ids.size) + zeros
|
28
|
+
attention_mask << mask
|
29
|
+
|
30
|
+
ids.concat(zeros)
|
31
|
+
end
|
32
|
+
|
33
|
+
# infer
|
34
|
+
input = {
|
35
|
+
input_ids: input_ids,
|
36
|
+
attention_mask: attention_mask
|
37
|
+
}
|
38
|
+
output = @model.predict(input)
|
39
|
+
|
40
|
+
# transform
|
41
|
+
scores =
|
42
|
+
output["output_0"].map do |row|
|
43
|
+
mapped = row.map { |v| Math.exp(v) }
|
44
|
+
sum = mapped.sum
|
45
|
+
mapped.map { |v| v / sum }
|
46
|
+
end
|
47
|
+
|
48
|
+
labels = ["negative", "positive"]
|
49
|
+
scores.map! do |item|
|
50
|
+
{label: labels[item.each_with_index.max[1]], score: item.max}
|
51
|
+
end
|
52
|
+
|
53
|
+
singular ? scores.first : scores
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: informers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kane
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: blingfire
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: onnxruntime
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: numo-narray
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email: andrew@chartkick.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- CHANGELOG.md
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- lib/informers.rb
|
107
|
+
- lib/informers/ner.rb
|
108
|
+
- lib/informers/question_answering.rb
|
109
|
+
- lib/informers/sentiment_analysis.rb
|
110
|
+
- lib/informers/version.rb
|
111
|
+
- vendor/LICENSE-bert.txt
|
112
|
+
- vendor/LICENSE-blingfire.txt
|
113
|
+
- vendor/bert_base_cased_tok.bin
|
114
|
+
- vendor/bert_base_tok.bin
|
115
|
+
homepage: https://github.com/ankane/informers
|
116
|
+
licenses:
|
117
|
+
- Apache-2.0
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '2.5'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubygems_version: 3.1.2
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: State-of-the-art natural language processing for Ruby
|
138
|
+
test_files: []
|