Some Entity Recognition models for 2019 Datagrand Cup: Text Information Extraction Challenge.
- python 3.6
- keras 2.2.4 (tensorflow backend)
- keras-contrib 2.0.8 for CRF inference.
- gensim for training word2vec.
- bilm-tf for EMLo.
- Static Word Embedding: word2vec, GloVE
- Contextualized Word Representation: ELMo (
_elmo), refer to Sec.
- BiLSTM
- DGCNN
- sequence labeling
- CRF
- softmax
- predict start/end index of entities (
_pointer)
According to the three components described above, there actually exists 12 models in all. However, this repo only implemented the following 6 models:
- Static Word Embedding × (BiLSTM, DGCNN) × (CRF, softmax):
main.py - (Static Word Embedding, ELMo) × BiLSTM × pointer:
bilstm_pointer.pyandbilstm_pointer_elmo.py
Other models can be implemented by adding/modifying few codes.
-
- download official competition data to
datafolder
- download official competition data to
-
- get sequence tagging train/dev/test data:
bin/trans_data.py
- get sequence tagging train/dev/test data:
-
- train word2vec:
bin/train_w2v.py
- train word2vec:
-
- prepare
vocab,tag
vocab: word vocabulary, one word per line, withword word_countformattag:BIOESner tag list, one tag per line (Oin first line)
- prepare
-
- modify
config.py
- modify
-
- run
python main.py [bilstm/dgcnn] [softmax/crf]orpython bilstm_pointer(remember to modifyconfig.model_namebefore a new run, or the old model will be overrided)
- run
-
- follow the instruction described here to get contextualized sentence representation for
train_full/dev/testdata from pre-trained ELMo weights
- follow the instruction described here to get contextualized sentence representation for
-
- run
python bilstm_pointer_elmo.py
- run
- Just follow the official instruction described here.
- Some notes:
- to train a token-level language model, modify
bin/train_elmo.py:
fromvocab = load_vocab(args.vocab_file, 50)
tovocab = load_vocab(args.vocab_file, None) - modify
n_train_tokens - remove
char_cnninoptions - modify
lstm.dim/lstm.projection_dimas you wish. n_gpus=2,n_train_tokens=94114921,lstm['dim']=2048,projection_dim=256,n_epochs=10. It took about 17 hours long on 2 GTX 1080 Ti.
- to train a token-level language model, modify
- After finishing the last step of the instruction, you can refer to the script dump_token_level_bilm_embeddings.py to dump the dynamic sentence representations of your own dataset.
- Blog:《基于CNN的阅读理解式问答模型:DGCNN 》
- Blog:《基于DGCNN和概率图的轻量级信息抽取模型 》
- Some codes
- Sequence Evaluation tools: seqeval
- Neural Sequence Labeling Toolkit: NCRF++
- Contextualized Word Representation: ELMo