Comments (6)
Gradients are not averaged, however the losses are if the loss is instantiated in such a way.
Relevant part is here:
https://github.com/uma-pi1/kge/blob/master/kge/job/train.py#L270
penalty_values = self.model.penalty(
epoch=self.epoch, batch_index=batch_index, num_batches=len(self.loader)
)
for pv_index, pv_value in enumerate(penalty_values):
penalty_value = penalty_value + pv_value
if len(sum_penalties) > pv_index:
sum_penalties[pv_index] += pv_value.item()
else:
sum_penalties.append(pv_value.item())
sum_penalty += penalty_value.item()
batch_forward_time += time.time()
forward_time += batch_forward_time
# backward pass
batch_backward_time = -time.time()
cost_value = loss_value + penalty_value
cost_value.backward()
penalty_value is not averaged.
from kge.
Loss average implies gradient average. The relevant code piece is here:
loss_value, batch_size, batch_prepare_time, batch_forward_time = self._compute_batch_loss(
batch_index, batch
)
sum_loss += loss_value.item() * batch_size
_compute_batch_loss
is thus supposed to average, that's why it's multiplied by the batch size afterwards.
7aa82ce should thus be reverted. If anything, the norms should be averaged over the number of training examples. But since this is constant (and can be thus be viewed as part of lambda) and not meaningful for all penalties, we shouldn't do this.
from kge.
So smaller batch size (bs) means more penalty per epoch? With your suggestion we apply a penalty of N / bs * || T || per epoch and with mine || T || , correct?
Another question to this topic: Why didn't we implement the weighted norm like in the CP paper?
from kge.
Perhaps _compute_batch_loss
should be renamed into _compute_batch_loss_avg
to be easier to interpret.
from kge.
Yes, more penalty per epoch. But also more loss per epoch, since the gradient of every example now has more impact in every step. Again, without the patch:
E[gradient] = E[gradient of a random example] + gradient of penatly term
This is what we want: the expected gradient is independent of the batch size.
from kge.
As for weighted norm: that's a separate issue. If you mean that frequency-based weighting is not implemented: #20
from kge.
Related Issues (20)
- bash: kge: command not found HOT 1
- Support more metrics?
- How to apply HittER
- Number of negative samples during evaluation HOT 3
- web.informatik.uni-mannheim.de not accesible HOT 2
- ValueError thrown by `$ kge start examples/toy-complex-train.yaml` HOT 3
- Using buffer for writing to a file during preprocessing
- ConvE and reciprocal_relations_model HOT 2
- Getting output of libKGE
- Relation Prediction HOT 5
- Filtered _ro prediction HOT 1
- Frequency based sampling broken
- Error on tensor scoring HOT 1
- Adding user keys to config HOT 2
- Trial XXXXX failed: TypeError("step() missing 1 required positional argument: 'closure'") HOT 2
- ERROR: file:///content does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found. HOT 3
- generate embeddings HOT 1
- Trained embeddings are missing for Codex-{S/M/L} HOT 1
- dataset issues HOT 3
- Getting model predictions in parallel HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kge.