thealper2 commited on
Commit
9148c8c
·
verified ·
1 Parent(s): 2355233

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -94,7 +94,6 @@ class AspectSentimentPipeline(Pipeline):
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":
@@ -102,17 +101,19 @@ class AspectSentimentPipeline(Pipeline):
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))
 
94
 
95
  aspects = []
96
  current_aspect = []
 
97
 
98
  for i, (token, prediction) in enumerate(zip(aligned_tokens, aligned_predictions)):
99
  if prediction == "B-A":
 
101
  aspects.append(" ".join(current_aspect))
102
  current_aspect = []
103
  current_aspect.append(token)
 
104
  elif prediction == "I-A":
105
+ if current_aspect:
106
+ current_aspect.append(token)
107
  else:
108
  current_aspect.append(token)
109
+ elif prediction == "O" or i == len(aligned_tokens) - 1:
110
+ if current_aspect:
111
+ aspects.append(" ".join(current_aspect))
112
+ current_aspect = []
113
  else:
114
  if current_aspect:
115
  aspects.append(" ".join(current_aspect))
116
  current_aspect = []
 
117
 
118
  if current_aspect:
119
  aspects.append(" ".join(current_aspect))