Skip to main content

NLP as a Service

Project description

NLP-as-a-service

One AI Python SDK

One AI is a NLP as a service platform. Our API enables language comprehension in context, transforming texts from any source into structured data to use in code.

This SDK provides safe and convenient access to One AI's API from a Python environment.

Documentation

See the documentation

Getting started

Requirements

Python 3.6.1+ (PyPy supported)

Installation

pip install oneai

Authentication

You will need a valid API key for all requests. Register and create a key for your project in the Studio.

Example

import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Names(),
    oneai.skills.Summarize(min_length=20),
    oneai.skills.Keywords()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)

Pipeline API

Language Skills

A Language Skill is a package of trained NLP models, available via API. Skills accept text as an input in various formats, and respond with processed texts and extracted metadata.

Pipelines

Language AI pipelines allow invoking and chaining multiple Language Skills to process your input text with a single call. Pipelines are defined by listing the desired Skills.

Language Studio

The Language Studio provides a visual interface to experiment with our APIs and generate calls to use in code. In the Studio you can craft a pipeline and paste the generated code back into your repository.

Basic Example

Let's say you're interested in extracting keywords from the text.

import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Keywords()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)

Multi Skills request

Let's say you're interested in extracting keywords and sentiments from the text.

import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Keywords(),
    oneai.skills.Sentiments()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)

Analyzer Skills vs Generator Skills

Skills can do either text analysis, and then their output are labels and spans (labels location in the analyzed text), or they can be generator skills, in which case they transform the input text into an output text.

Here's an example for a pipeline that combines both type of skills. It will extract keywords and sentiments from the text, and then summarize it.

import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Keywords(),
    oneai.skills.Sentiments(),
    oneai.skills.Summarize()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)

Order is Important

When the pipeline is invoked, it is invoked with an original text you submit. If a generator skill is ran, then all following skills will use its generated text rather then the original text. In this example, for instance, we change the order of the pipeline from the previous example, and the results will be different. Instead of extracting keywords and sentiments from the original text, keywords and sentiments will be extracted from the generated summary.

import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Summarize(),
    oneai.skills.Keywords(),
    oneai.skills.Sentiments()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)

Configuring Skills

Many skills are configurable as you can find out in the docs. Let's use the exact same example, this time however, we'll limit the summary length to 50 words.

import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Summarize(max_length=50),
    oneai.skills.Keywords(),
    oneai.skills.Sentiments()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)

Output

The structure of the output is dynamic, and corresponds to the Skills used and their order in the pipeline. Each output object contains the input text (which can be the original input or text produced by generator Skills), and a list of labels detected by analyzer Skills, that contain the extracted data. For example:

pipeline = oneai.Pipeline(steps=[
    oneai.skills.Sentiments(),
    oneai.skills.Summarize(max_length=50),
    oneai.skills.Keywords(),
])

my_text = '''Could a voice control microwave be the new norm? The price is unbeatable for a name brand product, an official Amazon brand, so you can trust it at least. Secondly, despite the very low price, if you don't want to use the voice control, you can still use it as a regular microwave.'''
output = pipeline.run(my_text)

will generate the following:

oneai.Output(
    text="Could a voice control microwave be the ...",
    sentiments=[ # list of detected sentiments
        oneai.Label(
            type='sentiment',
            output_spans=[ # where the sentiment appears in the text
                Span(
                    start=49,
                    end=97,
                    section=0,
                    text='The price is unbeatable for a name brand product'
                )
            ],
            value='POS' # a positive sentiment
        ),
        ...
    ],
    summary=oneai.Output(
        text='The price is unbeatable for a name brand product, an official Amazon brand, so you can trust it at least. Despite the very low price, you can still use it as a regular microwave.',
        keywords=[ # keyword labels
            oneai.Label(type='keyword', name='price', output_spans=[Span(start=4, end=9, section=0, text='price')], value=0.253), ...
        ]
    )
)

File Uploads

Our API supports the following file extensions:

  • .txt- text content
  • .json- conversations in the One AI conversation format
  • .srt- analyze captions as conversations
  • .wav- audio files to be transcribed & analyzed
  • .jpg- detect text in pictures via OCR Upload a file via the oneai.File class, i.e
input = oneai.File('./example.txt')
pipeline = oneai.Pipeline(steps=[...])
output = pipeline.run(input)

Support

Feel free to submit issues in this repo, contact us at devrel@oneai.com, or chat with us on Discord

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oneai-0.4.0.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oneai-0.4.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file oneai-0.4.0.tar.gz.

File metadata

  • Download URL: oneai-0.4.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9

File hashes

Hashes for oneai-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6eab440611040f27e081b611f6ded1f222a80fa4bb6e15e711d2ff20ff039282
MD5 8c668e66e09b2021cd8dba9559e58a3b
BLAKE2b-256 fe998286cad24b99dce11451ecc4c7e567a25b93955699a4d14b172d509b7b04

See more details on using hashes here.

File details

Details for the file oneai-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: oneai-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9

File hashes

Hashes for oneai-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d3c9a2fcf67534c4ee4592260252ae58e76af104e1076e212880497b7522c264
MD5 f9f02b50747b64eaebbf8cc8d8aa83d2
BLAKE2b-256 d8490a58851c577a913a202719d27c2f704a41bc2515ef14485ef0cef03050cd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page