Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -73,7 +73,6 @@ parser.add_argument("--model_dir", default="/home/user/app/Customized_IDSF/Joint
|
|
73 |
parser.add_argument("--batch_size", default=32, type=int, help="Batch size for prediction")
|
74 |
parser.add_argument("--no_cuda", action="store_true", help="Avoid using CUDA when available")
|
75 |
|
76 |
-
globals()['var'] = "an object"
|
77 |
pred_config = parser.parse_args()
|
78 |
|
79 |
# load model and args
|
@@ -124,17 +123,22 @@ def ner(text):
|
|
124 |
|
125 |
slot_tokens = []
|
126 |
|
127 |
-
words[0].
|
128 |
for word, pred in zip(words, slot_preds):
|
129 |
word = word.replace("_", " ")
|
130 |
if pred == 'O':
|
131 |
slot_tokens.extend([(word, None), (" ", None)])
|
132 |
-
|
|
|
133 |
added_tokens = list(slot_tokens[-2])
|
134 |
added_tokens[0] += f' {word}'
|
135 |
slot_tokens[-2] = tuple(added_tokens)
|
136 |
-
|
|
|
137 |
slot_tokens.extend([(word, pred[2:]), (" ", None)])
|
|
|
|
|
|
|
138 |
|
139 |
intent_label = intent_label_lst[intent_pred]
|
140 |
|
|
|
73 |
parser.add_argument("--batch_size", default=32, type=int, help="Batch size for prediction")
|
74 |
parser.add_argument("--no_cuda", action="store_true", help="Avoid using CUDA when available")
|
75 |
|
|
|
76 |
pred_config = parser.parse_args()
|
77 |
|
78 |
# load model and args
|
|
|
123 |
|
124 |
slot_tokens = []
|
125 |
|
126 |
+
words[0] = words[0].upper() + words[1:]
|
127 |
for word, pred in zip(words, slot_preds):
|
128 |
word = word.replace("_", " ")
|
129 |
if pred == 'O':
|
130 |
slot_tokens.extend([(word, None), (" ", None)])
|
131 |
+
|
132 |
+
elif pred[0] == 'I': # token with label's prefix' "I-XXX": will be combined their corresponded "B-XXX"
|
133 |
added_tokens = list(slot_tokens[-2])
|
134 |
added_tokens[0] += f' {word}'
|
135 |
slot_tokens[-2] = tuple(added_tokens)
|
136 |
+
|
137 |
+
elif pred[0] == 'B': # token with label's prefix "B-XXX" : remove "B-"
|
138 |
slot_tokens.extend([(word, pred[2:]), (" ", None)])
|
139 |
+
|
140 |
+
else: # PAD or UNK tags
|
141 |
+
slot_tokens.extend([(word, pred), (" ", None)])
|
142 |
|
143 |
intent_label = intent_label_lst[intent_pred]
|
144 |
|