コード例 #1
0
 def __init__(self, **kwargs: Dict[str, Any]):
     self.training_metrics = {}
     self.validation_metrics = {}
     for name, metric_kwargs in kwargs.items():
         # We need a special logic for the vocabulary, we do not want to deep copy it,
         # and it cannot be used in Params
         vocab = metric_kwargs.pop("vocabulary", None)
         self.training_metrics[name] = Metric.from_params(
             Params(copy.deepcopy(metric_kwargs)),
             **{} if vocab is None else {"vocabulary": vocab})
         self.validation_metrics[name] = Metric.from_params(
             Params(metric_kwargs),
             **{} if vocab is None else {"vocabulary": vocab})
コード例 #2
0
 def test_span_f1_can_build_from_params(self):
     params = Params(
         {"type": "non_bio_span_f1", "tag_namespace": "tags", "ignore_classes": ["V"]})
     metric = Metric.from_params(params, self.vocab)
     assert metric._ignore_classes == ["V"]
     assert metric._label_vocabulary == self.vocab.get_index_to_token_vocabulary(
         "tags")
コード例 #3
0
 def test_span_f1_can_build_from_params(self, device: str):
     params = Params({
         "type": "span_f1",
         "tag_namespace": "tags",
         "ignore_classes": ["V"]
     })
     metric = Metric.from_params(params=params, vocabulary=self.vocab)
     assert metric._ignore_classes == ["V"]  # type: ignore
     assert metric._label_vocabulary == self.vocab.get_index_to_token_vocabulary(  # type: ignore
         "tags")
コード例 #4
0
 def from_params(cls, vocab, params):
     text_field_embedder = TextFieldEmbedder.from_params(
         vocab, params.pop('text_field_embedder'))
     hidden_size = params.pop('hidden_size', 128)
     num_layers = params.pop('num_layers', 2)
     dropout = params.pop('dropout', 0.5)
     tag_namespace = params.pop('tag_namespace', 'tags')
     initializer = None
     initializer_params = params.pop('initializer', None)
     if initializer_params is not None:
         initializer = Initializer.from_params(initializer_params)
     metric = None
     metric_params = params.pop('metric', None)
     if metric_params is not None:
         metric = Metric.from_params(metric_params)
     params.assert_empty(cls.__name__)
     return cls(vocab, text_field_embedder, hidden_size=hidden_size, num_layers=num_layers,
                dropout=dropout, tag_namespace=tag_namespace, initializer=initializer,
                metric=metric)
コード例 #5
0
 def test_span_f1_can_build_from_params(self):
     params = Params({"type": "span_f1", "tag_namespace": "tags", "ignore_classes": ["V"]})
     metric = Metric.from_params(params=params, vocabulary=self.vocab)
     assert metric._ignore_classes == ["V"]
     assert metric._label_vocabulary == self.vocab.get_index_to_token_vocabulary("tags")
コード例 #6
0
 def test_span_f1_can_build_from_params(self):
     params = Params({u"type": u"span_f1", u"tag_namespace": u"tags", u"ignore_classes": [u"V"]})
     metric = Metric.from_params(params=params, vocabulary=self.vocab)
     assert metric._ignore_classes == [u"V"]
     assert metric._label_vocabulary == self.vocab.get_index_to_token_vocabulary(u"tags")