I want to add a loss function to torch that calculates the edit distance between predicted and target values. Is there an easy way to implement this idea? Or do I have to write my own class with backward and forward functions?
相关问题
- How to convert a list of tensors into a torch::Ten
- Trying to understand code that computes the gradie
- How can I use table layers in torch to create my o
- Error in running Torch/Lua, maybe an installation
- How do you alter the size of a Pytorch Dataset?
相关文章
- RuntimeError: Expected object of backend CUDA but
- torch / lua: retrieving n-best subset from Tensor
- Torch tensor equivalent function to matlab's “
- Train a CNN-LSTLM end-to-end?
- Performing Convolution (NOT cross-correlation) in
- Error: caskroom/cask was moved. Tap homebrew/cask-
- How to crop image based on binary mask
- How to check if two Torch tensors or matrices are
If your criterion can be represented as a composition of existing modules and criteria, it's a good idea to simply construct such composition using containers. The only problem is that standard containers are designed to work with modules only, not criteria. The difference is in
:forward
method signature:Luckily, we are free to define our own container which is able work with criteria too. For example, sequential:
Below is an illustration of how to implement
nn.CrossEntropyCriterion
having this generalized sequential container:Check whether everything is correct:
Just to add to the accepted answer, you have to be careful that the loss function you define (edit distance in your case) is differentiable with respect to the network parameters.