Upload folder using huggingface_hub
Browse files- fixtures/review.json +45 -0
- model.py +3 -1
fixtures/review.json
CHANGED
|
@@ -30,6 +30,36 @@
|
|
| 30 |
]
|
| 31 |
}
|
| 32 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
{
|
| 34 |
"start": 341,
|
| 35 |
"end": 349,
|
|
@@ -60,6 +90,21 @@
|
|
| 60 |
]
|
| 61 |
}
|
| 62 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
{
|
| 64 |
"start": 451,
|
| 65 |
"end": 458,
|
|
|
|
| 30 |
]
|
| 31 |
}
|
| 32 |
},
|
| 33 |
+
{
|
| 34 |
+
"start": 204,
|
| 35 |
+
"end": 216,
|
| 36 |
+
"text": "Battery life",
|
| 37 |
+
"label": "feature_mention",
|
| 38 |
+
"score": 0.3691289722919464,
|
| 39 |
+
"attributes": {
|
| 40 |
+
"sentiment": [
|
| 41 |
+
{
|
| 42 |
+
"label": "negative",
|
| 43 |
+
"score": 0.999858021736145
|
| 44 |
+
}
|
| 45 |
+
]
|
| 46 |
+
}
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"start": 260,
|
| 50 |
+
"end": 269,
|
| 51 |
+
"text": "fan noise",
|
| 52 |
+
"label": "feature_mention",
|
| 53 |
+
"score": 0.24698400497436523,
|
| 54 |
+
"attributes": {
|
| 55 |
+
"sentiment": [
|
| 56 |
+
{
|
| 57 |
+
"label": "negative",
|
| 58 |
+
"score": 0.9998291730880737
|
| 59 |
+
}
|
| 60 |
+
]
|
| 61 |
+
}
|
| 62 |
+
},
|
| 63 |
{
|
| 64 |
"start": 341,
|
| 65 |
"end": 349,
|
|
|
|
| 90 |
]
|
| 91 |
}
|
| 92 |
},
|
| 93 |
+
{
|
| 94 |
+
"start": 408,
|
| 95 |
+
"end": 419,
|
| 96 |
+
"text": "USB-C ports",
|
| 97 |
+
"label": "feature_mention",
|
| 98 |
+
"score": 0.4605136513710022,
|
| 99 |
+
"attributes": {
|
| 100 |
+
"sentiment": [
|
| 101 |
+
{
|
| 102 |
+
"label": "negative",
|
| 103 |
+
"score": 0.997340977191925
|
| 104 |
+
}
|
| 105 |
+
]
|
| 106 |
+
}
|
| 107 |
+
},
|
| 108 |
{
|
| 109 |
"start": 451,
|
| 110 |
"end": 458,
|
model.py
CHANGED
|
@@ -80,6 +80,7 @@ EXAMPLE_SCHEMAS = {
|
|
| 80 |
},
|
| 81 |
},
|
| 82 |
"review": {
|
|
|
|
| 83 |
"entities": {
|
| 84 |
"feature_mention": "A feature, component, or aspect of a product mentioned in the review",
|
| 85 |
},
|
|
@@ -210,7 +211,8 @@ def _infer_real(text):
|
|
| 210 |
if attr_groups:
|
| 211 |
schema = schema.entity_attributes(attr_groups)
|
| 212 |
|
| 213 |
-
result = _model.extract(text, schema,
|
|
|
|
| 214 |
|
| 215 |
spans = []
|
| 216 |
for label, entries in result.get("entities", {}).items():
|
|
|
|
| 80 |
},
|
| 81 |
},
|
| 82 |
"review": {
|
| 83 |
+
"threshold": 0.15, # features in complaint clauses score below the 0.5 default
|
| 84 |
"entities": {
|
| 85 |
"feature_mention": "A feature, component, or aspect of a product mentioned in the review",
|
| 86 |
},
|
|
|
|
| 211 |
if attr_groups:
|
| 212 |
schema = schema.entity_attributes(attr_groups)
|
| 213 |
|
| 214 |
+
result = _model.extract(text, schema, threshold=cfg.get("threshold", 0.5),
|
| 215 |
+
include_spans=True, include_confidence=True)
|
| 216 |
|
| 217 |
spans = []
|
| 218 |
for label, entries in result.get("entities", {}).items():
|