-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[🐛 Bug Report]: IndexOutOfBoundsException while training the model #23
Comments
Thank you for opening the issue. I can't reproduce the same error as you reported, but your dataset (both example and query) has an issue that might be the cause of your problem. In (Py)NeuraLogic, you can have two types of terms - logical variables (represented by strings) and constants (represented by numeric values or strings). I assume that "Dorothy", "Michael", and "Donald" are supposed to be specific entities, which should be represented as constants. Constants represented as strings have to start (by convention) with lower case letters ("dorothy", "donald" etc.) Your template seems to be okay. The only thing is that those two rules in the first comment are not equivalent to the rules you wrote in PyNeuraLogic (your version is absolutely valid, just not equivalent).
The equivalent to that would be: template.add_rules([
(R.special.embed_person(V.A)[3,] <= R.person(V.A)),
(R.special.embed_rel(V.B)[3,] <= R.rel(V.B))
]) The template.add_rules([
*[(R.person_embed(p)[3,] <= R.person(p)) for p in ("dorothy", "donald", "michael")],
*[(R.rel_embed(r)[3,] <= R.rel(r)) for r in ("father", "sister", "aunt")]
]) I listed only entities (people and relations) from your provided example, but the idea is to list all entities and embed them into unique (not shared) vectors [3,] (just like in embeddings.txt here)
This (your) rule would embed all possible entities into one shared vector. |
Hi @LukasZahradnik, thank you very much for your prompt response. I fixed both the issues that you pointed out and I was able to proceed with training the model. However, now I encountered a different issue. From the very first epoch, the loss seems to be already near 0, and it stays pretty much the same during the rest of epochs. These are some debug logs to illustrate:
I tried to examine different possibilities to find out what's wrong but I couldn't find much. The only thing I noticed is that the
It looks like there is something wrong with the queries that I pass to the dataset. I don't really understand how the NeuraLogic interprets the queries and how it translates them to actual classes. Do you know what could be the problem here? |
Do you have also negative examples in your queries? Like in the nations dataset, where it's 50:50. |
firstly, For example:
Regarding the issue you have, it looks like you are providing only positive examples (as @GustikS stated above). When your queries have no labels ( In your case, you might want to add some negative examples with queries such as |
@GustikS @LukasZahradnik thank you for your responses, I generated some negative example-query pairs and now the training works as expected. However, I realized that with the current setting, the model performs a binary classification task, which is not quite the task that I intended to perform initially with CLUTRR. What I wanted to achieve instead is a multi class classification of the query entity pair based on the input graph. Now I have to provide the model with a query (entityA, relation, entityB) and the model outputs 0/1 based on whether it thinks that the relation holds between the two entities. Instead, I would like to only input (entityA, entityB) and have the model predict the correct relation out of all possible (20) relations. What changes would I need to make to the model definition to be able to perform this multiclass classification task? Is there maybe a better example of multiclass classification performed in Neuralogic, since the one I used as a template no longer seems to be appropriate for my use case? My first idea was to keep the examples the same and only alter the queries in the following way
Where the parameter is a one-hot encoded vector representing the correct relation. Is this a valid line of thought? If so, how would I need to alter the template? Thank you. |
Hi, ok I didn't realize they treat it as a multiclass classification and not knowledge-base completion. However, when you move it to vectors/tensors like that you lose the relational expressiveness, i.e. ability to work with the term/relations in more sophisticated ways, e.g. changing the propagation scheme based on the relation. For that you'd want to keep the logical encoding and just "brute-force" enlist all the 20 queries (19 negative and 1 positive) with each example graph. Eventually, you might play with a combination of the two approaches, i.e. supply both the one-hot encoding and the logical relation term. That will require some thinking/experimentation when modifying the template, but some interesting modelling constructs might come out of that... |
Since this is not a bug but rather a discussion, let us move it there... |
Describe the bug
I am trying to train a simple model using the PyNeraLogic framework on the CLUTRR dataset.
However, after creating my Dataset and setting up the Template, I am getting the following error before the first training epoch starts:
Steps to reproduce the behavior
My Template is based on this example.
One sample graph in the CLUTRR dataset looks as follows
The input triplets and the target pair
(Donald, Dorothy)
are given and the task is to predict their relationship (aunt
), it is thus an R-way classification task where R is the total number of relations (such as aunt, father, ...).Below you can see the dataset creation process
This results in a dataset that looks like this:
The template definition is equivalent to the definition of the example template mentioned above, but it is rewritten to the PyNeuraLogic syntax. It looks as follows:
The evaluator definition and part of training loop can be seen here. The last line triggers the exception.
Expected behavior
calling
evaluator.train(dataset)
should yield(current_total_loss, number_of_samples)
correctly instead of raising an exceptionEnvironment
Google Colab (Python 3.6)
Additional context
Also, are there any other fundamental issues with the way I defined the dataset and architecture for this particular task? I am still trying to wrap my head around the way this framework works and how to rewrite PyG code to neuralogic language.
Thank you!
The text was updated successfully, but these errors were encountered: