Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -94,24 +94,25 @@ class AspectSentimentPipeline(Pipeline):
|
|
| 94 |
|
| 95 |
aspects = []
|
| 96 |
current_aspect = []
|
| 97 |
-
|
| 98 |
-
special_characters = ["+", "'"]
|
| 99 |
|
| 100 |
-
for token, prediction in zip(aligned_tokens, aligned_predictions):
|
| 101 |
if prediction == "B-A":
|
| 102 |
if current_aspect:
|
| 103 |
aspects.append(" ".join(current_aspect))
|
| 104 |
current_aspect = []
|
| 105 |
current_aspect.append(token)
|
|
|
|
| 106 |
elif prediction == "I-A":
|
| 107 |
-
if
|
|
|
|
|
|
|
| 108 |
current_aspect.append(token)
|
| 109 |
-
elif token in special_characters and current_aspect:
|
| 110 |
-
current_aspect[-1] += token
|
| 111 |
else:
|
| 112 |
if current_aspect:
|
| 113 |
aspects.append(" ".join(current_aspect))
|
| 114 |
current_aspect = []
|
|
|
|
| 115 |
|
| 116 |
if current_aspect:
|
| 117 |
aspects.append(" ".join(current_aspect))
|
|
|
|
| 94 |
|
| 95 |
aspects = []
|
| 96 |
current_aspect = []
|
| 97 |
+
previous_b_a_index = None
|
|
|
|
| 98 |
|
| 99 |
+
for i, (token, prediction) in enumerate(zip(aligned_tokens, aligned_predictions)):
|
| 100 |
if prediction == "B-A":
|
| 101 |
if current_aspect:
|
| 102 |
aspects.append(" ".join(current_aspect))
|
| 103 |
current_aspect = []
|
| 104 |
current_aspect.append(token)
|
| 105 |
+
previous_b_a_index = i
|
| 106 |
elif prediction == "I-A":
|
| 107 |
+
if previous_b_a_index is not None:
|
| 108 |
+
aligned_tokens[previous_b_a_index] += " " + token
|
| 109 |
+
else:
|
| 110 |
current_aspect.append(token)
|
|
|
|
|
|
|
| 111 |
else:
|
| 112 |
if current_aspect:
|
| 113 |
aspects.append(" ".join(current_aspect))
|
| 114 |
current_aspect = []
|
| 115 |
+
previous_b_a_index = None
|
| 116 |
|
| 117 |
if current_aspect:
|
| 118 |
aspects.append(" ".join(current_aspect))
|