Child Directed Speech test 2018-12-05

Agglomerative clustering, test_grammar updated 2018-10-19 , Link Grammar 5.5.1, server 94.130.238.118
This notebook is shared as static Child-Directed-Speech-2018-12-05.html;
The "All tests" table is shared as 'short_table.txt' in Child-Directed-Speech-2018-12-05 directory.
Previous tests: Child-Directed-Speech-2018-10-24.html,
Child-Directed-Speech-2018-10-19.html, Child-Directed-Speech-2018-08-14.html, Child-Directed-Speech-2018-08-06.html.

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
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')
table = []
long_table = []
start = time.time()
out_dir = module_path + '/output/Child-Directed-Speech-' + str(UTC())[:10]
print(UTC(), ':: out_dir:\n', out_dir)
runs = (1,1)
2018-12-05 09:46:58 UTC :: out_dir:
 /home/obaskov/94/language-learning/output/Child-Directed-Speech-2018-12-05

Corpus test settings

In [2]:
kwargs = {
    'left_wall'     :   ''          ,
    'period'        :   False       ,
    'min_word_count':           1   ,
    'min_link_count':           1   ,
    'min_co-occurrence_count':  1   ,
    'word_space'    :   'vectors'   ,
    'clustering'    :   ['kmeans', 'kmeans++', 10],
    'cluster_range' :   [30,120,3,3],
    'cluster_criteria'  : 'silhouette',
    'clustering_metric' : ['silhouette', 'cosine'],
    'cluster_level' :   1           ,
    'rules_merge'       :   0.8     , # grammar rules merge threshold
    'rules_aggregation' :   0.1     , # grammar rules aggregation threshold
    'top_level'         :   0.01    , # top-level rules generalization threshold
    'tmpath'        :   tmpath      , 
    'verbose'       :   'min'       ,
    'template_path' :   'poc-turtle',
    'linkage_limit' :   1000        }
lines = [
    [33, 'CDS-caps-br-text+brent9mos' , 'LG-English'                     ,0,0, 'none'  ], 
    [34, 'CDS-caps-br-text+brent9mos' , 'LG-English'                     ,0,0, 'rules' ], 
    [35, 'CDS-caps-br-text+brent9mos' , 'R=6-Weight=6:R-mst-weight=+1:R' ,0,0, 'none'  ], 
    [36, 'CDS-caps-br-text+brent9mos' , 'R=6-Weight=6:R-mst-weight=+1:R' ,0,0, 'rules' ]]
rpp = module_path + '/data/CDS-caps-br-text+brent9mos/LG-English'
cpp = rpp   # previous 2018-11-24 tests
cp = rp = module_path + '/data/CDS/LG-E-clean'  # clean: both files, 100% parsed
cp = rp     # test corpus path = reference_path

ULL Project Plan ⇒ Parses ⇒ lines 33-36, by columns (K-N), (O-Q)

Connectors-DRK-Connectors

In [3]:
%%capture
kwargs['context'] = 1
kwargs['grammar_rules'] = 1
average21, long21, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average21)
long_table.extend(long21)
In [4]:
display(html_table([header]+average21))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonecDRKc890.1796%73%0.76
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonecDRKc610.1389%50%0.53

Connectors-DRK-Disjuncts

In [5]:
%%capture
kwargs['context'] = 1
kwargs['word_space'] = 'vectors'
kwargs['clustering'] = 'kmeans'
kwargs['grammar_rules'] = 2
average22, long22, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average22)
long_table.extend(long22)
In [6]:
display(html_table([header]+average22))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonecDRKd890.1799%88%0.89
34CDS-caps-br-text+brent9mosLG-English --- --- rulescDRKd110.1799%73%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonecDRKd650.1287%48%0.51
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulescDRKd620.1388%49%0.52

Disjuncts-DRK-Disjuncts

In [7]:
%%capture
kwargs['context'] = 2
kwargs['word_space'] = 'vectors'
kwargs['clustering'] = 'kmeans'
kwargs['grammar_rules'] = 2
average23, long23, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average23)
long_table.extend(long23)
In [8]:
display(html_table([header]+average23))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedDRKd830.3499%90%0.91
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdDRKd340.3599%74%0.76
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedDRKd900.586%48%0.51
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdDRKd890.586%47%0.50

Disjuncts-ILE-Disjuncts

In [9]:
%%capture
kwargs['context'] = 2
kwargs['word_space'] = 'discrete'
kwargs['clustering'] = 'group'
kwargs['grammar_rules'] = 2
average24, long24, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average24)
long_table.extend(long24)
In [10]:
display(html_table([header] + average24))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedILEd2980 --- 99%97%0.98
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdILEd1820 --- 99%96%0.97
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedILEd3558 --- 69%43%0.45
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdILEd3129 --- 71%43%0.45

Disjuncts-ALE-Disjuncts

2018-10-24 test with clean test and reference datasets

In [11]:
%%capture
kwargs['context'] = 2
kwargs['grammar_rules'] = 2
kwargs['word_space'] = 'sparse'
kwargs['clustering'] = ['agglomerative', 'ward']
kwargs['clustering_metric'] = ['silhouette', 'cosine']
kwargs['min_word_count'] = 11
kwargs['min_link_count'] = 1
kwargs['min_co-occurrence_count'] = 1
average25 = []
crange = kwargs['cluster_range']
for kwargs['cluster_range'] in [10,20,50,100]:
    average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
    average25.append(average)
    table.extend(average)
    long_table.extend(long)
kwargs['cluster_range'] = crange
In [12]:
for tbl in average25:
    display(html_table([header] + tbl))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd10 --- 96%71%0.74
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd10 --- 96%71%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd10 --- 86%46%0.49
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd9 --- 86%46%0.49
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd20 --- 96%74%0.77
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd19 --- 96%74%0.77
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd20 --- 85%46%0.50
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd1 --- 86%46%0.49
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd50 --- 95%80%0.83
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd15 --- 96%72%0.75
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd50 --- 82%45%0.48
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd3 --- 86%46%0.49
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd100 --- 94%85%0.88
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd50 --- 96%71%0.73
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd100 --- 78%43%0.47
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd10 --- 86%46%0.49

Linkage/affinity: ward/euclidean; 50/400 clusters

In [14]:
%%capture
kwargs['cluster_range'] = 50
kwargs['min_word_count'] = 1
kwargs['clustering'] = ['agglomerative', 'ward']
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
In [15]:
display(html_table([header] + average))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd50 --- 99%86%0.87
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd13 --- 99%75%0.76
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd50 --- 86%48%0.51
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd49 --- 88%49%0.51
In [16]:
%%capture
kwargs['cluster_range'] = 400
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
In [17]:
display(html_table([header] + average))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd400 --- 99%97%0.97
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd281 --- 99%95%0.95
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd400 --- 73%44%0.46
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd291 --- 82%47%0.50

Linkage/affinity: complete/cosine; 50/400 clusters

In [18]:
%%capture
kwargs['cluster_range'] = 50
kwargs['clustering'] = ['agglomerative', 'complete', 'cosine']
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
In [19]:
display(html_table([header] + average))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd50 --- 99%73%0.74
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd50 --- 99%73%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd50 --- 89%50%0.52
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd50 --- 89%50%0.52
In [20]:
%%capture
kwargs['cluster_range'] = 400
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
In [21]:
display(html_table([header] + average))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd400 --- 99%75%0.76
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd125 --- 99%73%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd400 --- 89%50%0.52
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd400 --- 89%50%0.52

Linkage/affinity: average/cosine; 50/400 clusters

In [22]:
%%capture
kwargs['cluster_range'] = 50
kwargs['clustering'] = ['agglomerative', 'complete', 'cosine']
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
In [23]:
display(html_table([header] + average))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd50 --- 99%73%0.74
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd50 --- 99%73%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd50 --- 89%50%0.52
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd50 --- 89%50%0.52
In [24]:
%%capture
kwargs['cluster_range'] = 400
average, long, header = table_rows(lines, out_dir, cp, rp, runs, **kwargs)
table.extend(average)
long_table.extend(long)
In [25]:
display(html_table([header] + average))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd400 --- 99%75%0.76
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd125 --- 99%73%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd400 --- 89%50%0.52
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd400 --- 89%50%0.52

All tests

In [26]:
display(html_table([header]+long_table))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonecDRKc 89 0.1796%73%0.76
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonecDRKc 61 0.1389%50%0.53
33CDS-caps-br-text+brent9mosLG-English --- --- nonecDRKd 89 0.1799%88%0.89
34CDS-caps-br-text+brent9mosLG-English --- --- rulescDRKd 11 0.1799%73%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonecDRKd 65 0.1287%48%0.51
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulescDRKd 62 0.1388%49%0.52
33CDS-caps-br-text+brent9mosLG-English --- --- nonedDRKd 83 0.3499%90%0.91
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdDRKd 34 0.3599%74%0.76
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedDRKd 90 0.586%48%0.51
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdDRKd 89 0.586%47%0.50
33CDS-caps-br-text+brent9mosLG-English --- --- nonedILEd 2980 --- 99%97%0.98
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdILEd 1820 --- 99%96%0.97
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedILEd 3558 --- 69%43%0.45
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdILEd 3129 --- 71%43%0.45
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 10 --- 96%71%0.74
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 10 --- 96%71%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 10 --- 86%46%0.49
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 9 --- 86%46%0.49
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 20 --- 96%74%0.77
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 19 --- 96%74%0.77
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 20 --- 85%46%0.50
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 1 --- 86%46%0.49
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 50 --- 95%80%0.83
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 15 --- 96%72%0.75
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 50 --- 82%45%0.48
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 3 --- 86%46%0.49
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 100 --- 94%85%0.88
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 50 --- 96%71%0.73
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 100 --- 78%43%0.47
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 10 --- 86%46%0.49
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 50 --- 99%86%0.87
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 13 --- 99%75%0.76
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 50 --- 86%48%0.51
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 49 --- 88%49%0.51
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 400 --- 99%97%0.97
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 281 --- 99%95%0.95
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 400 --- 73%44%0.46
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 291 --- 82%47%0.50
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 50 --- 99%73%0.74
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 50 --- 99%73%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 50 --- 89%50%0.52
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 50 --- 89%50%0.52
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 400 --- 99%75%0.76
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 125 --- 99%73%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 400 --- 89%50%0.52
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 400 --- 89%50%0.52
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 50 --- 99%73%0.74
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 50 --- 99%73%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 50 --- 89%50%0.52
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 50 --- 89%50%0.52
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 400 --- 99%75%0.76
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 125 --- 99%73%0.74
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 400 --- 89%50%0.52
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 400 --- 89%50%0.52
In [27]:
print(UTC(), ':: finished, elapsed', str(round((time.time()-start)/3600.0, 1)), 'hours')
table_str = list2file(table, out_dir+'/short_table.txt')
if runs == (1,1):
    print('Results saved to', out_dir + '/short_table.txt')
else:
    long_table_str = list2file(long_table, out_dir+'/long_table.txt')
    print('Average results saved to', out_dir + '/short_table.txt\n'
          'Detailed results for every run saved to', out_dir + '/long_table.txt')
2018-12-05 12:31:12 UTC :: finished, elapsed 2.7 hours
Results saved to /home/obaskov/94/language-learning/output/Child-Directed-Speech-2018-12-05/short_table.txt