File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 41
41
UNK_IDX = 0
42
42
43
43
44
+ def load_label_dict (filename ):
45
+ d = dict ()
46
+ tag_dict = set ()
47
+ with open (filename , 'r' ) as f :
48
+ for i , line in enumerate (f ):
49
+ line = line .strip ()
50
+ if line .startswith ("B-" ):
51
+ tag_dict .add (line [2 :])
52
+ elif line .startswith ("I-" ):
53
+ tag_dict .add (line [2 :])
54
+ index = 0
55
+ for tag in tag_dict :
56
+ d ["B-" + tag ] = index
57
+ index += 1
58
+ d ["I-" + tag ] = index
59
+ index += 1
60
+ d ["O" ] = index
61
+ return d
62
+
63
+
44
64
def load_dict (filename ):
45
65
d = dict ()
46
66
with open (filename , 'r' ) as f :
@@ -188,7 +208,7 @@ def get_dict():
188
208
verb_dict = load_dict (
189
209
paddle .v2 .dataset .common .download (VERBDICT_URL , 'conll05st' ,
190
210
VERBDICT_MD5 ))
191
- label_dict = load_dict (
211
+ label_dict = load_label_dict (
192
212
paddle .v2 .dataset .common .download (TRGDICT_URL , 'conll05st' ,
193
213
TRGDICT_MD5 ))
194
214
return word_dict , verb_dict , label_dict
You can’t perform that action at this time.
0 commit comments