Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some mkdirs exception #20

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions BERT_NER.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def convert_single_example(ex_index, example, label_list, max_seq_length, tokeni
label_map = {}
for (i, label) in enumerate(label_list,1):
label_map[label] = i
with open('./output/label2id.pkl','wb') as w:
with open('%slabel2id.pkl' % FLAGS.output_dir,'wb') as w:
pickle.dump(label_map,w)
textlist = example.text.split(' ')
labellist = example.label.split(' ')
Expand Down Expand Up @@ -475,6 +475,8 @@ def main(_):
"was only trained up to sequence length %d" %
(FLAGS.max_seq_length, bert_config.max_position_embeddings))

tf.gfile.MakeDirs(FLAGS.output_dir)

task_name = FLAGS.task_name.lower()
if task_name not in processors:
raise ValueError("Task not found: %s" % (task_name))
Expand Down Expand Up @@ -570,7 +572,8 @@ def main(_):
writer.write("%s = %s\n" % (key, str(result[key])))
if FLAGS.do_predict:
token_path = os.path.join(FLAGS.output_dir, "token_test.txt")
with open('./output/label2id.pkl','rb') as rf:
# We should use the folder assigned by user
with open('%slabel2id.pkl' % FLAGS.output_dir,'rb') as rf:
label2id = pickle.load(rf)
id2label = {value:key for key,value in label2id.items()}
if os.path.exists(token_path):
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The following evaluation results differ from the evaluation results specified by
![](/picture2.png)


#### 注:For the parameters of the above model, I have not made any modifications. All parameters are based on the BERT default parameters. The better parameters for this problem can be adjusted by yourselves.
#### Note: For the parameters of the above model, I have not made any modifications. All parameters are based on the BERT default parameters. The better parameters for this problem can be adjusted by yourselves.

The f_score evaluation codes come from:https://github.com/guillaumegenthial/tf_metrics/blob/master/tf_metrics/__init__.py

Expand Down
18 changes: 18 additions & 0 deletions run_ner.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@echo off
SET BERT_BASE_DIR=uncased_L-12_H-768_A-12
SET DATA_DIR=NERdata/
SET TASK=ner
py -3.6 BERT_NER.py ^
--task_name=%TASK% ^
--do_train=true ^
--do_eval=true ^
--do_predict=true ^
--data_dir=%DATA_DIR% ^
--vocab_file=%BERT_BASE_DIR%/vocab.txt ^
--bert_config_file=%BERT_BASE_DIR%/bert_config.json ^
--init_checkpoint=%BERT_BASE_DIR%/bert_model.ckpt ^
--max_seq_length=64 ^
--train_batch_size=32 ^
--learning_rate=2e-3 ^
--num_train_epochs=3.0 ^
--output_dir=output/%TASK%/