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.0.tar.gz (8.0 MB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: ner4opt-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 89f5bd11a69de1ca21472579ba5494620232f35633f0e47ac71acbd693e30c7f
MD5 d6a961a4597a70ca40519ff8fcc3154d
BLAKE2b-256 f4899c4c65031af412925ecf076c5380eef5861100c7930e0cdbfe14443cc1f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ner4opt-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc33fb64233298657e07e0ce375d1e046fbfa8a87fbb47dab9ec7649311d5324
MD5 2f3739fc2e187d200d9675c2b12dc7d7
BLAKE2b-256 dff6f6afd548d7bd63fe85868ec2fca1c08a7c548f51d274cae5bb0f1b49c73c

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