Comments (5)
Because initially, the labeled score (in log space) could be something like -180
unlabeled score could be: 557
(I debugged inside and check the value).
In that case, when you take the exp
operation, it would be really close to zero, probably exceed the floating-point boundary in python/torch.
It's like torch.exp(-1000) = 0, and torch.exp(-500) still = 0.
Thus, log(0) gives you nan. That's why we prefer to work on log space directly
from pytorch_neural_crf.
I see, thanks again! :)
from pytorch_neural_crf.
Thanks Allan! I wanted to add something to the softmax, before log. I'll do more experiments :)
from pytorch_neural_crf.
Yes.
For CRF, it is a negative log-likelihood.
Mathematically, the probability p(y|x)
is:
If we take the negative loglikelihood, it becomes:
So the left-hand side is unlabeled_score
, the right-hand side is labeled_score
. And we make a subtraction.
You can also take an average (mean) to make the loss smaller but I guess it doesn't change a lot the performance.
from pytorch_neural_crf.
Hi Allan,
I have one more question if you don't mind.
If I change the loss like this:
p = torch.exp(labeled_score - unlabed_score)
return -torch.log(p)
it should work because unlabed_score - labeled_score is the nll loss, then probability should be expressed as above, and then I do -torch.log, it should generate the same nll loss, but instead it generates "nan" at each epoch.
Thanks, Allan!
from pytorch_neural_crf.
Related Issues (20)
- AttributeError: 'str' object has no attribute 'size' HOT 2
- Macro F1 and Precision HOT 2
- get error when running in torch 1.81 HOT 4
- ValueError: The label B-MISC does not exist in label2idx dict. The label might not appear in the training set. HOT 1
- How to tweak the learning rate of CRF layer? HOT 1
- Errors when running the default model HOT 7
- Is there a way to use local model checkpoints for Hugginface models ? HOT 3
- About orig_to_token_index padding problem HOT 2
- About CRF layer HOT 3
- Evaluation question HOT 1
- About GLOVE result F1 91.36 HOT 9
- Can not run ner_predictor.py HOT 3
- Please help me? HOT 7
- Summary of training/finetuning/prediction commands HOT 2
- Learning on Heterogeneous Tag Sets using Tag Hierarchy HOT 1
- Use custom pre-trained BERT models HOT 2
- purpose of token_type_ids or segments HOT 2
- load data error HOT 5
- computation of partition function HOT 11
- ImportError: cannot import name 'context_models' from 'src.config' when running transformers_predictor.py HOT 2
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 pytorch_neural_crf.