User:Alice/Prototyping trim4

From XPUB & Lens-Based wiki

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 .

A Django application called The Mealgeneer

Based on the personal nutrient profile system on completefoods.co, it will be a humorous exaggeration of personal recommendation of nutrients/vitamins you would need to consume.

Idea: Check the recommendations, make up a meal, associate each quantity of nutrient with a corresponding real food item, then create a meal named after a real version using those ingredients.

The Mealgeneer is your personal sys-admin who recommends you personalized reverse-engineered meals based on your personal profile. What could go wrong?

My personalized nutritional needs
Ideal proportions

Publishing experiments with zines/flipbooks/booklets

Generating flipbooks from YouTube videos

The script and documentation for this can be found here.

Food flipbook.png

Sound to image

Experiments with translating sounds and tones to raw data, and then to images.

The resulting image can be superimposed with other images, such as photos and gradients.

Superimpose sound.jpg


Experiments with generating a gradient using Python

import math
from PIL import Image
im = Image.new('RGB', (1000, 1000))
ld = im.load()

def gaussian(x, a, b, c, d=0):
    return a * math.exp(-(x - b)**2 / (2 * c**2)) + d

for x in range(im.size[0]):
    r = int(gaussian(x, 231.3135, 666, 201.5447) + gaussian(x, 17.1017, 395.8819, 45))
    g = int(gaussian(x, 129.9851, 157.7571, 108.0298) + gaussian(x, 27.6831, 399.4535, 143.6828))
    b = int(gaussian(x, 3000, 3000, 8.0739) + gaussian(x, 158.8242, 402, 87.0739))
    for y in range(im.size[1]):
        ld[x, y] = (r, g, b)
im.save('test2.png', 'PNG')

Test2.png

from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import landscape
from reportlab.lib.colors import (
    darkorchid, peachpuff, tan, teal,
    orangered, papayawhip, royalblue,
    red, green, blue, yellow, cornsilk,
    rosybrown
)
from reportlab.lib.units import mm

canvas = Canvas("gradient.pdf")
canvas.setPageSize((210*mm, 297*mm))
canvas.linearGradient(10*mm, 200*mm, 190*mm, 100*mm, (teal, papayawhip))
canvas.showPage()
canvas.save()
Date sound.png