Skip to main content

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.996867, starting_index=2)],
    size=None,
    amount=[IngredientAmount(quantity=Fraction(3, 1),
                             quantity_max=Fraction(3, 1),
                             unit=<Unit('pound')>,
                             text='3 pounds',
                             confidence=0.999982,
                             starting_index=0,
                             unit_system=<UnitSystem.US_CUSTOMARY: 'us_customary'>,
                             APPROXIMATE=False,
                             SINGULAR=False,
                             RANGE=False,
                             MULTIPLIER=False,
                             PREPARED_INGREDIENT=False)],
	preparation=IngredientText(text='cut into 2 inch chunks',
                               confidence=0.999946,
                               starting_index=5),
	comment=None,
	purpose=None,
	foundation_foods=[],
	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 over 88,000 example sentences is used to train and evaluate the model. See the Explanation section of the documentation for more details.

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

╒══════════════════════════╤══════════════════════════╕
│ Sentence-level results   │ Word-level results       │
╞══════════════════════════╪══════════════════════════╡
│ Accuracy: 94.98%         │ Accuracy: 98.05%         │
│                          │ Precision (micro) 98.04% │
│                          │ Recall (micro) 98.05%    │
│                          │ F1 score (micro) 98.05%  │
╘══════════════════════════╧══════════════════════════╛

Development

Basic

Train and fine-tune new ingredient datasets to expand beyond the existing trained model provided in the library. The development dependencies are in the requirements-dev.txt file. Details on the training process can be found in the Explanation documentation.

Web App

The ingredient parser library provides a convenient web interface that you can run locally to access most of the library's functionality, including using the parser, browsing the database, labelling entries, and training the model(s). View the specific README in webtools for a detailed overview.

Parser Labeller Trainer
Screen shot of web parser Screen shot of web labeller Screen shot of web trainer

Documentation

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

Tests

The ingredient parser library has extensive test coverage. The pytest framework is used for testing, and coverage.py is used to measure test coverage.

# Run the test suite
$ pytest

# Evaluate test coverage
$ coverage run -m pytest
# Generate coverage report
$ coverage html

Contribution

Please target the develop branch for pull requests. The main branch is used for stable releases and hotfixes only.

Before committing anything, install pre-commit and run the following to install the hooks:

$ pre-commit install

Pre-commit hooks cover both the main python library code and the web app (webtools) code.

Metadata

Release files for ingredient-parser-nlp 2.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ingredient-parser-nlp 2.9.0
File Size Uploaded
ingredient_parser_nlp-2.9.0.tar.gz 4.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for ingredient-parser-nlp 2.9.0
File Interpreter ABI Platform
ingredient_parser_nlp-2.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 MB

Release files / ingredient_parser_nlp-2.9.0.tar.gz

Download URL ingredient_parser_nlp-2.9.0.tar.gz
Size 4.3 MB
Tags Source
SHA-256 checksum
How to use checksums
afdbbc5dbaff57bab086131d5d0aa102f49c98d61c4d91d61d78993a4b4f2eb5
BLAKE2b-256 checksum
How to use checksums
422523faf6bc48c804c0efde55288c115eb435d3629222ceb42255e1345e8f50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / ingredient_parser_nlp-2.9.0-py3-none-any.whl

Download URL ingredient_parser_nlp-2.9.0-py3-none-any.whl
Size 4.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f95630809a56bdfd184c7bb0ec5f27327b38cddeaa82110228905fff5741ac82
BLAKE2b-256 checksum
How to use checksums
d6ff35651ddcc485fac13a4ea945a8112897292e9e4d270dfb6191820534e1df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

2.9.1

2 release files

This release

2.9.0 This release

2 release files

2.8.0

2 release files

2.7.0

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page