informers 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +123 -0
- data/lib/informers/configs.rb +10 -8
- data/lib/informers/model.rb +2 -9
- data/lib/informers/models.rb +997 -12
- data/lib/informers/pipelines.rb +768 -8
- data/lib/informers/processors.rb +796 -0
- data/lib/informers/tokenizers.rb +154 -4
- data/lib/informers/utils/core.rb +4 -0
- data/lib/informers/utils/generation.rb +294 -0
- data/lib/informers/utils/image.rb +116 -0
- data/lib/informers/utils/math.rb +73 -0
- data/lib/informers/utils/tensor.rb +46 -0
- data/lib/informers/version.rb +1 -1
- data/lib/informers.rb +3 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab4f19adb4d6ca0289784cee6c6cb5235b73a5184abffbeaf44391768be1f0ac
|
4
|
+
data.tar.gz: '0880ce4dced5ce47ceaaa5fee8d10e6324b3fc0a23e05c3da3728414dcc273d9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb3ee6d16e4e20eca6fae3fae8f97d78ba6bb655d48e2012640d64538785e2a9ff2afb10269cf01db928553438e8fbd08584774ba3f3d08bc25f36cbb971a99a
|
7
|
+
data.tar.gz: '0008441293f2605ec8599135d715093053e21f67f56ba59b730a3bc1f46f04f4a7fabb7fef039f156cd4183011c93b7fc9cab6ba731bf78627244bc4dedcf18d'
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -240,6 +240,12 @@ The model must include a `.onnx` file ([example](https://huggingface.co/Xenova/a
|
|
240
240
|
|
241
241
|
## Pipelines
|
242
242
|
|
243
|
+
- [Text](#text)
|
244
|
+
- [Vision](#vision)
|
245
|
+
- [Multimodel](#multimodal)
|
246
|
+
|
247
|
+
### Text
|
248
|
+
|
243
249
|
Embedding
|
244
250
|
|
245
251
|
```ruby
|
@@ -275,6 +281,48 @@ qa = Informers.pipeline("question-answering")
|
|
275
281
|
qa.("Who invented Ruby?", "Ruby is a programming language created by Matz")
|
276
282
|
```
|
277
283
|
|
284
|
+
Zero-shot classification
|
285
|
+
|
286
|
+
```ruby
|
287
|
+
classifier = Informers.pipeline("zero-shot-classification")
|
288
|
+
classifier.("text", ["label1", "label2", "label3"])
|
289
|
+
```
|
290
|
+
|
291
|
+
Text generation
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
generator = Informers.pipeline("text-generation")
|
295
|
+
generator.("I enjoy walking with my cute dog,")
|
296
|
+
```
|
297
|
+
|
298
|
+
Text-to-text generation
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
text2text = Informers.pipeline("text2text-generation")
|
302
|
+
text2text.("translate from English to French: I'm very happy")
|
303
|
+
```
|
304
|
+
|
305
|
+
Translation
|
306
|
+
|
307
|
+
```ruby
|
308
|
+
translator = Informers.pipeline("translation", "Xenova/nllb-200-distilled-600M")
|
309
|
+
translator.("जीवन एक चॉकलेट बॉक्स की तरह है।", src_lang: "hin_Deva", tgt_lang: "fra_Latn")
|
310
|
+
```
|
311
|
+
|
312
|
+
Summarization
|
313
|
+
|
314
|
+
```ruby
|
315
|
+
summarizer = Informers.pipeline("summarization")
|
316
|
+
summarizer.("Many paragraphs of text")
|
317
|
+
```
|
318
|
+
|
319
|
+
Fill mask
|
320
|
+
|
321
|
+
```ruby
|
322
|
+
unmasker = Informers.pipeline("fill-mask")
|
323
|
+
unmasker.("Paris is the [MASK] of France.")
|
324
|
+
```
|
325
|
+
|
278
326
|
Feature extraction
|
279
327
|
|
280
328
|
```ruby
|
@@ -282,6 +330,80 @@ extractor = Informers.pipeline("feature-extraction")
|
|
282
330
|
extractor.("We are very happy to show you the 🤗 Transformers library.")
|
283
331
|
```
|
284
332
|
|
333
|
+
### Vision
|
334
|
+
|
335
|
+
Image classification
|
336
|
+
|
337
|
+
```ruby
|
338
|
+
classifier = Informers.pipeline("image-classification")
|
339
|
+
classifier.("image.jpg")
|
340
|
+
```
|
341
|
+
|
342
|
+
Zero-shot image classification
|
343
|
+
|
344
|
+
```ruby
|
345
|
+
classifier = Informers.pipeline("zero-shot-image-classification")
|
346
|
+
classifier.("image.jpg", ["label1", "label2", "label3"])
|
347
|
+
```
|
348
|
+
|
349
|
+
Image segmentation
|
350
|
+
|
351
|
+
```ruby
|
352
|
+
segmenter = Informers.pipeline("image-segmentation")
|
353
|
+
segmenter.("image.jpg")
|
354
|
+
```
|
355
|
+
|
356
|
+
Object detection
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
detector = Informers.pipeline("object-detection")
|
360
|
+
detector.("image.jpg")
|
361
|
+
```
|
362
|
+
|
363
|
+
Zero-shot object detection
|
364
|
+
|
365
|
+
```ruby
|
366
|
+
detector = Informers.pipeline("zero-shot-object-detection")
|
367
|
+
detector.("image.jpg", ["label1", "label2", "label3"])
|
368
|
+
```
|
369
|
+
|
370
|
+
Depth estimation
|
371
|
+
|
372
|
+
```ruby
|
373
|
+
estimator = Informers.pipeline("depth-estimation")
|
374
|
+
estimator.("image.jpg")
|
375
|
+
```
|
376
|
+
|
377
|
+
Image-to-image
|
378
|
+
|
379
|
+
```ruby
|
380
|
+
upscaler = Informers.pipeline("image-to-image")
|
381
|
+
upscaler.("image.jpg")
|
382
|
+
```
|
383
|
+
|
384
|
+
Image feature extraction
|
385
|
+
|
386
|
+
```ruby
|
387
|
+
extractor = Informers.pipeline("image-feature-extraction")
|
388
|
+
extractor.("image.jpg")
|
389
|
+
```
|
390
|
+
|
391
|
+
### Multimodal
|
392
|
+
|
393
|
+
Image captioning
|
394
|
+
|
395
|
+
```ruby
|
396
|
+
captioner = Informers.pipeline("image-to-text")
|
397
|
+
captioner.("image.jpg")
|
398
|
+
```
|
399
|
+
|
400
|
+
Document question answering
|
401
|
+
|
402
|
+
```ruby
|
403
|
+
qa = Informers.pipeline("document-question-answering")
|
404
|
+
qa.("image.jpg", "What is the invoice number?")
|
405
|
+
```
|
406
|
+
|
285
407
|
## Credits
|
286
408
|
|
287
409
|
This library was ported from [Transformers.js](https://github.com/xenova/transformers.js) and is available under the same license.
|
@@ -321,5 +443,6 @@ To get started with development:
|
|
321
443
|
git clone https://github.com/ankane/informers.git
|
322
444
|
cd informers
|
323
445
|
bundle install
|
446
|
+
bundle exec rake download:files
|
324
447
|
bundle exec rake test
|
325
448
|
```
|
data/lib/informers/configs.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
module Informers
|
2
2
|
class PretrainedConfig
|
3
|
-
attr_reader :model_type, :problem_type, :id2label
|
4
|
-
|
5
3
|
def initialize(config_json)
|
6
|
-
@
|
7
|
-
|
8
|
-
@model_type = config_json["model_type"]
|
9
|
-
@problem_type = config_json["problem_type"]
|
10
|
-
@id2label = config_json["id2label"]
|
4
|
+
@config_json = config_json.to_h
|
11
5
|
end
|
12
6
|
|
13
7
|
def [](key)
|
14
|
-
|
8
|
+
@config_json[key.to_s]
|
9
|
+
end
|
10
|
+
|
11
|
+
def []=(key, value)
|
12
|
+
@config_json[key.to_s] = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
@config_json.to_h
|
15
17
|
end
|
16
18
|
|
17
19
|
def self.from_pretrained(
|
data/lib/informers/model.rb
CHANGED
@@ -1,19 +1,12 @@
|
|
1
1
|
module Informers
|
2
2
|
class Model
|
3
3
|
def initialize(model_id, quantized: false)
|
4
|
-
@model_id = model_id
|
5
4
|
@model = Informers.pipeline("embedding", model_id, quantized: quantized)
|
5
|
+
@options = model_id == "mixedbread-ai/mxbai-embed-large-v1" ? {pooling: "cls", normalize: false} : {}
|
6
6
|
end
|
7
7
|
|
8
8
|
def embed(texts)
|
9
|
-
|
10
|
-
when "sentence-transformers/all-MiniLM-L6-v2", "Xenova/all-MiniLM-L6-v2", "Xenova/multi-qa-MiniLM-L6-cos-v1", "Supabase/gte-small"
|
11
|
-
@model.(texts)
|
12
|
-
when "mixedbread-ai/mxbai-embed-large-v1"
|
13
|
-
@model.(texts, pooling: "cls", normalize: false)
|
14
|
-
else
|
15
|
-
raise Error, "Use the embedding pipeline for this model: #{@model_id}"
|
16
|
-
end
|
9
|
+
@model.(texts, **@options)
|
17
10
|
end
|
18
11
|
end
|
19
12
|
end
|