Skip to main content

A Python package to parse structured information from recipe ingredient sentences

Project description

Ingredient Parser

The Ingredient Parser package is a Python package for parsing structured information out of recipe ingredient sentences.

Documentation

Documentation on using the package and training the model can be found at https://ingredient-parser.readthedocs.io/.

Quick Start

Install the package using pip

$ python -m pip install ingredient-parser-nlp

Import the parse_ingredient function and pass it an ingredient sentence.

>>> from ingredient_parser import parse_ingredient
>>> parse_ingredient("3 pounds pork shoulder, cut into 2-inch chunks")
ParsedIngredient(
    name=IngredientText(text='pork shoulder', confidence=0.999193),
    size=None,
    amount=[IngredientAmount(quantity='3',
                             unit=<Unit('pound')>,
                             text='3 pounds',
                             confidence=0.999906,,
                             APPROXIMATE=False,
                             SINGULAR=False)],
    preparation=IngredientText(text='cut into 2 inch chunks', confidence=0.999193),
    comment=None,
    purpose=None,
    sentence='3 pounds pork shoulder, cut into 2-inch chunks'
)

Refer to the documentation here for the optional parameters that can be used with parse_ingredient .

Model

The core of the library is a sequence labelling model that is used to label each token in the sentence with the part of the sentence it belongs to. A data set of 75,000 example sentences is used to train and evaluate the model. See the Model Guide in the documentation for mode details.

The model has the following accuracy on a test data set of 20% of the total data used:

Sentence-level results:
	Accuracy: 95.86%

Word-level results:
	Accuracy 98.41%
	Precision (micro) 98.41%
	Recall (micro) 98.41%
	F1 score (micro) 98.41%

Development

The development dependencies are in the requirements-dev.txt file. Details on the training process can be found in the Model Guide documentation.

Before committing anything, install pre-commit and run

pre-commit install

to install the pre-commit hooks.

There is a simple web app for testing the parser with ingredient sentences and showing the parsed output. To run the web app, run the command

$ flask --app webapp run

Screen shot of web app

This requires the development dependencies to be installed.

The dependencies for building the documentation are in the requirements-doc.txt file.

Project details


Release history Release notifications | RSS feed

This version

1.3.0

Download files

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

Source Distribution

ingredient_parser_nlp-1.3.0.tar.gz (828.5 kB view details)

Uploaded Source

Built Distribution

ingredient_parser_nlp-1.3.0-py3-none-any.whl (827.6 kB view details)

Uploaded Python 3

File details

Details for the file ingredient_parser_nlp-1.3.0.tar.gz.

File metadata

  • Download URL: ingredient_parser_nlp-1.3.0.tar.gz
  • Upload date:
  • Size: 828.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ingredient_parser_nlp-1.3.0.tar.gz
Algorithm Hash digest
SHA256 89b867b6ae28118e531e552c45ca68fffb683e23e0f8b9a7a4bfde1517dc4ef3
MD5 0ab33dc90792a12008f90a395439d4d3
BLAKE2b-256 4c31645bd88443495384930f85b1d288ffb89f3706da1a8c3d4f5b0cb6719b4d

See more details on using hashes here.

File details

Details for the file ingredient_parser_nlp-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ingredient_parser_nlp-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d915e8f6e55c254ed54e6b9f61374e39a97235f8294fea3751c1d73c9b8da0f
MD5 2a35423718c6bd1fe5e96bd8d9ec62f7
BLAKE2b-256 918e22ea6fca04aebe5729db38330d61a5cc54a63e78e3e8226b848523d09898

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