Gutenberg children books agglomerative clustering 2018-10-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, server 88.99.210.144.
This notebook is shared as static Gutenberg-Children-Books-500-disjuncts-10-20-50-clusters-2018-10-31.html
The "All tests" table is shared as 'all_tests_table.txt' in Gutenberg-Children-Books-500-disjuncts-2018-10-31 directory.

_1st results 2018-10-29,30 were manually saved to 88.../clustering2018; updated 2018-10-31

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()

Corpus test settings

In [2]:
corpus = 'Gutenberg-Children-Books-Caps'
disjuncts = 500
out = module_path + '/output/' + corpus + '-' \
    + str(disjuncts) + '-disjuncts-' + str(UTC())[:10]
kwargs = {
    'output_grammar':   out         ,
    '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' :   disjuncts   ,
    'tmpath'        :   tmpath      , 
    'verbose'       :   'min'       ,
    'template_path' :   'poc-turtle',
    'linkage_limit' :   1000        ,
    'path': '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/pg24878.txt_headless_split_U.ull'
check_corpus(rp, 'max')
cp = rp  # corpus path = reference_path :: use 'gold' parses as test corpus
runs = (1,1)
def out_dir(**kwargs):
    path = kwargs['output_grammar'] + '/' + corpus \
        + '-' + str(kwargs['cluster_range']) + '-clusters-'  + str(UTC())[:10]
    if check_dir(path, True, 'none'):
        return path
print(f'Output dir structure: {out_dir(**kwargs)}')
Input file: /home/obaskov/88/language-learning/data/Gutenberg-Children-Books-Caps/LG-English/pg24878.txt_headless_split_U.ull
Output dir structure: /home/obaskov/88/language-learning/output/Gutenberg-Children-Books-Caps-500-disjuncts-2018-10-31/Gutenberg-Children-Books-Caps-10-clusters-2018-10-31

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

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

In [9]:
display(html_table([header] + table2))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd10 --- 65%34%0.35
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd20 --- 61%34%0.36
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd50 --- 40%18%0.23

LG-ANY-all-parses-agm-opt: ... line 48

In [16]:
display(html_table([header] + table3))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd10 --- 64%32%0.36
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd20 --- 64%34%0.37
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd50 --- 48%24%0.29

All tests

In [17]:
display(html_table([header] + table))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd10 --- 65%34%0.35
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd20 --- 61%34%0.36
39Gutenberg-Children-Books-CapsLG-English --- --- nonecALEd50 --- 40%18%0.23
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd10 --- 64%32%0.36
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd20 --- 64%34%0.37
48Gutenberg-Children-Books-CapsLG-ANY-all-parses-agm-opt --- --- nonecALEd50 --- 48%24%0.29
In [18]:
print(UTC(), ':: finished, elapsed', str(round((time.time()-start)/3600.0, 1)), 'hours')
table_str = list2file(table, out + '/all_tests_table.txt')
print('Results saved to', out + '/all_tests_table.txt')
2018-10-31 15:22:21 UTC :: finished, elapsed 6.1 hours
Results saved to /home/obaskov/88/language-learning/output/Gutenberg-Children-Books-Caps-500-disjuncts-2018-10-31/all_tests_table.txt