Commit e763aa15 by manetta

### adding the situation embeddings exercise

parent 8e1eae3b
 # Table embeddings # written during Algolit # 13 April 2018 # Notes: https://pad.constantvzw.org/p/130418_algolit_word2vec2 import os from collections import Counter import pprint import random pp = pprint.PrettyPrinter(indent=4) filename = 'embeddings.train' text = open('{}.txt'.format(filename),'r').readlines() # [['empty, bankcard, pen holder\n'], # ['bankcard, pen holder, notebook\n'], # ['pen holder, notebook, keys\n']] main = {} # main = { # 'human' { # Counter({ # 'cup' : 1, # 'laptop' : 1, # }) # } # } for ngram in text: ngram = ngram.split(', ') center = ngram[1] left = ngram[0] right = ngram[2].replace('\n','') if not center in main: main[center] = Counter() main[center][left] +=1 main[center][right] +=1 pp.pprint(main) print('************') numbers = {1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four', 5 : 'five', 6 : 'six', 7 : 'seven', 8 : 'eight', 9 : 'nine', 10 : 'ten'} determiners = {3 : 'a few', 5 :'many', 7: 'a lot of', 6 : 'most', 2 : 'some', 1 : 'any', 4 : 'enough'} sentences = [] x = 0 for cw, c in main.items(): x += 1 wwords = [] wwordsandcounts = [] wwordsanddeterminers = [] for word, count in c.items(): wwords.append(word) if count > 1: word = word+'s' determiner = determiners[count] wwordsandcounts.append(numbers[count] + ' ' + word) wwordsanddeterminers.append(determiner + ' ' + word) intro = '' templates = [ 'What makes a {0} a {0}, is its closeness to {1} and {2}.'.format(cw, ', '.join(wwordsanddeterminers[:-1]), wwordsanddeterminers[-1]), 'You can identify a {} when it appears in the company of {} and {}.'.format(cw, ', '.join(wwordsandcounts[:-1]), wwordsandcounts[-1]), 'A {} can be recognized when it lies next to a {} and a {}.'.format(cw, ', '.join(wwords[:-1]), wwords[-1]) ] if x == 5: sentences.append('\nMeanwhile ...\n') x = 0 s = random.choice(templates) sentences.append(s) for sentence in sentences: print(sentence) head = '''

situation embeddings

''' foot = ''' ''' images = [f for f in os.listdir('./img/{}'.format(filename))] with open('{}.html'.format(filename),'w') as html: html.write(head) html.write(''.format(filename, random.choice(images))) i = 0 for sentence in sentences: if 'Meanwhile' in sentence: html.write('

'+sentence+'

') print(i, i % 2) if i % 2 == 0: html.write(''.format(filename, random.choice(images))) else: html.write(''.format(filename, random.choice(images))) else: html.write('

'+sentence+'

') i += 1 html.write(foot) print('*html file written*') \ No newline at end of file


situation embeddings

You can identify a hand when it appears in the company of one charger and one keys.

A cup can be recognized when it lies next to a charger, mouse, laptop, notebook, phone and a human.

What makes a box a box, is its closeness to any charger and any laptop.

You can identify a keys when it appears in the company of one hand, one notebook, one bottle and one extension block.

Meanwhile ...

What makes a pen holder a pen holder, is its closeness to any bankcard and any notebook.

You can identify a lego piece when it appears in the company of one laptop and one extension block.

A bowl can be recognized when it lies next to a sheet and a human.

A plate can be recognized when it lies next to a cable and a laptop.

What makes a notebook a notebook, is its closeness to any cup, any keys, any pen holder and any human.

Meanwhile ...

You can identify a extension block when it appears in the company of one lego piece and one keys.

What makes a charger a charger, is its closeness to any hand, some cups, any sheet, any box, any bottle, any laptop and any speaker.

What makes a sheet a sheet, is its closeness to any bowl and any charger.

What makes a bottle a bottle, is its closeness to any charger and any keys.

You can identify a speaker when it appears in the company of one charger and one phone.

Meanwhile ...

A bankcard can be recognized when it lies next to a empty and a pen holder.

What makes a cable a cable, is its closeness to any plate and any laptop.

A laptop can be recognized when it lies next to a lego piece, cup, box, charger, laptop, plate, cable and a human.

What makes a human a human, is its closeness to any cup, any mouse, any bowl, a few laptops, any notebook, any phone and enough humans.

You can identify a phone when it appears in the company of one cup and one speaker.

Meanwhile ...

What makes a mouse a mouse, is its closeness to any cup and any human.

 empty, bankcard, pen holder bankcard, pen holder, notebook pen holder, notebook, keys notebook, keys, hand keys, hand, charger hand, charger, box charger, box, laptop box, laptop, cup laptop, cup, mouse cup, mouse, human mouse, human, laptop human, laptop, plate laptop, plate, cable plate, cable, laptop cable, laptop, human laptop, human, bowl human, bowl, sheet bowl, sheet, charger sheet, charger, bottle charger, bottle, keys bottle, keys, extension block keys, extension block, lego piece extension block, lego piece, laptop lego piece, laptop, human laptop, human, human human, human, notebook human, notebook, cup notebook, cup, phone cup, phone, speaker phone, speaker, charger speaker, charger, cup charger, cup, laptop cup, laptop, charger laptop, charger, cup charger, cup, laptop cup, laptop, laptop laptop, laptop, cup laptop, cup, human cup, human, human human, human, phone


situation embeddings

What makes a human a human, is its closeness to any window and any chair.

You can identify a backpack when it appears in the company of one feet and one trash bin.

What makes a trash bin a trash bin, is its closeness to any backpack, some windows and any nothing.

A nothing can be recognized when it lies next to a feet, nothing, trash bin and a aisle.

Meanwhile ...

A feet can be recognized when it lies next to a backpack and a nothing.

What makes a window a window, is its closeness to any human, some trash bins and any chair.

You can identify a chair when it appears in the company of one human, two aisles and three chairs.

You can identify a aisle when it appears in the company of two nothings and two chairs.

 chair, chair, aisle chair, aisle, chair aisle, chair, chair chair, chair, human chair, human, window human, window, trash bin window, trash bin, backpack trash bin, backpack, feet backpack, feet, nothing feet, nothing, aisle, nothing, aisle, nothing aisle, nothing, nothing nothing, nothing, trash bin nothing, trash bin, window trash bin, window, chair

2.49 MB

2.4 MB

2.04 MB

2.07 MB

2.36 MB

2.36 MB

2.18 MB

2.33 MB

2.16 MB

2.05 MB

2.05 MB

2.02 MB

2 MB

2.03 MB

2.27 MB

2.34 MB

1.99 MB

2.07 MB

1.87 MB

1.98 MB

2.02 MB

2.45 MB

2.67 MB

2.59 MB

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!