Comments (2)
Agree with you @lyconghk . Have you come up with any better solution to apply mlm_weights_X
in mlm_l
calculation?
The weight
parameter of PyTorch CrossEntropyLoss
does not seem to support mlm_weights_X
in the way that the MXNet does. I guess that is why the PyTorch version of _get_batch_loss_bert
calculate mlm_l
in this way. It tries to reduce the impact of padded tokens to mlm_l
, but it does not use mlm_weights_X
in an correct way.
from d2l-en.
How about just use the package torch.nn import functional
to calculate the two cross entropy loss of mlm and nsp?
And remove the input parameter loss
in the function _get_batch_loss_ber
.
from torch.nn import functional as F
mlm_l = F.cross_entropy(mlm_Y_hat.reshape(-1, vocab_size), mlm_Y.reshape(-1), reduction='none')
nsp_l = F.cross_entropy(nsp_Y_hat, nsp_Y, reduction='mean')
from d2l-en.
Related Issues (20)
- AttributeError: module 'd2l.torch' has no attribute 'train_ch3' HOT 5
- module 'd2l.torch' has no attribute 'count_corpus' HOT 3
- A question about 4.7.3.3. Label Shift Correction HOT 1
- PyTorch Colab of Chapter 13.5 is having an IndexError HOT 2
- Free copy for the first 100 contributors
- Ethics?
- MLX support HOT 1
- Add type hinting to functions HOT 1
- Incorrect Use of torch.no_grad() in fit_epoch Method in d2l/torch.py::Trainer::fit_epoch HOT 2
- Not able to render :begin_tab:toc
- Errors in train_ch3 in tensorflow version softmax-regression-scratch.ipynb HOT 1
- [**emergency**] the comment block is down, please fix it right now HOT 1
- Chinese version of the code is out of date
- The discussion link can not be accessed. HOT 7
- Can't build the book on MacOS when trying to add MLX implementation
- Some issues with the book
- WikiText-2 is not a zip file HOT 2
- question about ”d2l = sys.modules[__name__]“
- Website of preview version is down. HOT 5
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 d2l-en.