Child Directed Speech test 2018-11-08, Link Grammar 5.5.1.

Agglomerative clustering, test_grammar updated 2018-10-19, Link Grammar 5.5.1; server 88.99.210.144.
This notebook is shared as static Child-Directed-Speech-2018-11-08.html
The "All tests" table is shared as 'short_table.txt' in Child-Directed-Speech-2018-11-08 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()
print(UTC(), ':: module_path =', module_path)
2018-11-08 10:00:31 UTC :: module_path = /home/obaskov/language-learning

Corpus test settings

In [2]:
out_dir = module_path + '/output/Child-Directed-Speech-' + str(UTC())[:10]
runs = (1,1)
if runs != (1,1): out_dir += '-multi'
kwargs = {
    'left_wall'     :   ''          ,
    'period'        :   False       ,
    'min_word_count':   1           ,
    'min_link_count':   1           ,
    'max_words'     :   100000      ,
    'max_features'  :   100000      ,
    '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           ,
    'tmpath'        :   tmpath      , 
    'verbose'       :   'min'       ,
    'template_path' :   'poc-turtle',
    'linkage_limit' :   1000        ,
    'categories_generalization': 'off' }
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' ]]
rp = module_path + '/data/CDS-caps-br-text+brent9mos/LG-English'
cp = rp  # corpus path = reference_path :: use 'gold' parses as test corpus

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 --- --- nonecDRKc850.1770%50%0.51
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonecDRKc650.1270%44%0.44

Connectors-DRK-Disjuncts

In [5]:
%%capture
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 --- --- nonecDRKd860.1769%57%0.57
34CDS-caps-br-text+brent9mosLG-English --- --- rulescDRKd800.1770%57%0.57
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonecDRKd730.1269%43%0.43
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulescDRKd650.1269%43%0.43

Disjuncts-DRK-Disjuncts

In [7]:
%%capture
kwargs['context'] = 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 --- --- nonedDRKd610.3469%57%0.58
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdDRKd900.3467%59%0.60
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedDRKd840.567%42%0.42
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdDRKd890.567%42%0.42

Disjuncts-ILE-Disjuncts

In [9]:
%%capture
kwargs['word_space'] = 'discrete'
kwargs['clustering'] = 'group'
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 --- 58%59%0.59
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdILEd2423 --- 59%59%0.59
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedILEd3558 --- 59%39%0.39
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdILEd3415 --- 59%39%0.39

Disjuncts-ALE-Disjuncts

In [11]:
%%capture
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]:
    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 --- 66%46%0.46
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd10 --- 66%46%0.46
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd10 --- 64%39%0.40
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd10 --- 64%39%0.40
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd20 --- 66%47%0.48
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd20 --- 66%47%0.48
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd20 --- 64%39%0.40
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd20 --- 64%39%0.40
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd50 --- 64%50%0.51
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd50 --- 64%50%0.51
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd50 --- 63%38%0.39
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd50 --- 63%38%0.39

All tests

In [13]:
display(html_table([header]+long_table))
LineCorpusParsingLWRWGen.SpaceRulesSilhouettePAPQF1
33CDS-caps-br-text+brent9mosLG-English --- --- nonecDRKc 85 0.1770%50%0.51
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonecDRKc 65 0.1270%44%0.44
33CDS-caps-br-text+brent9mosLG-English --- --- nonecDRKd 86 0.1769%57%0.57
34CDS-caps-br-text+brent9mosLG-English --- --- rulescDRKd 80 0.1770%57%0.57
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonecDRKd 73 0.1269%43%0.43
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulescDRKd 65 0.1269%43%0.43
33CDS-caps-br-text+brent9mosLG-English --- --- nonedDRKd 61 0.3469%57%0.58
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdDRKd 90 0.3467%59%0.60
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedDRKd 84 0.567%42%0.42
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdDRKd 89 0.567%42%0.42
33CDS-caps-br-text+brent9mosLG-English --- --- nonedILEd 2980 --- 58%59%0.59
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdILEd 2423 --- 59%59%0.59
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedILEd 3558 --- 59%39%0.39
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdILEd 3415 --- 59%39%0.39
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 10 -0.0266%46%0.46
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 10 -0.0266%46%0.46
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 10 -0.0264%39%0.40
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 10 -0.0264%39%0.40
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 20 -0.0366%47%0.48
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 20 -0.0366%47%0.48
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 20 -0.0364%39%0.40
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 20 -0.0364%39%0.40
33CDS-caps-br-text+brent9mosLG-English --- --- nonedALEd 50 -0.0564%50%0.51
34CDS-caps-br-text+brent9mosLG-English --- --- rulesdALEd 50 -0.0564%50%0.51
35CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- nonedALEd 50 -0.0363%38%0.39
36CDS-caps-br-text+brent9mosR=6-Weight=6:R-mst-weight=+1:R --- --- rulesdALEd 50 -0.0363%38%0.39
In [14]:
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-11-08 11:10:18 UTC :: finished, elapsed 1.2 hours
Results saved to /home/obaskov/language-learning/output/Child-Directed-Speech-2018-11-08/short_table.txt