2018-10_29-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.
This notebook is shared as static Gutenberg-Children-Books-1000-disjuncts-10-20-50-clusters-2018-10-29.html.
The "All tests" table is shared as 'all_tests_table.txt' in Gutenberg-Children-Books-1000-disjuncts=2018-10-29 directory.
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()
#print(UTC(), ':: module_path =', module_path)
corpus = 'Gutenberg-Children-Books-Caps'
kwargs = {
'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' : 1000 ,
'tmpath' : tmpath ,
'verbose' : 'min' ,
'template_path' : 'poc-turtle',
'linkage_limit' : 1000 ,
'categories_generalization': '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'
rp = module_path + '/data/' + corpus + '/LG-English/pg24878.txt_headless_split_U.ull'
check_corpus(rp, 'max')
# sftp://[email protected]/home/obaskov/94/language-learning/data/Gutenberg-Children-Books-Caps/LG-English/pg24878.txt_headless_split_U.ull
cp = rp # corpus path = reference_path :: use 'gold' parses as test corpus
runs = (1,1)
def out_dir(**kwargs):
path = module_path + '/output/' + corpus + '-' \
+ str(kwargs['cluster_range']) + '-clusters-' \
+ str(kwargs['max_disjuncts']) + '-disjuncts-' + str(UTC())[:10] + '_'
if check_dir(path, True, 'none'):
return path
out_dir(**kwargs)
%%capture
table = []
table2 = []
kwargs['cluster_range'] = 10
average, _, header = table_rows([lines[0]], out_dir(**kwargs), cp, rp, runs, **kwargs)
table.extend(average)
table2.extend(average)
display(html_table([header] + table2))
%%capture
table3 = []
kwargs['cluster_range'] = 10
average, _, header = table_rows([lines[1]], out_dir(**kwargs), cp, rp, runs, **kwargs)
table.extend(average)
table3.extend(average)
display(html_table([header] + table3))
display(html_table([header] + table))
print(UTC(), ':: finished, elapsed', str(round((time.time()-start)/3600.0, 1)), 'hours')
out = '/home/obaskov/94/language-learning/output/Gutenberg-Children-Books-Caps-1000-disjuncts-2018-10-29'
if check_dir(out, True, 'none'):
table_str = list2file(table, out + '/all_tests_table.txt')
print('Results saved to', out + '/all_tests_table.txt')