This is a python package for parsing ingredient strings. There is only one function parse_ingredients
. It takes in a
single string or list of strings and returns a dictionary containing the name, quantity and unit in that recipe string.
First install the package using pip:
pip install pying
Then you can use it like follows:
from PyIng import parse_ingredients
ingredients = ["3 large melons", "5 1/2 cups water", "2 cups flour"]
parsed_ingredients = parse_ingredients(ingredients)
the output parsed_ingredients
should look like so:
parsed_ingredients = [
{
"name": "melons",
"unit": None,
"qty": 3.0
},
{
"name": "water",
"unit": "cups",
"qty": 5.5
},
{
"name": "flour",
"unit": "cups",
"qty": 2
}
]
The ingredient parser uses a LSTM model written in tensorflow. It is trained on a publically available dataset produced by the new york times:
The entire model is trained using the train_model.ipynb
and the model is saved in tflite format. Please try and improve on my model, it is far from optimal, I wanted to get something that works without spending too long.
THere are more details on training the model in the jupyter notebook.