Haroldf01 commited on
Commit
3b64168
·
1 Parent(s): 80043e6

Create invoice_data.py

Browse files
Files changed (1) hide show
  1. invoice_data.py +117 -0
invoice_data.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """Introduction to the CoNLL-2003 Shared Task: Language-Independent Named Entity Recognition"""
18
+
19
+ import os
20
+
21
+ import datasets
22
+
23
+
24
+ logger = datasets.logging.get_logger(__name__)
25
+
26
+
27
+ _CITATION = """\
28
+ @inproceedings{BV-Custom-Invoice-Data,
29
+ title = "Invoice Data Shared Task: Language-Independent Named Entity Recognition",
30
+ author = "BureauVeritas",
31
+ }
32
+ """
33
+
34
+ _DESCRIPTION = """\
35
+ Custom Invoice Dataset
36
+ """
37
+
38
+ _URL = "dataset.tar.gz"
39
+
40
+
41
+ class InvoiceDataConfig(datasets.BuilderConfig):
42
+ """BuilderConfig for Conll2003"""
43
+
44
+ def __init__(self, **kwargs):
45
+ """BuilderConfig forConll2003.
46
+
47
+ Args:
48
+ **kwargs: keyword arguments forwarded to super.
49
+ """
50
+ super(InvoiceDataConfig, self).__init__(**kwargs)
51
+
52
+
53
+ class Conll2003(datasets.GeneratorBasedBuilder):
54
+ """Conll2003 dataset."""
55
+
56
+ BUILDER_CONFIGS = [
57
+ InvoiceDataConfig(name="InvoiceData", version=datasets.Version("1.0.0"), description="InvoiceDataConfig dataset"),
58
+ ]
59
+
60
+ def _info(self):
61
+ return datasets.DatasetInfo(
62
+ description=_DESCRIPTION,
63
+ features=datasets.Features(
64
+ {
65
+ "id": datasets.Value("string"),
66
+ "tokens": datasets.Sequence(datasets.Value("string")),
67
+ "ner_tags": datasets.Sequence(
68
+ datasets.features.ClassLabel(
69
+ names=[
70
+ "O",
71
+ "B-LOC",
72
+ "I-LOC",
73
+ "B-PROD",
74
+ "I-PROD",
75
+ "B-MODEL_YEAR",
76
+ "I-MODEL_YEAR",
77
+ "B-BRAND",
78
+ "I-BRAND",
79
+ "B-MODEL",
80
+ "I-MODEL",
81
+ "B-STATE",
82
+ "I-STATE",
83
+ "B-PRICE",
84
+ "I-PRICE",
85
+ "B-CHAR",
86
+ "I-CHAR",
87
+ ]
88
+ )
89
+ ),
90
+ }
91
+ ),
92
+ supervised_keys=None,
93
+ homepage="",
94
+ citation=_CITATION,
95
+ )
96
+
97
+ def _split_generators(self, dl_manager):
98
+ """Returns SplitGenerators."""
99
+ path = dl_manager.download_and_extract(_URL)
100
+
101
+ return [
102
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": os.path.join(path, 'dataset.jsonl')})
103
+ ]
104
+
105
+ def _generate_examples(self, filepath):
106
+ logger.info("⏳ Generating examples from = %s", filepath)
107
+ with open(filepath, encoding="utf-8") as f:
108
+ guid = 0
109
+ tokens = []
110
+ ner_tags = []
111
+ for line in f:
112
+ import json
113
+ print(json.loads(line))
114
+ obj = json.loads(line)
115
+
116
+ yield guid, obj
117
+ guid += 1