m-newhauser commited on
Commit
f9b1c76
·
verified ·
1 Parent(s): 25e6476

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. fixtures/review.json +54 -24
  2. model.py +6 -11
fixtures/review.json CHANGED
@@ -1,46 +1,76 @@
1
  {
2
  "spans": [
3
  {
4
- "start": 25,
5
- "end": 41,
6
- "text": "Nimbus 14 laptop",
7
- "label": "product",
8
- "score": 0.9600220918655396,
9
  "attributes": {
10
  "sentiment": [
11
  {
12
- "label": "negative",
13
- "score": 0.975648820400238
14
  }
15
  ]
16
  }
17
  },
18
  {
19
- "start": 224,
20
- "end": 233,
21
- "text": "Nimbus 14",
22
- "label": "product",
23
- "score": 0.906394898891449,
24
  "attributes": {
25
  "sentiment": [
26
  {
27
- "label": "negative",
28
- "score": 0.9998642206192017
29
  }
30
  ]
31
  }
32
  },
33
  {
34
- "start": 408,
35
- "end": 419,
36
- "text": "USB-C ports",
37
- "label": "product",
38
- "score": 0.5385769605636597,
39
  "attributes": {
40
  "sentiment": [
41
  {
42
- "label": "negative",
43
- "score": 0.8142373561859131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
45
  ]
46
  }
@@ -49,13 +79,13 @@
49
  "start": 510,
50
  "end": 525,
51
  "text": "docking station",
52
- "label": "product",
53
- "score": 0.8726967573165894,
54
  "attributes": {
55
  "sentiment": [
56
  {
57
  "label": "negative",
58
- "score": 0.9747726917266846
59
  }
60
  ]
61
  }
 
1
  {
2
  "spans": [
3
  {
4
+ "start": 155,
5
+ "end": 161,
6
+ "text": "screen",
7
+ "label": "feature_mention",
8
+ "score": 0.9743606448173523,
9
  "attributes": {
10
  "sentiment": [
11
  {
12
+ "label": "positive",
13
+ "score": 0.9995241165161133
14
  }
15
  ]
16
  }
17
  },
18
  {
19
+ "start": 182,
20
+ "end": 190,
21
+ "text": "keyboard",
22
+ "label": "feature_mention",
23
+ "score": 0.9798126220703125,
24
  "attributes": {
25
  "sentiment": [
26
  {
27
+ "label": "positive",
28
+ "score": 0.9994789958000183
29
  }
30
  ]
31
  }
32
  },
33
  {
34
+ "start": 341,
35
+ "end": 349,
36
+ "text": "trackpad",
37
+ "label": "feature_mention",
38
+ "score": 0.9792487621307373,
39
  "attributes": {
40
  "sentiment": [
41
  {
42
+ "label": "positive",
43
+ "score": 0.9997420907020569
44
+ }
45
+ ]
46
+ }
47
+ },
48
+ {
49
+ "start": 358,
50
+ "end": 363,
51
+ "text": "hinge",
52
+ "label": "feature_mention",
53
+ "score": 0.9491639733314514,
54
+ "attributes": {
55
+ "sentiment": [
56
+ {
57
+ "label": "positive",
58
+ "score": 0.9993890523910522
59
+ }
60
+ ]
61
+ }
62
+ },
63
+ {
64
+ "start": 451,
65
+ "end": 458,
66
+ "text": "Support",
67
+ "label": "feature_mention",
68
+ "score": 0.9439302682876587,
69
+ "attributes": {
70
+ "sentiment": [
71
+ {
72
+ "label": "positive",
73
+ "score": 0.9954706430435181
74
  }
75
  ]
76
  }
 
79
  "start": 510,
80
  "end": 525,
81
  "text": "docking station",
82
+ "label": "feature_mention",
83
+ "score": 0.5191700458526611,
84
  "attributes": {
85
  "sentiment": [
86
  {
87
  "label": "negative",
88
+ "score": 0.9989418387413025
89
  }
90
  ]
91
  }
model.py CHANGED
@@ -53,18 +53,15 @@ DEMO = {
53
  'review = open("product_review.txt").read()\n'
54
  '\n'
55
  'schema = (extractor.create_schema()\n'
56
- ' .entities({"product": "A product or product component mentioned in the review",\n'
57
- ' "person": "A person by name or role"})\n'
58
  ' .entity_attributes({\n'
59
  ' "sentiment": AttributeGroup(\n'
60
  ' labels=["positive", "neutral", "negative"],\n'
61
- ' applies_to=["product"]),\n'
62
- ' "role": AttributeGroup(\n'
63
- ' labels=["executive", "employee", "customer", "analyst"],\n'
64
- ' applies_to=["person"])}))\n'
65
  '\n'
66
  'result = extractor.extract(review, schema, include_spans=True, include_confidence=True)\n'
67
- '# -> {"entities": {"product": [{"text": "docking station", "sentiment": {"label": "negative"}, ...}], ...}}'
 
68
  )},
69
  ],
70
  }
@@ -84,12 +81,10 @@ EXAMPLE_SCHEMAS = {
84
  },
85
  "review": {
86
  "entities": {
87
- "product": "A product or product component mentioned in the review",
88
- "person": "A person by name or role",
89
  },
90
  "attributes": {
91
- "sentiment": (["positive", "neutral", "negative"], ["product"]),
92
- "role": (["executive", "employee", "customer", "analyst"], ["person"]),
93
  },
94
  },
95
  }
 
53
  'review = open("product_review.txt").read()\n'
54
  '\n'
55
  'schema = (extractor.create_schema()\n'
56
+ ' .entities({"feature_mention": "A feature, component, or aspect of a product mentioned in the review"})\n'
 
57
  ' .entity_attributes({\n'
58
  ' "sentiment": AttributeGroup(\n'
59
  ' labels=["positive", "neutral", "negative"],\n'
60
+ ' applies_to=["feature_mention"])}))\n'
 
 
 
61
  '\n'
62
  'result = extractor.extract(review, schema, include_spans=True, include_confidence=True)\n'
63
+ '# -> {"entities": {"feature_mention": [{"text": "keyboard", "sentiment": {"label": "positive"}, ...},\n'
64
+ '# {"text": "docking station", "sentiment": {"label": "negative"}, ...}], ...}}'
65
  )},
66
  ],
67
  }
 
81
  },
82
  "review": {
83
  "entities": {
84
+ "feature_mention": "A feature, component, or aspect of a product mentioned in the review",
 
85
  },
86
  "attributes": {
87
+ "sentiment": (["positive", "neutral", "negative"], ["feature_mention"]),
 
88
  },
89
  },
90
  }