You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The constructor for ltn.Predicate accepts a model that outputs one truth degree in [0,1].
classModelThatOutputsATruthDegree(tf.keras.Model):
def__init__(self):
super().__init__()
self.dense1=tf.keras.layers.Dense(5, activation=tf.nn.relu)
self.dense2=tf.keras.layers.Dense(1, activation=tf.nn.sigmoid) # returns one value in [0,1]defcall(self, x):
x=self.dense1(x)
returnself.dense2(x)
model=ModelThatOutputsATruthDegree()
P1=ltn.Predicate(model)
P1(x) # -> call with a ltn Variable
Issue
Many models output several values simultaneously. For example, a model for the predicate P2 classifying images x into n classes type_1, ..., type_n will likely output n logits using the same hidden layers.
Eventually, we would expect to call the corresponding predicate using the syntax P2(x,type). This requires two additional steps:
Transforming the logits into values in [0,1],
Indexing the class using the term type.
Because this is a common use-case, we implemented a function ltn.utils.LogitsToPredicateModel for convenience. It is used in some of the examples (cf MNIST digit addition).
The syntax is:
logits_model(x) # how to call `logits_model`P2=ltn.Predicate(ltn.utils.LogitsToPredicateModel(logits_model), single_label=True)
P2([x,type]) # how to call the predicate
It automatically adds a final argument for class indexing and performs a sigmoid or softmax activation depending on the parameter single_label.
Proposition
It would be more elegant to have the functionality of creating a predicate from a logits model as a class constructor for ltn.Predicate.
Constructors for
ltn.Predicate
The constructor for
ltn.Predicate
accepts a model that outputs one truth degree in [0,1].Issue
Many models output several values simultaneously. For example, a model for the predicate
P2
classifying imagesx
into n classestype_1
, ...,type_n
will likely output n logits using the same hidden layers.Eventually, we would expect to call the corresponding predicate using the syntax
P2(x,type)
. This requires two additional steps:type
.Because this is a common use-case, we implemented a function
ltn.utils.LogitsToPredicateModel
for convenience. It is used in some of the examples (cf MNIST digit addition).The syntax is:
It automatically adds a final argument for class indexing and performs a sigmoid or softmax activation depending on the parameter
single_label
.Proposition
It would be more elegant to have the functionality of creating a predicate from a logits model as a class constructor for
ltn.Predicate
.A suggested syntax is:
single_label
parameter inltn.utils.LogitsToPredicateModel
,with_class_indexing=False
still allows creating predicates in the form ofP1(x)
, like abovementioned.Changes to the rest of the API
The proposition adds a new constructor but shouldn't change any other method of
ltn.Predicate
or any framework method in general.The text was updated successfully, but these errors were encountered: