User:Alice/Prototyping trim4: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
Line 5: Line 5:
Spacy is an NLP library for Python that is supposed to make some things simpler (potentially easier than NLTK?), such as training, for instance.
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 [https://medium.com/@akankshamalhotra24/introduction-to-libraries-of-nlp-in-python-nltk-vs-spacy-42d7b2f128f2 this article] which compares the two, and SpaCy seems to be performing better speed-wise and not only.
I have decided to give SpaCy a try, since I found working with NLTK a bit cumbersome at times. I also read [https://medium.com/@akankshamalhotra24/introduction-to-libraries-of-nlp-in-python-nltk-vs-spacy-42d7b2f128f2 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
<source lang='python'>
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_)
</source>

Revision as of 14:55, 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_)