hugging-face 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -6
- data/README.md +8 -1
- data/lib/hugging_face/base_api.rb +1 -1
- data/lib/hugging_face/inference_api.rb +17 -5
- data/lib/hugging_face/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b9591169889f3b463224dade2fa11e63bba1733d6e09ebb814e9e9e1d5bad14
|
4
|
+
data.tar.gz: 521110a79c57838d68aff92db3212358bcda75484b55a78c92ea46272fbc41d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9940b1ec90fdb03631d3318f1f12bf6431132166d97adbb9e3e962f6acf7e2150982da478129cee4c2d2bb4bdb973f9dda2b7e837c4722ad2d9b09d122205172
|
7
|
+
data.tar.gz: 4d9076507fcc8b3f6829aeb34d462fda23a317b8b2009a94be73cceb33b255f871ece5a0d0b41a832b743b4c26e7aa6af9d589f0eb3c112b96d4760ac56434b4
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hugging-face (0.1
|
5
|
-
faraday (~>
|
4
|
+
hugging-face (0.3.1)
|
5
|
+
faraday (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -12,11 +12,11 @@ GEM
|
|
12
12
|
crack (0.4.5)
|
13
13
|
rexml
|
14
14
|
diff-lcs (1.5.0)
|
15
|
-
faraday (2.
|
16
|
-
|
17
|
-
ruby2_keywords
|
18
|
-
faraday-net_http (3.0.2)
|
15
|
+
faraday (1.2.0)
|
16
|
+
multipart-post (>= 1.2, < 3)
|
17
|
+
ruby2_keywords
|
19
18
|
hashdiff (1.0.1)
|
19
|
+
multipart-post (2.3.0)
|
20
20
|
public_suffix (5.0.1)
|
21
21
|
rake (13.0.6)
|
22
22
|
rexml (3.2.5)
|
@@ -41,6 +41,7 @@ GEM
|
|
41
41
|
|
42
42
|
PLATFORMS
|
43
43
|
arm64-darwin-21
|
44
|
+
x86_64-darwin-19
|
44
45
|
x86_64-linux
|
45
46
|
|
46
47
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ Instantiate a HuggigFace Inference API client:
|
|
28
28
|
client = HuggingFace::InferenceApi.new(api_key: ENV['HUGGING_FACE_API_KEY'])
|
29
29
|
```
|
30
30
|
|
31
|
-
|
31
|
+
Question answering:
|
32
32
|
|
33
33
|
```ruby
|
34
34
|
client.question_answering(
|
@@ -49,6 +49,13 @@ Summarization:
|
|
49
49
|
client.summarization(input: 'The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930.')
|
50
50
|
```
|
51
51
|
|
52
|
+
Embedding:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
client.embedding(input: ['How to build a ruby gem?', 'How to install ruby gem?'])
|
56
|
+
```
|
57
|
+
|
58
|
+
|
52
59
|
## Development
|
53
60
|
|
54
61
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -1,11 +1,15 @@
|
|
1
1
|
module HuggingFace
|
2
2
|
class InferenceApi < BaseApi
|
3
3
|
HOST = "https://api-inference.huggingface.co"
|
4
|
-
MAX_RETRY = 20
|
5
4
|
|
5
|
+
# Retry connecting to the model for 1 minute
|
6
|
+
MAX_RETRY = 60
|
7
|
+
|
8
|
+
# Deafult models that can be overriden by 'model' param
|
6
9
|
QUESTION_ANSWERING_MODEL = 'distilbert-base-cased-distilled-squad'
|
7
10
|
SUMMARIZATION_MODEL = "sshleifer/distilbart-xsum-12-6"
|
8
11
|
GENERATION_MODEL = "distilgpt2"
|
12
|
+
EMBEDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
|
9
13
|
|
10
14
|
def call(input:, model:)
|
11
15
|
request(connection: connection(model), input: input)
|
@@ -14,21 +18,29 @@ module HuggingFace
|
|
14
18
|
def question_answering(question:, context:, model: QUESTION_ANSWERING_MODEL)
|
15
19
|
input = { question: question, context: context }
|
16
20
|
|
17
|
-
request
|
21
|
+
request connection: connection(model), input: input
|
18
22
|
end
|
19
23
|
|
20
24
|
def summarization(input:, model: SUMMARIZATION_MODEL)
|
21
|
-
request
|
25
|
+
request connection: connection(model), input: { inputs: input }
|
22
26
|
end
|
23
27
|
|
24
28
|
def text_generation(input:, model: GENERATION_MODEL)
|
25
|
-
request
|
29
|
+
request connection: connection(model), input: { inputs: input }
|
30
|
+
end
|
31
|
+
|
32
|
+
def embedding(input:)
|
33
|
+
request connection: connection(EMBEDING_MODEL), input: { inputs: input }
|
26
34
|
end
|
27
35
|
|
28
36
|
private
|
29
37
|
|
30
38
|
def connection(model)
|
31
|
-
|
39
|
+
if model == EMBEDING_MODEL
|
40
|
+
build_connection "#{HOST}/pipeline/feature-extraction/#{model}"
|
41
|
+
else
|
42
|
+
build_connection "#{HOST}/models/#{model}"
|
43
|
+
end
|
32
44
|
end
|
33
45
|
|
34
46
|
def request(connection:, input:)
|
data/lib/hugging_face/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hugging-face
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Chaplinsky
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.0'
|
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: '
|
26
|
+
version: '1.0'
|
27
27
|
description: Ruby client for Hugging Face API
|
28
28
|
email:
|
29
29
|
- alchaplinsky@gmail.com
|