-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs and some fixes to high-level apis
- Loading branch information
William Cohen
committed
Jul 1, 2016
1 parent
7021ec8
commit 619c695
Showing
14 changed files
with
211 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
Theano-based version of ProPPR - see 'docs' directory | ||
TensorLog is outlined in a [http://arxiv.org/abs/1605.06523 technical | ||
paper]. There is documentation on the | ||
[https://github.com/TeamCohen/TensorLog/wiki GitHub wiki page]. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
test: | ||
(cd cora; make) | ||
(cd wordnet; make) | ||
(cd grid; make) | ||
(cd smokers; make) | ||
|
||
clean: | ||
(cd cora; make clean) | ||
(cd wordnet; make clean) | ||
(cd grid; make clean) | ||
(cd smokers; make clean) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#TODO: fix for new API | ||
|
||
VPATH= raw | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#TODO: update for new API | ||
|
||
default: | ||
echo make what? | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ expt: | |
python smokers-expt.py | ||
|
||
clean: | ||
rm *~ *.pyc | ||
rm -f *~ *.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
BASICS | ||
|
||
A Tensorlog DATABASE is holds a bunch of unary and binary relations, | ||
which are encoded as scipy sparse matrixes. The human-readable format | ||
for this is a set of files with the .cfacts extension. Some examples, | ||
from src/test/textcattoy.cfacts: | ||
|
||
hasWord dh a | ||
hasWord dh pricy | ||
hasWord dh doll | ||
hasWord dh house | ||
hasWord ft a | ||
hasWord ft little | ||
hasWord ft red | ||
hasWord ft fire | ||
hasWord ft truck | ||
... | ||
label pos | ||
label neg | ||
|
||
An additional column can be added which is a numeric weight (so don't | ||
use any constant that parses to a number in a cfacts file to avoid | ||
program confusion.) A database can be SERIALIZED and should be stored | ||
in a directory with extension .db. | ||
|
||
A Tensorlog PROGRAM usually has extension .ppr. Some examples: | ||
|
||
------------------------------------------------------------------------------ | ||
predict(X,Pos) :- assign(Pos,pos) {all(F): hasWord(X,W),posPair(W,F)}. | ||
predict(X,Neg) :- assign(Neg,neg) {all(F): hasWord(X,W),negPair(W,F)}. | ||
|
||
match(R,S) :- fname(R,FR),fmatch(FR,FS),fname(S,FS) {f}. | ||
match(R,S) :- lname(R,LR),lmatch(LR,LS),lname(S,LS) {l}. | ||
match(R,S) :- addr(R,AR),amatch(AR,AS),addr(S,AS) {a}. | ||
------------------------------------------------------------------------------ | ||
|
||
If you use the ProPPR-style rule features (in the curly braces) you | ||
should | ||
- make sure any constants appearing there are in the database | ||
- load the rule file as 'proppr' format, which is NOT the default. | ||
There's no serialized form of a program. | ||
|
||
A Tensorlog DATASET is given in a file .exam with lines of the form "P | ||
<tab> X <tab> Y1 <tab> Yk" where | ||
|
||
- P is the functor of some predicate defined in your program | ||
- X is an input | ||
- Y1...Yk are ALL the outputs for X that are considered correct | ||
|
||
Eg, this dataset essentially labels match(r1,r2) and match(r1,r1) as | ||
positive, and any other fact match(r1,foo) as negative. The constant | ||
r3 should only match itself: | ||
|
||
---------------------------------------- | ||
match r1 r2 r1 | ||
match r3 r3 | ||
.... | ||
---------------------------------------- | ||
|
||
A serialized dataset has extension .dset. | ||
|
||
|
||
HOW TO RUN AN EXPERIMENT: | ||
|
||
Look at the sample main in src/expt.py, and the sample input files in | ||
src/test/textcattoy.cfacts and src/test/textcat.ppr. Some other | ||
larger examples are in datasets/cora/cora-expt.py and | ||
datasets/wordnet/wnet-expt.py. | ||
|
||
|
||
HOW TO CONFIGURE TENSORLOG: | ||
|
||
Some of the modules have a config.Config() object, which is just an | ||
object that contains fields which can be used as options. Any | ||
user-settable parameters should be in these objects. | ||
|
||
HOW TO SERIALIZE A .cfacts FILE AND CREATE A DB FILE: | ||
|
||
% python matrixdb.py --serialize foo.cfacts foo.db | ||
|
||
HOW TO DEBUG A TENSORLOG PROGRAM: | ||
|
||
Start up an interpreter with the command | ||
|
||
% python -i -m tensorlog --programFiles foo.db:foo.ppr:foo.cfacts:... | ||
|
||
You can then evaluate functions with commands like: | ||
|
||
% ti.eval("foo/io", "input_constant") | ||
|
||
Try setting these config options before you do | ||
|
||
ops.trace = True | ||
conf.trace = True | ||
|
||
You can also insert "printf literals" into a clause, eg | ||
|
||
p(X,Z1):-printf(X,X1),spouse(X1,Y),printf(Y,Y1),sister(Y1,Z),printf(Z,Z1). | ||
|
||
These literals just copy the input to the output, but will echo the | ||
bindings of the variables when the message-passing happens. (Make | ||
sure the output variable of the printf is used somewhere "downstream", | ||
otherwise it's undefined when the print will actually happen.) | ||
|
||
Finally there is the debug.py module, which contains a start at a | ||
graphical debugger. | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
predict pb pos | ||
predict yc pos | ||
predict rb2 pos | ||
predict rp pos | ||
predict bp neg | ||
predict he neg | ||
predict wt neg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
predict pb pos | ||
predict yc pos | ||
predict rb2 pos | ||
predict rp pos | ||
predict bp neg | ||
predict he neg | ||
predict wt neg | ||
|