Skip to content

Commit 0441243

Browse files
author
Julien Salinas
committed
Support embeddings and semantic-similarity endpoints.
1 parent d06482e commit 0441243

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ Call the `generation()` method and pass the following arguments:
140140
1. (Optional) `length_penalty`: Exponential penalty to the length, as a float. 1.0 means no penalty. Set to values < 1.0 in order to encourage the model to generate shorter sequences, or to a value > 1.0 in order to encourage the model to produce longer sequences. Defaults to 1.0.
141141
1. (Optional) `bad_words`: List of tokens that are not allowed to be generated, as a list of strings. Defaults to null.
142142

143-
144143
```ruby
145144
client.generation("<Your input text>")
146145
```
@@ -200,6 +199,16 @@ client.langdetection("<The text you want to analyze>")
200199

201200
The above command returns a JSON object.
202201

202+
### Semantic Similarity Endpoint
203+
204+
Call the `semantic_similarity()` method and pass a list made up of 2 blocks of text that you want to compare.
205+
206+
```python
207+
client.semantic_similarity(["<Block of text 1>", "<Block of text 2>")
208+
```
209+
210+
The above command returns a JSON object.
211+
203212
### Tokenization Endpoint
204213

205214
Call the `tokens()` method and pass the text you want to tokenize.
@@ -230,6 +239,16 @@ client.sentence_dependencies("<Your block of text>")
230239

231240
The above command returns a JSON object.
232241

242+
### Embeddings Endpoint
243+
244+
Call the `embeddings()` method and pass a list of blocks of text that you want to extract embeddings from.
245+
246+
```ruby
247+
client.embeddings(["<Text 1>", "<Text 2>", "<Tex 3>"], ...)
248+
```
249+
250+
The above command returns a JSON object.
251+
233252
### Library Versions Endpoint
234253

235254
Call the `lib_versions()` method to know the versions of the libraries used behind the hood with the model (for example the PyTorch, TensorFlow or spaCy versions used).
@@ -239,4 +258,3 @@ client.lib_versions()
239258
```
240259

241260
The above command returns a JSON object.
242-

lib/nlpcloud.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ def langdetection(text)
114114
JSON.parse(response.body)
115115
end
116116

117+
def semantic_similarity(sentences)
118+
payload = {
119+
'sentences' => sentences
120+
}
121+
response = RestClient.post("#{@root_url}/semantic_similarity", payload.to_json, @headers)
122+
JSON.parse(response.body)
123+
end
124+
117125
def tokens(text)
118126
payload = {
119127
'text' => text
@@ -138,6 +146,14 @@ def sentence_dependencies(text)
138146
JSON.parse(response.body)
139147
end
140148

149+
def embeddings(sentences)
150+
payload = {
151+
'sentences' => sentences
152+
}
153+
response = RestClient.post("#{@root_url}/embeddings", payload.to_json, @headers)
154+
JSON.parse(response.body)
155+
end
156+
141157
def lib_versions
142158
response = RestClient.get("#{@root_url}/versions", @headers)
143159
JSON.parse(response.body)

nlpcloud.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Gem::Specification.new do |s|
22
s.name = 'nlpcloud'
3-
s.version = '1.0.16'
3+
s.version = '1.0.17'
44
s.summary = 'Ruby client for the NLP Cloud API'
5-
s.description = 'NLP Cloud serves high performance pre-trained or custom models for NER, sentiment-analysis, classification, summarization, text generation, question answering, machine translation, language detection, tokenization, POS tagging, and dependency parsing. It is ready for production, served through a REST API. This is the Ruby client for the API. More details here: https://nlpcloud.io. Documentation: https://docs.nlpcloud.io.'
5+
s.description = 'NLP Cloud serves high performance pre-trained or custom models for NER, sentiment-analysis, classification, summarization, text generation, question answering, machine translation, language detection, semantic similarity, tokenization, POS tagging, embeddings, and dependency parsing. It is ready for production, served through a REST API. This is the Ruby client for the API. More details here: https://nlpcloud.io. Documentation: https://docs.nlpcloud.io.'
66
s.authors = ['Julien Salinas']
77
s.email = 'all@juliensalinas.com'
88
s.files = [

0 commit comments

Comments
 (0)