Skip to main content

NLP client for python

Project description

DigitalOwl NlpClient

Python client, that utilized the digitalowl.org NLP API.

Take advantage of some of the modern NLP techniques in easy, fast and acessible way. Most of the time you won't need more than 10 lines of code to integrate this into your pipeline.

The API is free for use

Install using pip

pip install pysemantics

So what can it do?

With few words, this is a script/client that can be used to perform semantic analysis of text, or in order words analyse the text's meaning.

Functionalities

Text classification

Classify text or url into set of user defined categories.

client.classify(input='https://en.wikipedia.org/wiki/2020_United_States_presidential_election')

Output:

{'tags': ['politics', 'law'], 'originalTags': ['2012 democratic national convention']}

The url is downloaded, meaningful text is extracted and classified, if you alredy have the text available, you can directly pass it as input.

Full working code, with more explanations: classify_example.py

Phrase/Word analysis

The underlying logic is based on NLP model called Word2Vec, if given the right training training data, it can start picking up contextual relations between words. Meaning words that are used often together, or are used in similar way, are close by contextual meaning (contextual synonyms).

client.analyse_sentence(sentence='apricot')

Output:

  {'pistachio': 0.7594164609909058, 'overripe': 0.7523329257965088, 'mango': 0.7421437501907349,
  'peach': 0.7410970330238342, 'rhubarb': 0.7401571273803711, 'pecan': 0.7379646897315979,
  'persimmon': 0.7368103265762329, 'strawberry': 0.731874942779541, 'unripe': 0.7294522523880005,
  'sorbet': 0.7278781533241272, 'walnut': 0.7244322299957275, 'tart': 0.7223066687583923,
  'beetroot': 0.7216348648071289, 'okra': 0.7172538042068481, 'pumpkin': 0.7165997624397278,
  'pineapple': 0.7146158814430237, 'lemongrass': 0.7138402462005615, 'papaya': 0.7137945294380188,
  'blueberry': 0.7127506136894226, 'marmalade': 0.7100027799606323}

The words that are close to apricot are other fruits and foods, these relations can be used in various NLP tasks. Similar relations can be extracted for whole paragraphs full working code with more explanations: analyse_sentence_example.py

Semantic Similarity

Given two documents, words or just phrases, you can compare to what degree they are close by meaning.

first = 'https://en.wikipedia.org/wiki/Impeachment_inquiry_against_Donald_Trump'

second = 'https://news.sky.com/story/ex-trump-adviser-fiona-hill-says-russia-gearing-up-to-interfere-in-2020-election-11866422'

client.similarity(first=first, second=second)

{'similarity': 0.9516085802597031}

Full working example with documentation: similarity_example.py

Text Clusters

Automatically group documents, words or sentences.

Using the vectors we obtain from the API and the KMeans algorithm integrated into this client we can group pieces of text or documents based on their meaning.

Full working example can be found here: data_cluster_example.py

Belong to group check

Using the client you are able to define a group of objects and then determine if certain object belongs to that group

define some group of animals:

group = ['cat', 'dog', 'fox', 'horse', 'rhino']

pick some random words, some of which are animals:

targets = ['carrot', 'animal', 'monkey', 'ship', 'Canada', 'buffalo', 'crow', 'news', 'government', 'murder', 'chariot']

client.belong(group=group, targets=targets)

Output:

['animal', 'monkey', 'buffalo', 'crow', 'chariot']

Full working example: groups_example.py

In case you find any issues, please report them as issue. Any feedback is welcome, don't hesitate to contact me at borislav.stoilov@digitalowl.org

Project details


Download files

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

Source Distribution

pysemantics-1.0.3.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

pysemantics-1.0.3-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file pysemantics-1.0.3.tar.gz.

File metadata

  • Download URL: pysemantics-1.0.3.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.2

File hashes

Hashes for pysemantics-1.0.3.tar.gz
Algorithm Hash digest
SHA256 630cca06a50c19089d81394ac4a7836e7b437e5a403782467b067c191eb368a3
MD5 36e13c3e909b2dfc788603f5cbf776ff
BLAKE2b-256 f632f54eed88b94d3f2b128f036323b6e47eb4251241f9cda79c766c2a410474

See more details on using hashes here.

File details

Details for the file pysemantics-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pysemantics-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.5.2

File hashes

Hashes for pysemantics-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0ed47c52ab4bc48dd065a20de66f7a7b07f81b5e33490f7d6ca0dca366b9aa3d
MD5 f42cb07dd3df78a228a7c3d4cb14ebaf
BLAKE2b-256 cb425085b86dc4c25bc0816ed0c6df5b5931e3295c2244296bf6f7fd92aeadf8

See more details on using hashes here.

Supported by

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