Upload folder using huggingface_hub
Browse files- fixtures/review.json +54 -24
- model.py +6 -11
fixtures/review.json
CHANGED
|
@@ -1,46 +1,76 @@
|
|
| 1 |
{
|
| 2 |
"spans": [
|
| 3 |
{
|
| 4 |
-
"start":
|
| 5 |
-
"end":
|
| 6 |
-
"text": "
|
| 7 |
-
"label": "
|
| 8 |
-
"score": 0.
|
| 9 |
"attributes": {
|
| 10 |
"sentiment": [
|
| 11 |
{
|
| 12 |
-
"label": "
|
| 13 |
-
"score": 0.
|
| 14 |
}
|
| 15 |
]
|
| 16 |
}
|
| 17 |
},
|
| 18 |
{
|
| 19 |
-
"start":
|
| 20 |
-
"end":
|
| 21 |
-
"text": "
|
| 22 |
-
"label": "
|
| 23 |
-
"score": 0.
|
| 24 |
"attributes": {
|
| 25 |
"sentiment": [
|
| 26 |
{
|
| 27 |
-
"label": "
|
| 28 |
-
"score": 0.
|
| 29 |
}
|
| 30 |
]
|
| 31 |
}
|
| 32 |
},
|
| 33 |
{
|
| 34 |
-
"start":
|
| 35 |
-
"end":
|
| 36 |
-
"text": "
|
| 37 |
-
"label": "
|
| 38 |
-
"score": 0.
|
| 39 |
"attributes": {
|
| 40 |
"sentiment": [
|
| 41 |
{
|
| 42 |
-
"label": "
|
| 43 |
-
"score": 0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
}
|
| 45 |
]
|
| 46 |
}
|
|
@@ -49,13 +79,13 @@
|
|
| 49 |
"start": 510,
|
| 50 |
"end": 525,
|
| 51 |
"text": "docking station",
|
| 52 |
-
"label": "
|
| 53 |
-
"score": 0.
|
| 54 |
"attributes": {
|
| 55 |
"sentiment": [
|
| 56 |
{
|
| 57 |
"label": "negative",
|
| 58 |
-
"score": 0.
|
| 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({"
|
| 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=["
|
| 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": {"
|
|
|
|
| 68 |
)},
|
| 69 |
],
|
| 70 |
}
|
|
@@ -84,12 +81,10 @@ EXAMPLE_SCHEMAS = {
|
|
| 84 |
},
|
| 85 |
"review": {
|
| 86 |
"entities": {
|
| 87 |
-
"
|
| 88 |
-
"person": "A person by name or role",
|
| 89 |
},
|
| 90 |
"attributes": {
|
| 91 |
-
"sentiment": (["positive", "neutral", "negative"], ["
|
| 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 |
}
|