Gutenberg children books agglomerative clustering 2018-10_29-31

Test set: 1 file pg24878.txt_headless_split_U.ull, 2.1 MB - Lucy Maud Montgomery Short Stories.
Agglomerative clustering, test_grammar updated 2018-10-19 , Link Grammar 5.4.4.
This notebook is shared as static Gutenberg-Children-Books-1000-disjuncts-10-20-50-clusters-2018-10-29.html.
The "All tests" table is shared as 'all_tests_table.txt' in Gutenberg-Children-Books-1000-disjuncts=2018-10-29 directory.

Basic settings

In [1]:
import os, sys, time
module_path = os.path.abspath(os.path.join('..'))
if module_path not in sys.path: sys.path.append(module_path)
from src.grammar_learner.utl import UTC
from src.grammar_learner.read_files import check_dir, check_corpus
from src.grammar_learner.write_files import list2file
from src.grammar_learner.widgets import html_table
from src.grammar_learner.pqa_table import table_rows
tmpath = module_path + '/tmp/'
check_dir(tmpath, True, 'none')
start = time.time()
#print(UTC(), ':: module_path =', module_path)

Corpus test settings

In [2]:
corpus = 'Gutenberg-Children-Books-Caps'
kwargs = {
    'min_word_count':   31          , # ~7000+ words
    'min_link_count':   2           ,
    'min_co-occurrence_count':  1   ,
    'min_co-occurrence_probability' : 1e-9 ,
    'left_wall'     :   ''          ,
    'period'        :   False       ,
    'context'       :   1           ,
    'word_space'    :   'sparse'    ,
    'clustering'    :   ('agglomerative', 'ward'),
    'cluster_range' :   10          ,
    'cluster_criteria'  : 'silhouette',
    'clustering_metric' : ('silhouette', 'cosine'),
    'cluster_level' :   1           ,
    'grammar_rules' :   2           ,
    'max_disjuncts' :   1000        ,
    'tmpath'        :   tmpath      , 
    'verbose'       :   'min'       ,
    'template_path' :   'poc-turtle',
    'linkage_limit' :   1000        ,
    'categories_generalization': 'off' }
lines = [
    [39, corpus , 'LG-English'                 ,0,0, 'none'  ], 
    [48, corpus , 'LG-ANY-all-parses-agm-opt'  ,0,0, 'none'  ]]
# rp = module_path + '/data/' + corpus + '/LG-English'
rp = module_path + '/data/' + corpus + '/LG-English/pg24878.txt_headless_split_U.ull'
check_corpus(rp, 'max')
# sftp://[email protected]/home/obaskov/94/language-learning/data/Gutenberg-Children-Books-Caps/LG-English/pg24878.txt_headless_split_U.ull
cp = rp  # corpus path = reference_path :: use 'gold' parses as test corpus
runs = (1,1)
def out_dir(**kwargs):
    path = module_path + '/output/' + corpus + '-' \
        + str(kwargs['cluster_range']) + '-clusters-' \
        + str(kwargs['max_disjuncts']) + '-disjuncts-' + str(UTC())[:10] + '_'
    if check_dir(path, True, 'none'):
        return path
out_dir(**kwargs)
File exists: /home/obaskov/94/language-learning/data/Gutenberg-Children-Books-Caps/LG-English/pg24878.txt_headless_split_U.ull
Out[2]:
'/home/obaskov/94/language-learning/output/Gutenberg-Children-Books-Caps-10-clusters-1000-disjuncts-2018-10-29_'

Tests: ULL Project Plan ⇒ Parses ⇒ lines 39, 48

LG-English: ULL Project Plan ⇒ Parses ⇒ line 39

In [3]:
%%capture
table = []
table2 = []
kwargs['cluster_range'] = 10
average, _, header = table_rows([lines[0]], out_dir(**kwargs), cp, rp, runs, **kwargs)
table.extend(average)
table2.extend(average)
In [9]:
display(html_table([header] + table2))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd10 --- 65%33%0.33
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd20 --- 65%37%0.38
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd50 --- 50%26%0.31

LG-ANY-all-parses-agm-opt: ULL Project Plan ⇒ Parses ⇒ line 48

In [10]:
%%capture
table3 = []
kwargs['cluster_range'] = 10
average, _, header = table_rows([lines[1]], out_dir(**kwargs), cp, rp, runs, **kwargs)
table.extend(average)
table3.extend(average)
In [16]:
display(html_table([header] + table3))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd10 --- 64%32%0.35
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd20 --- 64%34%0.37
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd20 --- 64%34%0.37

All tests

In [17]:
display(html_table([header] + table))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd10 --- 65%33%0.33
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd20 --- 65%37%0.38
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd50 --- 50%26%0.31
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd10 --- 64%32%0.35
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd20 --- 64%34%0.37
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd20 --- 64%34%0.37
In [19]:
print(UTC(), ':: finished, elapsed', str(round((time.time()-start)/3600.0, 1)), 'hours')
out = '/home/obaskov/94/language-learning/output/Gutenberg-Children-Books-Caps-1000-disjuncts-2018-10-29'
if check_dir(out, True, 'none'):
    table_str = list2file(table, out + '/all_tests_table.txt')
    print('Results saved to', out + '/all_tests_table.txt')
2018-10-31 18:16:55 UTC :: finished, elapsed 51.1 hours
Results saved to /home/obaskov/94/language-learning/output/Gutenberg-Children-Books-Caps-1000-disjuncts-2018-10-29/all_tests_table.txt