Skip to main content

NER4OPT Library

Project description

Ner4Opt: Named Entity Recognition for Optimization

Given an optimization problem in natural language, Ner4Opt extracts optimization related entities from free-form text.

See our HugginFace Space Demo to test it yourself 🤗.

The Ner4Opt model (CPAIOR'23, NeurIPS'22) is trained to detect six named entities:

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

Here are the details of our pre-trained models and the training procedure. Large pretrained models are hosted on HuggingFace Models.

Quick Start

from ner4opt import Ner4Opt

# Input optimization problem description as free-form text
problem_description = "The Notorious Desk company wants to promote a new brand of wine and wants to market it using a total market budget of $ 87,000 . To do so , the company needs to decide how much to allocate on each of its two advertising channels : ( 1 ) morning TV show and ( 2 ) social media . Each day , it costs the company $ 1,000 and $ 2000 to run advertisement spots on morning TV show and social media respectively . The expected daily reach , based on past ratings , is 15,000 viewers for each morning show spot and 30,000 internet users for a social media spot . The chief marketer knows from her experience that both channels are key to the success of the product launch . She wants to plan at least 4 but no more than 7 morning show spots . In addition , the social media spots needs to be at least 30 due to pricing tier policy . How many times should each of the media channels be used to maximize the reach of the campaign ?"

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

# Extract 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 entity output
[
    {
        'start': 108,
        'end': 114,
        'word': 'budget',
        'entity_group': 'CONST_DIR',
        'score': 0.9919970308651846
    },
    {
        'start': 120,
        'end': 126,
        'word': '87,000',
        'entity_group': 'LIMIT',
        'score': 0.9993724035912778
    },
    { ... },
]

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

Citation

Citation

If you use Ner4Opt, please cite the following paper:

@inproceedings {ner4opt,
    title = {Ner4Opt: Named Entity Recognition for Optimization Modelling from Natural Language}
	author = {Parag Pravin Dakle, Serdar Kadıoğlu, Karthik Uppuluri, Regina Politi, Preethi Raghavan, SaiKrishna Rallabandi, Ravisutha Srinivasamurthy}
    journal = {The 20th International Conference on the Integration of Constraint Programming, Artificial Intelligence, and Operations Research (CPAIOR 2023)},
	year = {2023},
}

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ner4opt-1.0.3.tar.gz
Algorithm Hash digest
SHA256 7cb269fbb4990d0dc105372a89f88736021d010ea96e50cf1bc0ddaa1cf9dd29
MD5 577890feeffa6d79cff25ad74751799a
BLAKE2b-256 1e38fdb6f00ede6dd2978ea21365fc1d4adc691a65d08da4d70264457c813758

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ner4opt-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 44b63ec5fa43652bcd0e2c9cd056733f76fbd76e0c72ca0d6a021c283fb91638
MD5 cf47850781e64f37feab6701af3bdefb
BLAKE2b-256 a9e9f1dc054a3162a851d673dd7e143e5c34eb7ddc3f72d52a63ffd7b9b647cd

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