User:Alice/Prototyping trim4: Difference between revisions
No edit summary |
No edit summary |
||
Line 14: | Line 14: | ||
nlp = en_core_web_sm.load() | nlp = en_core_web_sm.load() | ||
doc = nlp(u'''Preheat the oven to 200ºC/400ºF/gas. Lay out 3 slices of the prosciutto so they overlap. Repeat with the rest of the prosciutto so you have 4 piles. | doc = nlp(u'''Preheat the oven to 200ºC/400ºF/gas. Lay out 3 slices of the prosciutto so they overlap. Repeat with the rest of the prosciutto so you have 4 piles. | ||
Put a frying pan over a high heat. Season the chops well with salt and pepper, then sear in the hot pan on both sides. Place a seared chop on top of each pile of prosciutto. Divide the sliced apple and Stilton between the prosciutto piles, on top of the pork. | Put a frying pan over a high heat. Season the chops well with salt and pepper, then sear in the hot pan on both sides. Place a seared chop on top of each pile of prosciutto. | ||
Wrap the prosciutto around each of the pork, apple and Stilton parcels to hold it all in place. Secure each with a rosemary sprig. Place the prosciutto parcels on a baking tray and bake in the oven for 15 minutes, or until the pork is cooked through. Serve with mashed potato and greens and cooking juices from the parcels.''') | Divide the sliced apple and Stilton between the prosciutto piles, on top of the pork. | ||
Wrap the prosciutto around each of the pork, apple and Stilton parcels to hold it all in place. | |||
Secure each with a rosemary sprig. Place the prosciutto parcels on a baking tray and bake in the oven for 15 minutes, or until the pork is cooked through. | |||
Serve with mashed potato and greens and cooking juices from the parcels.''') | |||
for token in doc: | for token in doc: |
Revision as of 13:56, 30 September 2018
Natural Language Processing experiment with recipes
Idea
I would like to train an NLP tool with language specific to recipe writing, so that it can output cooking instructions by mixing and matching various actions and ingredients.
SpaCy
Spacy is an NLP library for Python that is supposed to make some things simpler (potentially easier than NLTK?), such as training, for instance. I have decided to give SpaCy a try, since I found working with NLTK a bit cumbersome at times. I also read this article which compares the two, and SpaCy seems to be performing better speed-wise and not only.
A simple example
Extracting POS tags and lemmas from a cooking recipe
import spacy
import en_core_web_sm
nlp = en_core_web_sm.load()
doc = nlp(u'''Preheat the oven to 200ºC/400ºF/gas. Lay out 3 slices of the prosciutto so they overlap. Repeat with the rest of the prosciutto so you have 4 piles.
Put a frying pan over a high heat. Season the chops well with salt and pepper, then sear in the hot pan on both sides. Place a seared chop on top of each pile of prosciutto.
Divide the sliced apple and Stilton between the prosciutto piles, on top of the pork.
Wrap the prosciutto around each of the pork, apple and Stilton parcels to hold it all in place.
Secure each with a rosemary sprig. Place the prosciutto parcels on a baking tray and bake in the oven for 15 minutes, or until the pork is cooked through.
Serve with mashed potato and greens and cooking juices from the parcels.''')
for token in doc:
print(token.text, token.lemma_, token.pos_, token.tag_)