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
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 = '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)}')
display(html_table([header] + table2))
display(html_table([header] + table3))
display(html_table([header] + table))
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')