You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was playing around a variation of spERT, where the relations where extracted using a softmax instead of a sigmoid.
To ensure the correctness of the overall system I trained it with the version of conll04 that you provided with the model and everything seemed fine.
The issues arose when trying to train it with a different dataset, converted to a format compatible with spERT.
Train went smoothly, but the model didn't make any prediction at all, be it an entity or relation. I am for sure missing something, I was wondering if you could maybe provide to me a direction from which start to work.
Here is a single sample from the training dataset:
--- Entities (named entity recognition (NER)) ---
An entity is considered correct if the entity type and span is predicted correctly
type precision recall f1-score support
drug_n 0.00 0.00 0.00 101.0
drug 0.00 0.00 0.00 1396.0
group 0.00 0.00 0.00 538.0
brand 0.00 0.00 0.00 169.0
micro 0.00 0.00 0.00 2204.0
macro 0.00 0.00 0.00 2204.0
--- Relations ---
Without named entity classification (NEC)
A relation is considered correct if the relation type and the spans of the two related entities are predicted correctly (entity type is not considered)
With named entity classification (NEC)
A relation is considered correct if the relation type and the two related entities are predicted correctly (in span and entity type)
def_convert_pred_relations(rel_clf: torch.tensor, rels: torch.tensor,
entity_types: torch.tensor, entity_spans: torch.tensor, input_reader: BaseInputReader):
-rel_class_count=rel_clf.shape[1]
-rel_clf=rel_clf.view(-1)
# get predicted relation labels and corresponding entity pairs-rel_nonzero=rel_clf.nonzero().view(-1)
-pred_rel_scores=rel_clf[rel_nonzero]
--pred_rel_types= (rel_nonzero%rel_class_count) +1# model does not predict None class (+1)-valid_rel_indices=rel_nonzero//rel_class_count+valid_rel_indices=torch.nonzero(torch.sum(rel_clf, dim=-1)).view(-1)
+valid_rel_indices=valid_rel_indices.view(-1)
++pred_rel_types=rel_clf[valid_rel_indices]
+ifpred_rel_types.shape[0] !=0:
+pred_rel_types=pred_rel_types.argmax(dim=-1)
+valid_rel_indices=torch.nonzero(pred_rel_types).view(-1)
++pred_rel_types=pred_rel_types[valid_rel_indices]
++pred_rel_scores=rel_clf[valid_rel_indices]
+ifpred_rel_scores.shape[0] !=0:
+pred_rel_scores=pred_rel_scores.max(dim=-1)[0]
valid_rels=rels[valid_rel_indices]
Not related to the previous topic, thought I'd add it here since the same dataset is involved.
During the experimentation with the original spERT I changed bert to scibert. Using 1 epoch of training I had no issues whatsoever, when I increased them to 5 the procedure to store the predictions started to pick up relations that should instead be filtered out by previous elaboration (if I interpreted everything correctly).
Here is the log
--- Entities (named entity recognition (NER)) ---
An entity is considered correct if the entity type and span is predicted correctly
type precision recall f1-score support
brand 0.00 0.00 0.00 169.0
drug 0.00 0.00 0.00 1396.0
drug_n 0.00 0.00 0.00 101.0
group 0.00 0.00 0.00 538.0
micro 0.00 0.00 0.00 2204.0
macro 0.00 0.00 0.00 2204.0
--- Relations ---
Without named entity classification (NEC)
A relation is considered correct if the relation type and the spans of the two related entities are predicted correctly (entity type is not considered)
With named entity classification (NEC)
A relation is considered correct if the relation type and the two related entities are predicted correctly (in span and entity type)
Process SpawnProcess-1:
Traceback (most recent call last):
File "/home/deeplearning/.conda/envs/salvalai/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/home/deeplearning/.conda/envs/salvalai/lib/python3.8/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/home/deeplearning/Salvalai/spert/spert.py", line 16, in __train
trainer.train(train_path=run_args.train_path, valid_path=run_args.valid_path,
File "/home/deeplearning/Salvalai/spert/spert/spert_trainer.py", line 97, in train
self._eval(model, validation_dataset, input_reader, epoch + 1, updates_epoch)
File "/home/deeplearning/Salvalai/spert/spert/spert_trainer.py", line 253, in _eval
evaluator.store_predictions()
File "/home/deeplearning/Salvalai/spert/spert/evaluator.py", line 87, in store_predictions
prediction.store_predictions(self._dataset.documents, self._pred_entities,
File "/home/deeplearning/Salvalai/spert/spert/prediction.py", line 196, in store_predictions
head_idx = converted_entities.index(converted_head)
ValueError: {'type': 'None', 'start': 0, 'end': 1} is not in list
Best regards
The text was updated successfully, but these errors were encountered:
Hi,
I just pushed a corner case handling (commit e0d9aee) which may be related to your problem. In some cases (especially strings containing only control characters) the tokenizer we are using maps tokens to empty sequences, which could lead to zero divisions (and NaN values) down the road. Can you please check if the commit fixes your problem? If so, it would still be better to remove any control characters from your dataset beforehand.
If this does not fix your isuse, could you please send me the dataset (or a representative part of it) by email ([email protected])? I can have a look at it then.
Hi @markus-eberts ,
thanks for sharing your great work.
I was playing around a variation of spERT, where the relations where extracted using a softmax instead of a sigmoid.
To ensure the correctness of the overall system I trained it with the version of conll04 that you provided with the model and everything seemed fine.
The issues arose when trying to train it with a different dataset, converted to a format compatible with spERT.
Train went smoothly, but the model didn't make any prediction at all, be it an entity or relation. I am for sure missing something, I was wondering if you could maybe provide to me a direction from which start to work.
Here is a single sample from the training dataset:
On this dataset the softmax is recommended since all the relations are symmetrical and between two entities exists only a single relation.
Here is the log of the training run:
The following are the major changes that I applied to the original model:
spert/spert_trainer.py
spert/loss.py
spert/sampling.py
spert/models.py
spert/predictions.py
spert/predictions.py
Not related to the previous topic, thought I'd add it here since the same dataset is involved.
During the experimentation with the original spERT I changed bert to scibert. Using 1 epoch of training I had no issues whatsoever, when I increased them to 5 the procedure to store the predictions started to pick up relations that should instead be filtered out by previous elaboration (if I interpreted everything correctly).
Here is the log
Best regards
The text was updated successfully, but these errors were encountered: