Gutenberg Children Books agglomerative clustering 2018-12-08

Tests: "LG English", no limits, 10/50/500/1000/2000 clusters.

Agglomerative clustering, test_grammar updated 2018-10-19 , Link Grammar 5.4.4.
This notebook is shared as static Gutenberg-Children-Books-2018-12-08.html.
The "All tests" table is shared as 'all_tests_table.txt' in Gutenberg-Children-Books-2018-12-08 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, params, wide_rows
tmpath = module_path + '/tmp/'
check_dir(tmpath, True, 'none')
start = time.time()
runs = (1,1)
#print(UTC(), ':: module_path =', module_path)

Corpus test settings

In [2]:
corpus = 'Gutenberg-Children-Books-Caps'
dataset = 'LG-English'
kwargs = {
    'left_wall'     :   ''          ,
    'period'        :   False       ,
    'context'       :   1           ,
    'min_word_count':   31          ,   # ~7K words
    'word_space'    :   'sparse'    ,
    'clustering'    :   ['agglomerative', 'ward'],
    'clustering_metric' : ['silhouette', 'cosine'],
    'cluster_range' :   1000        ,
    'top_level'     :   0.01        ,
    'grammar_rules' :   2           ,
    'max_disjuncts' :   1000000     ,   # off
    'tmpath'        :   tmpath      , 
    'verbose'       :   'min'       ,
    'template_path' :   'poc-turtle',
    'linkage_limit' :   1000        }   # no tests
lines = [
    [45, corpus , 'LG-English'                 ,0,0, 'none'  ], 
    [46, corpus , 'LG-ANY-all-parses-agm-opt'  ,0,0, 'none'  ]]
rp = module_path + '/data/' + corpus + '/LG-E-clean/GCB-LG-English-clean.ull'
# rp = module_path + '/data/' + corpus + '/LG-English/pg24878.txt_headless_split_U.ull'
cp = rp  # corpus path = reference_path :: use 'gold' parses as test corpus
runs = (1,1)
out_dir = module_path + '/output/' + corpus + '-' + str(UTC())[:10]
#if check_corpus(rp, 'min'): print(UTC(), out_dir)

Tests: "LG English", no limits, 10/50/500/1000/2000 clusters

In [3]:
%%capture
table = []
kwargs['cluster_range'] = 2000
line = [[2.1, corpus, dataset, 0, 0, 'none']]
#a, _, header, log, rules = wide_rows([lines[0]], out_dir(**kwargs), cp, rp, runs, **kwargs)
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
table.extend(a)
In [4]:
display(html_table([header] + a))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesNNSIPAPQF1Top 5 cluster sizes
2.1Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---2000---0.047%43%0.50[145, 138, 137, 126, 117]
In [5]:
%%capture
kwargs['cluster_range'] = 1000
line = [[2.2, corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
table.extend(a)
In [6]:
display(html_table([header] + a))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesNNSIPAPQF1Top 5 cluster sizes
2.2Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---1000---0.048%43%0.50[384, 325, 286, 241, 236]
In [7]:
%%capture
kwargs['cluster_range'] = 500
line = [[2.3, corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
table.extend(a)
In [8]:
display(html_table([header] + a))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesNNSIPAPQF1Top 5 cluster sizes
2.3Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---500---0.050%44%0.51[1002, 466, 437, 384, 381]
In [9]:
%%capture
kwargs['cluster_range'] = 100
line = [[2.4, corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
table.extend(a)
In [10]:
display(html_table([header] + a))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesNNSIPAPQF1Top 5 cluster sizes
2.4Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---100---0.060%44%0.46[1414, 1094, 978, 824, 721]
In [12]:
%%capture
kwargs['cluster_range'] = 50
line = [[2.5, corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
table.extend(a)
In [13]:
display(html_table([header] + a))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesNNSIPAPQF1Top 5 cluster sizes
2.5Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---50---0.062%40%0.42[1414, 1350, 1146, 1116, 721]
In [15]:
%%capture
kwargs['cluster_range'] = 20
line = [[2.6, corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
table.extend(a)
In [16]:
display(html_table([header] + a))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesNNSIPAPQF1Top 5 cluster sizes
2.6Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---20---0.062%35%0.36[3281, 2466, 437, 371, 261]
In [18]:
%%capture
kwargs['cluster_range'] = 10
line = [[2.7, corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
table.extend(a)
In [19]:
display(html_table([header] + a))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesNNSIPAPQF1Top 5 cluster sizes
2.7Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---10---0.00%0%0.00[3281, 2466, 632, 498, 72]

All tests

In [20]:
display(html_table([header] + table))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesNNSIPAPQF1Top 5 cluster sizes
2.1Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---2000---0.047%43%0.50[145, 138, 137, 126, 117]
2.2Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---1000---0.048%43%0.50[384, 325, 286, 241, 236]
2.3Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---500---0.050%44%0.51[1002, 466, 437, 384, 381]
2.4Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---100---0.060%44%0.46[1414, 1094, 978, 824, 721]
2.5Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---50---0.062%40%0.42[1414, 1350, 1146, 1116, 721]
2.6Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---20---0.062%35%0.36[3281, 2466, 437, 371, 261]
2.7Gutenberg-Children-Books-CapsLG-EnglishcALWEdwardeuclideannone---10---0.00%0%0.00[3281, 2466, 632, 498, 72]

Interrupted after 51+ hours run with 10 clusters setting

In [22]:
print(UTC(), ':: finished, elapsed', str(round((time.time()-start)/3600.0, 1)), 'hours')
table_str = list2file(table, out_dir + '/all_tests_table.txt')
print('Results saved to', out_dir + '/all_tests_table.txt')
2018-12-11 07:49:15 UTC :: finished, elapsed 72.8 hours
Results saved to /home/obaskov/94/language-learning/output/Gutenberg-Children-Books-Caps-2018-12-08/all_tests_table.txt