Delicalib commited on
Commit
8813f81
·
verified ·
1 Parent(s): 0f62137

Update spaCy pipeline

Browse files
README.md CHANGED
@@ -45,5 +45,7 @@ model-index:
45
  | `F1_CONNECTED-WITH` | 13.81 |
46
  | `F1_IN-MANNER-OF` | 11.96 |
47
  | `F1_ATTRIBUTE-FOR` | 17.36 |
 
 
48
  | `TRANSFORMER_LOSS` | 0.77 |
49
  | `RELATION_EXTRACTOR_LOSS` | 111.45 |
 
45
  | `F1_CONNECTED-WITH` | 13.81 |
46
  | `F1_IN-MANNER-OF` | 11.96 |
47
  | `F1_ATTRIBUTE-FOR` | 17.36 |
48
+ | `F1_MACRO` | 0.00 |
49
+ | `F1_WEIGHTED` | 0.00 |
50
  | `TRANSFORMER_LOSS` | 0.77 |
51
  | `RELATION_EXTRACTOR_LOSS` | 111.45 |
relationFactory.py CHANGED
@@ -1,34 +1,28 @@
1
- from itertools import islice
2
  from typing import Tuple, List, Iterable, Optional, Dict, Callable, Any
3
 
4
- from spacy.scorer import PRFScore
5
- from thinc.types import Floats2d
 
 
 
 
 
 
 
 
 
 
6
  import numpy
7
  from spacy.training.example import Example
8
- from thinc.api import Model, Optimizer
9
- from spacy.tokens.doc import Doc
10
  from spacy.pipeline.trainable_pipe import TrainablePipe
11
  from spacy.vocab import Vocab
12
  from spacy import Language
13
  from thinc.model import set_dropout_rate
14
  from wasabi import Printer
15
-
16
- from typing import List, Tuple, Callable
17
-
18
- import spacy
19
- from spacy.tokens import Doc, Span
20
- from thinc.types import Floats2d, Ints1d, Ragged, cast
21
- from thinc.api import Model, Linear, chain, Logistic
22
-
23
- import json
24
- import os
25
- import time
26
- from pathlib import Path
27
-
28
- from sklearn.metrics import precision_recall_fscore_support, f1_score
29
  import plotly.express as px
30
  import plotly.graph_objects as go
31
 
 
32
  @spacy.registry.architectures("rel_model.v1")
33
  def create_relation_model(
34
  create_instance_tensor: Model[List[Doc], Floats2d],
@@ -270,17 +264,6 @@ class RelationExtractor(TrainablePipe):
270
  self.set_annotations(docs, predictions)
271
  return losses
272
 
273
- def get_focal_loss(self, examples: Iterable[Example], scores, gamma=3.0, alpha=0.25, eps=1e-8) -> Tuple[float, float]:
274
- truths = self._examples_to_truth(examples)
275
- scores_2 = numpy.clip(scores, eps, 1. - eps)
276
- p_t = numpy.clip(scores_2 * truths + (1 - scores_2) * (1 - truths), eps, 1. - eps)
277
-
278
- focal_loss = -(1 - p_t) ** gamma * numpy.log(p_t)
279
- loss = numpy.mean(numpy.sum(focal_loss, axis=1))
280
- gradient = focal_loss * (1 - 2 * truths)
281
- return float(loss), gradient
282
-
283
-
284
  def get_loss(self, examples: Iterable[Example], scores) -> Tuple[float, float]:
285
  """Find the loss and gradient of loss for the batch of documents and
286
  their predicted scores."""
 
 
1
  from typing import Tuple, List, Iterable, Optional, Dict, Callable, Any
2
 
3
+ import json
4
+ import os
5
+ import time
6
+ from itertools import islice
7
+ from pathlib import Path
8
+
9
+ import spacy
10
+ from spacy.tokens import Doc, Span
11
+ from thinc.types import Floats2d, Ints1d, Ragged, cast
12
+ from thinc.api import Model, Linear, chain, Logistic, Optimizer
13
+
14
+ from sklearn.metrics import precision_recall_fscore_support, f1_score
15
  import numpy
16
  from spacy.training.example import Example
 
 
17
  from spacy.pipeline.trainable_pipe import TrainablePipe
18
  from spacy.vocab import Vocab
19
  from spacy import Language
20
  from thinc.model import set_dropout_rate
21
  from wasabi import Printer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  import plotly.express as px
23
  import plotly.graph_objects as go
24
 
25
+
26
  @spacy.registry.architectures("rel_model.v1")
27
  def create_relation_model(
28
  create_instance_tensor: Model[List[Doc], Floats2d],
 
264
  self.set_annotations(docs, predictions)
265
  return losses
266
 
 
 
 
 
 
 
 
 
 
 
 
267
  def get_loss(self, examples: Iterable[Example], scores) -> Tuple[float, float]:
268
  """Find the loss and gradient of loss for the batch of documents and
269
  their predicted scores."""
ru_patents_rel-any-py3-none-any.whl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:01a4762ef635162b3d38a964bf53b46c50d350f75b69c96116caecc4e4660464
3
- size 661156608
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:123967bb99f193af5288262919e0a68942706cbe9acc5e3a27b22fb6dc6bfa31
3
+ size 661156390