Mean shift clustering "Gutenberg Children Books" 2019-02-18

"Gutenberg Children Books" corpus "LG-English-clean" dataset, ,
trash filter off: min_word_count = 31,21,11,6,2, max_sentence_length off, Link Grammar 5.5.1
.

This notebook is shared as static Mean-shift-clustering-GCB-LG-E-clean-2019-02-18.html.
Output data shared via Mean-shift-clustering-GCB-LG-E-clean-2019-02-18 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, test_stats
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)
2019-02-18 12:28:36 UTC :: module_path: /home/obaskov/94/language-learning

Corpus test settings

In [2]:
corpus = 'GCB' # 'Gutenberg-Children-Books-Caps' 
dataset = 'LG-E-clean'
kwargs = {
    'corpus'        :   corpus      ,
    'dataset'       :   dataset     ,
    'left_wall'     :   ''          ,
    'period'        :   False       ,
    'context'       :   1           ,
    'min_word_count':   1           ,
    'min_link_count':   1           ,
    'word_space'    :   'sparse'    ,
    'clustering'    :   ('mean_shift', 2),
    'clustering_metric' : ['silhouette', 'cosine'],
    'cluster_range' :   [0]         ,   # auto
    'top_level'     :   0.01        ,
    'grammar_rules' :   2           ,
    'max_disjuncts' :   1000000     ,   # off
    'stop_words'    :   []          ,
    'tmpath'        :   tmpath      ,
    'verbose'       :   'log+'      ,
    'template_path' :   'poc-turtle',
    'linkage_limit' :   1000        }
rp = module_path + '/data/' + corpus + '/LG-E-clean/GCB-LG-English-clean.ull'
cp = rp  # corpus path = reference_path
out_dir = module_path + '/output/' + 'MeanShift-GCB-LG-E-clean-' + str(UTC())[:10] + '_'
print(UTC(), '\n', out_dir)
2019-02-18 12:28:36 UTC 
 /home/obaskov/94/language-learning/output/MeanShift-GCB-LG-E-clean-2019-02-18_

Tests: "Child Directed Speech", "Gutenberg Children Boooks"

"Child Directed Speech" corpus

In [3]:
corpus  = 'CDS' # 'Child Directed Speech'
dataset = 'LG-E-clean'
kwargs['corpus']  = corpus
kwargs['dataset'] = dataset
kwargs['context']        = 2
kwargs['grammar_rules']  = 2
kwargs['min_word_count'] = 2
kwargs['min_link_count'] = 2
rp = module_path + '/data/' + corpus + '/' + dataset
cp = rp  # corpus path = reference_path
In [4]:
%%capture
kwargs['context'] = 1
kwargs['grammar_rules'] = 2
kwargs['cluster_range']  = [0]
kwargs['min_word_count'] = 1
kwargs['min_link_count'] = 1
line = [['1.1', corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
header[0] = 'CDS'
display(html_table([header] + a)); print(test_stats(log))
In [5]:
display(html_table([header] + a)); print(test_stats(log))
CDSCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
1.1CDSLG-E-cleancMLEdmean_shift---none---2451---0.0100%99%0.99[56, 2, 1, 0]
Cleaned dictionary: 301 words, grammar learn time: 00:00:06, grammar test time: 00:00:01
In [6]:
%%capture
kwargs['context'] = 2
line = [['1.2', corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
display(html_table([header] + a)); print(test_stats(log))
In [7]:
display(html_table([header] + a)); print(test_stats(log))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
1.2CDSLG-E-cleandMLEdmean_shift---none---2341---0.0100%98%0.99[68, 1, 0]
Cleaned dictionary: 301 words, grammar learn time: 00:00:07, grammar test time: 00:00:01
In [8]:
%%capture
dataset = 'LG-E-551'
kwargs['dataset'] = dataset
kwargs['context']        = 2
kwargs['grammar_rules']  = 2
kwargs['min_word_count'] = 11
kwargs['min_link_count'] = 2
line = [['1.3', corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
display(html_table([header] + a)); print(test_stats(log))
In [9]:
display(html_table([header] + a)); print(test_stats(log))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
1.3CDSLG-E-551dMLEdmean_shift---none---77811---0.099%97%0.97[39, 1, 0]
Cleaned dictionary: 816 words, grammar learn time: 00:01:34, grammar test time: 00:00:03
In [10]:
%%capture
kwargs['min_word_count'] = 1
kwargs['min_link_count'] = 1
line = [['1.4', corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
In [11]:
display(html_table([header] + a)); print(test_stats(log))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
1.4CDSLG-E-551dMLEdmean_shift---none---10751---0.0100%97%0.97[2237, 1, 0]
Cleaned dictionary: 3311 words, grammar learn time: 01:54:26, grammar test time: 00:00:04

"Gutenberg Children Books" corpus, min_word_count = 51,11,1

In [12]:
corpus  = 'GCB' # 'Gutenberg-Children-Books' 
dataset = 'LG-E-clean'
kwargs['corpus']  = corpus
kwargs['dataset'] = dataset
kwargs['context']        = 1
kwargs['grammar_rules']  = 2
kwargs['min_word_count'] = 1  # final objective - cell 18, line 2.3 
kwargs['min_link_count'] = 1
rp = module_path + '/data/' + corpus + '/LG-E-clean/GCB-LG-English-clean.ull'
cp = rp  # corpus path = reference_path
kwargs['reference_path'] = rp
table = []
In [13]:
%%capture
kwargs['min_word_count'] = 51
kwargs['min_link_count'] = 5
line = [['2.1', corpus, dataset, 0, 0, 'none']]
a, _, header, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
header[0] = 'GCB'
table.extend(a)
In [14]:
display(html_table([header] + a)); print(test_stats(log))
GCBCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
2.1GCBLG-E-cleancMLEdmean_shift---none---283651---0.047%40%0.47[1, 0]
Cleaned dictionary: 2836 words, grammar learn time: 00:32:39, grammar test time: 00:30:37
In [15]:
%%capture
kwargs['min_word_count'] = 11
kwargs['min_link_count'] = 3
line = [['2.2', corpus, dataset, 0, 0, 'none']]
a, _, h, log, rules = wide_rows(line, out_dir, cp, rp, runs, **kwargs)
table.extend(a)
In [16]:
display(html_table([header] + a)); print(test_stats(log))
GCBCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
2.2GCBLG-E-cleancMLEdmean_shift---none---793711---0.051%45%0.52[78, 6, 4, 3, 2]
Cleaned dictionary: 8035 words, grammar learn time: 04:46:14, grammar test time: 00:38:07
In [17]:
%%capture
kwargs['min_word_count'] = 1
kwargs['min_link_count'] = 1
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 [18]:
display(html_table([header] + a)); print(test_stats(log))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
2.3GCBLG-E-cleancMLEdmean_shift---none---93531---0.051%47%0.52[16121, 4, 3, 2, 1]
Cleaned dictionary: 25528 words, grammar learn time: 147:01:00, grammar test time: 00:41:26

Save results for "Gutengerg Children Books" corpus

In [19]:
display(html_table([header] + table))
LineCorpusParsingSpaceLinkageAffinityG12nThresholdRulesMWCNNSIPAPQF1Top 5 cluster sizes
2.1GCBLG-E-cleancMLEdmean_shift---none---283651---0.047%40%0.47[1, 0]
2.2GCBLG-E-cleancMLEdmean_shift---none---793711---0.051%45%0.52[78, 6, 4, 3, 2]
2.3GCBLG-E-cleancMLEdmean_shift---none---93531---0.051%47%0.52[16121, 4, 3, 2, 1]
In [20]:
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')
2019-02-25 00:35:10 UTC :: finished, elapsed 156.1 hours
Results saved to /home/obaskov/94/language-learning/output/MeanShift-GCB-LG-E-clean-2019-02-18_/all_tests_table.txt

Results for "Gutenberg Children Books" corpus with min_word_count = 31, 21, 11, 6, 2 are shared as static Mean-shift-clustering-GCB-LG-E-clean-2019-02-20.html.