User:Alice/Prototyping trim4: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
Line 24: Line 24:


</source>
</source>
Extract from result:
Preheat preheat VERB VB
the the DET DT
oven oven NOUN NN
to to ADP IN
200ºC/400ºF 200ºc/400ºf NUM CD
/ / SYM SYM
gas gas NOUN NN
. . PUNCT .
Lay lay VERB VB
out out PART RP
3 3 NUM CD
slices slice NOUN NNS
of of ADP IN
the the DET DT
prosciutto prosciutto NOUN NN
so so ADV RB
they -PRON- PRON PRP
overlap overlap VERB VBP
. . PUNCT .
Repeat repeat VERB VB
with with ADP IN
the the DET DT
rest rest NOUN NN
of of ADP IN
the the DET DT
prosciutto prosciutto NOUN NN
so so ADP IN
you -PRON- PRON PRP
have have VERB VBP
4 4 NUM CD
piles pile NOUN NNS
. . PUNCT .

Revision as of 15:00, 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_)

Extract from result:

Preheat preheat VERB VB
the the DET DT
oven oven NOUN NN
to to ADP IN
200ºC/400ºF 200ºc/400ºf NUM CD
/ / SYM SYM
gas gas NOUN NN
. . PUNCT .
Lay lay VERB VB
out out PART RP
3 3 NUM CD
slices slice NOUN NNS
of of ADP IN
the the DET DT
prosciutto prosciutto NOUN NN
so so ADV RB
they -PRON- PRON PRP
overlap overlap VERB VBP
. . PUNCT .
Repeat repeat VERB VB
with with ADP IN
the the DET DT
rest rest NOUN NN
of of ADP IN
the the DET DT
prosciutto prosciutto NOUN NN
so so ADP IN
you -PRON- PRON PRP
have have VERB VBP
4 4 NUM CD
piles pile NOUN NNS
. . PUNCT .