use pie-modules instead of pytorch-ie
Browse filessee https://github.com/ArneBinder/pie-datasets/pull/204 for further information
- README.md +3 -3
- conll2003.py +29 -6
- requirements.txt +2 -1
README.md
CHANGED
|
@@ -15,13 +15,13 @@ and the following annotation layers:
|
|
| 15 |
|
| 16 |
- `entities` (annotation type: `LabeledSpan`, target: `text`)
|
| 17 |
|
| 18 |
-
See [here](https://github.com/
|
| 19 |
|
| 20 |
## Document Converters
|
| 21 |
|
| 22 |
The dataset provides document converters for the following target document types:
|
| 23 |
|
| 24 |
-
- `
|
| 25 |
|
| 26 |
-
See [here](https://github.com/
|
| 27 |
definitions.
|
|
|
|
| 15 |
|
| 16 |
- `entities` (annotation type: `LabeledSpan`, target: `text`)
|
| 17 |
|
| 18 |
+
See [here](https://github.com/ArneBinder/pie-modules/blob/main/src/pie_modules/annotations.py) for the annotation type definitions.
|
| 19 |
|
| 20 |
## Document Converters
|
| 21 |
|
| 22 |
The dataset provides document converters for the following target document types:
|
| 23 |
|
| 24 |
+
- `pie_modules.documents.TextDocumentWithLabeledSpans`
|
| 25 |
|
| 26 |
+
See [here](https://github.com/ArneBinder/pie-modules/blob/main/src/pie_modules/documents.py) for the document type
|
| 27 |
definitions.
|
conll2003.py
CHANGED
|
@@ -1,17 +1,40 @@
|
|
| 1 |
from dataclasses import dataclass
|
|
|
|
| 2 |
|
| 3 |
import datasets
|
| 4 |
-
from
|
| 5 |
-
from
|
| 6 |
-
from
|
| 7 |
-
from
|
| 8 |
|
| 9 |
from pie_datasets import GeneratorBasedBuilder
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
@dataclass
|
| 13 |
-
class CoNLL2003Document(
|
| 14 |
-
entities:
|
| 15 |
|
| 16 |
|
| 17 |
class Conll2003(GeneratorBasedBuilder):
|
|
|
|
| 1 |
from dataclasses import dataclass
|
| 2 |
+
from typing import List, Sequence, Tuple
|
| 3 |
|
| 4 |
import datasets
|
| 5 |
+
from pie_core import AnnotationLayer, annotation_field
|
| 6 |
+
from pie_modules.annotations import LabeledSpan
|
| 7 |
+
from pie_modules.documents import TextBasedDocument, TextDocumentWithLabeledSpans
|
| 8 |
+
from pie_modules.utils.sequence_tagging import tag_sequence_to_token_spans
|
| 9 |
|
| 10 |
from pie_datasets import GeneratorBasedBuilder
|
| 11 |
|
| 12 |
|
| 13 |
+
def tokens_and_tags_to_text_and_labeled_spans(
|
| 14 |
+
tokens: Sequence[str], tags: Sequence[str]
|
| 15 |
+
) -> Tuple[str, Sequence[LabeledSpan]]:
|
| 16 |
+
start = 0
|
| 17 |
+
token_offsets: List[Tuple[int, int]] = []
|
| 18 |
+
for token in tokens:
|
| 19 |
+
end = start + len(token)
|
| 20 |
+
token_offsets.append((start, end))
|
| 21 |
+
# we add a space after each token
|
| 22 |
+
start = end + 1
|
| 23 |
+
|
| 24 |
+
text = " ".join(tokens)
|
| 25 |
+
|
| 26 |
+
spans: List[LabeledSpan] = []
|
| 27 |
+
for label, (start, end) in tag_sequence_to_token_spans(tag_sequence=tags):
|
| 28 |
+
spans.append(
|
| 29 |
+
LabeledSpan(start=token_offsets[start][0], end=token_offsets[end][1], label=label)
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
return text, spans
|
| 33 |
+
|
| 34 |
+
|
| 35 |
@dataclass
|
| 36 |
+
class CoNLL2003Document(TextBasedDocument):
|
| 37 |
+
entities: AnnotationLayer[LabeledSpan] = annotation_field(target="text")
|
| 38 |
|
| 39 |
|
| 40 |
class Conll2003(GeneratorBasedBuilder):
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
pie-datasets>=0.
|
|
|
|
|
|
| 1 |
+
pie-datasets>=0.10.11,<0.11.0
|
| 2 |
+
pie-modules>=0.15.9,<0.16.0
|