Skip to main content

NER4OPT Library

Project description

Named Entity Recognition for Optimization (Ner4Opt) Library

Given an optimization problem in natural language, the Ner4Opt library extracts six named entities:

  • CONST_DIR: Constraint direction
  • LIMIT: Limit
  • OBJ_DIR: Objective direction
  • OBJ_NAME: Objective name
  • PARAM: Parameter
  • VAR: Variable

Quick Start

# Import the Ner4Opt Library
from ner4opt import Ner4Opt

# Problem Description
problem_description = "Cautious Asset Investment has a total of $150,000 to manage and decides to invest it in money market fund, which yields a 2% return as well as in foreign bonds, which gives and average rate of return of 10.2%. Internal policies require PAI to diversify the asset allocation so that the minimum investment in money market fund is 40% of the total investment. Due to the risk of default of foreign countries, no more than 40% of the total investment should be allocated to foreign bonds. How much should the Cautious Asset Investment allocate in each asset so as to maximize its average return?"

# Ner4Opt Model options: lexical, lexical_plus, semantic, hybrid (default). 
ner4opt = Ner4Opt(model="hybrid")

# Extracts a list of dictionaries corresponding to entities found in the given problem description.
# Each dictionary holds keys for the following: 
# start (starting character index of the entity), end (ending character index of the entity)
# word (entity), entity_group (entity label) and score (confidence score for the entity)
entities = ner4opt.get_entities(problem_description)

# Output
print("Number of entities found: ", len(entities))

# Example output
[   
    {
        'start': 32, 
        'end': 37, 
        'word': 'total', 
        'entity_group': 'CONST_DIR', 
        'score': 0.997172257043559
    },
    {
        'start': 575, 
        'end': 583, 
        'word': 'maximize', 
        'entity_group': 'OBJ_DIR', 
        'score': 0.9982091561140413
    },
    { ... },
]

Installation

Ner4Opt requires Python 3.8+ and can be installed from PyPI using pip install ner4opt or by building from source

git clone https://github.com/skadio/ner4opt.git
cd ner4opt
pip install .

Testing

To run tests, execute the following from the root folder:

python -m unittest

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

ner4opt-1.0.1.tar.gz (8.0 MB view details)

Uploaded Source

Built Distribution

ner4opt-1.0.1-py3-none-any.whl (8.1 MB view details)

Uploaded Python 3

File details

Details for the file ner4opt-1.0.1.tar.gz.

File metadata

  • Download URL: ner4opt-1.0.1.tar.gz
  • Upload date:
  • Size: 8.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for ner4opt-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9c2ed09f4104a6812a1f834d899e9f00024378bbd99647f35eba2c1ca800ad24
MD5 0abd56ef3aa67dc6d7703044322d8476
BLAKE2b-256 10499ea09e101fadcacc0fdb429f1a936bfc77a83ddadf794f6686f671804eda

See more details on using hashes here.

File details

Details for the file ner4opt-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: ner4opt-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for ner4opt-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 72b483b8a879127b38fa63e27636c69a9c8d00cb1b19d015d90b5f8779725ec5
MD5 f7565be0cadf45ff05c3bf557403fac4
BLAKE2b-256 7d48a920b5f898d298546e6af922d823adff2f170d6d6973e8c8e83d0352bc5f

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