napsternxg commited on
Commit
820660d
1 Parent(s): 073d962

Upload nyt_ingredients.py

Browse files
Files changed (1) hide show
  1. nyt_ingredients.py +111 -0
nyt_ingredients.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ """New York Times Ingredient Phrase Tagger Dataset"""
3
+
4
+
5
+ import datasets
6
+
7
+
8
+ logger = datasets.logging.get_logger(__name__)
9
+
10
+
11
+ _CITATION = """\
12
+ @misc{nytimesTaggedIngredients,
13
+ author = {Erica Greene and Adam Mckaig},
14
+ title = {{O}ur {T}agged {I}ngredients {D}ata is {N}ow on {G}it{H}ub --- archive.nytimes.com},
15
+ howpublished = {\url{https://archive.nytimes.com/open.blogs.nytimes.com/2016/04/27/structured-ingredients-data-tagging/}},
16
+ year = {},
17
+ note = {[Accessed 03-10-2023]},
18
+ }
19
+ """
20
+
21
+
22
+ _DESCRIPTION = """\
23
+ New York Times Ingredient Phrase Tagger Dataset
24
+ We use a conditional random field model (CRF) to extract tags from labelled training data, which was tagged by human news assistants.
25
+ e wrote about our approach on the [New York Times Open blog](http://open.blogs.nytimes.com/2015/04/09/extracting-structured-data-from-recipes-using-conditional-random-fields/).
26
+ This repo contains scripts to extract the Quantity, Unit, Name, and Comments from unstructured ingredient phrases.
27
+ We use it on Cooking to format incoming recipes. Given the following input:
28
+
29
+ ```
30
+ 1 pound carrots, young ones if possible
31
+ Kosher salt, to taste
32
+ 2 tablespoons sherry vinegar
33
+ 2 tablespoons honey
34
+ 2 tablespoons extra-virgin olive oil
35
+ 1 medium-size shallot, peeled and finely diced
36
+ 1/2 teaspoon fresh thyme leaves, finely chopped
37
+ Black pepper, to taste
38
+ ```
39
+ """
40
+
41
+ _URL = "https://github.com/nytimes/ingredient-phrase-tagger"
42
+
43
+ import json
44
+
45
+ class NYTIngedientsConfig(datasets.BuilderConfig):
46
+ """The NYTIngedients Dataset."""
47
+
48
+ def __init__(self, **kwargs):
49
+ """BuilderConfig for NYTIngedients.
50
+ Args:
51
+ **kwargs: keyword arguments forwarded to super.
52
+ """
53
+ super(NYTIngedientsConfig, self).__init__(**kwargs)
54
+
55
+
56
+ class NYTIngedients(datasets.GeneratorBasedBuilder):
57
+ """The WNUT 17 Emerging Entities Dataset."""
58
+
59
+ BUILDER_CONFIGS = [
60
+ NYTIngedientsConfig(
61
+ name="nyt-ingredients", version=datasets.Version("1.0.0"), description="The NYTIngedients Dataset"
62
+ ),
63
+ ]
64
+
65
+ def _info(self):
66
+ return datasets.DatasetInfo(
67
+ description=_DESCRIPTION,
68
+ features=datasets.Features(
69
+ {
70
+ "input": datasets.Value("string"),
71
+ "display_input": datasets.Value("string"),
72
+ "tokens": datasets.Sequence(datasets.Value("string")),
73
+ "index": datasets.Sequence(datasets.Value("string")),
74
+ "lengthGroup": datasets.Sequence(datasets.Value("string")),
75
+ "isCapitalized": datasets.Sequence(datasets.Value("string")),
76
+ "insideParenthesis": datasets.Sequence(datasets.Value("string")),
77
+ "label": datasets.Sequence(
78
+ datasets.features.ClassLabel(
79
+ names=[
80
+ 'O',
81
+ 'B-COMMENT',
82
+ 'I-COMMENT',
83
+ 'B-NAME',
84
+ 'I-NAME',
85
+ 'B-RANGE_END',
86
+ 'I-RANGE_END',
87
+ 'B-QTY',
88
+ 'I-QTY',
89
+ 'B-UNIT',
90
+ 'I-UNIT',
91
+ ]
92
+ )
93
+ ),
94
+ }
95
+ ),
96
+ supervised_keys=None,
97
+ homepage="https://github.com/nytimes/ingredient-phrase-tagger",
98
+ citation=_CITATION,
99
+ )
100
+
101
+ def _split_generators(self, dl_manager):
102
+ """Returns SplitGenerators."""
103
+ return [
104
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": "nyt-ingredients.crf.jsonl"}),
105
+ ]
106
+
107
+ def _generate_examples(self, filepath):
108
+ logger.info("⏳ Generating examples from = %s", filepath)
109
+ with open(filepath, encoding="utf-8") as fp:
110
+ for i, line in enumerate(fp):
111
+ yield i, json.loads(line)