readme: ## Conll2012 中文分词和词性标注
  
  LSTM chinese position of sentence tagging
  采用 chinese-bert-wwm-ext 的分词, 
  在 conll-2012, chinese, v4 数据集上训练. 
  在第 54 个 epoch 时达到最高分数,   
  training_accuracy=0.8970,  
  validation_accuracy=0.8687.  
  
  第 0 个 epoch 时, training_accuracy=0.8676, validation_accuracy=0.8483.  
  之后的训练, 每个 epoch 提升非常小.   
  设置的 patience=5, 但是我看 AllenNLP 官方示例中的 patience=25, 因此, 如果设置 patience=25, 准确率还可以再提高.   
  https://demo.allennlp.org/named-entity-recognition/named-entity-recognition  
  
  
  
  此模型可能的用途.  
  (1) 迁移学习, 做完分词和词性标注之后, 可用于实体识别, 句子关键词识别的迁移学习. 
  
  
  依赖  
  模型训练和预测依赖于 AllenNLP 框架.  
  ```text
  pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple allennlp==2.4.0
  pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple allennlp-models==2.4.0
  ```
  
  
  ### 模型训练
  ```python
  #!/usr/bin/python3
  # -*- coding: utf-8 -*-
  import os
  import sys
  
  from allennlp.commands.train import train_model_from_file
  from allennlp_models.tagging.models.crf_tagger import CrfTagger
  
  from project_settings import project_path
  
  model_path = os.path.join(project_path, 'model/pos_tagging/config.json')
  sys.path.append(os.path.dirname(model_path))
  
  from smart.allennlp_models.tagging.dataset_readers.bio_tagging_json_reader import BioTaggingJsonReader
  from smart.allennlp.training.optimizers import BertAdamOptimizer
  
  
  train_model_from_file(
      parameter_filename=model_path,
      serialization_dir="serialization_dir",
  )
  
  ```
  
  
  ### 模型预测
  
  ```python
  #!/usr/bin/python3
  # -*- coding: utf-8 -*-
  import os
  import sys
  import time
  
  from allennlp.commands.train import train_model_from_file
  from allennlp.data.tokenizers.pretrained_transformer_tokenizer import PretrainedTransformerTokenizer
  from allennlp.models.archival import archive_model, load_archive
  from allennlp.predictors.predictor import Predictor
  from allennlp_models.tagging.models.crf_tagger import CrfTagger
  
  from project_settings import project_path
  
  model_path = os.path.join(project_path, 'model/pos_tagging/')
  sys.path.append(os.path.dirname(model_path))
  
  from smart.allennlp_models.tagging.dataset_readers.bio_tagging_json_reader import BioTaggingJsonReader
  from smart.allennlp.training.optimizers import BertAdamOptimizer
  from smart.allennlp_models.tagging.predictors.sentence_tagger_with_tokenizer import SentenceTaggerWithTokenizerPredictor
  
  
  model_name = r'D:\Users\tianx\PycharmProjects\PyTorch\pretrained\chinese-bert-wwm-ext'
  
  
  tokenizer = PretrainedTransformerTokenizer(
      model_name=model_name
  )
  
  archive = load_archive(model_path)
  predictor: SentenceTaggerWithTokenizerPredictor = Predictor.from_archive(archive, predictor_name='sentence_tagger_with_tokenizer', extra_args={'tokenizer': tokenizer})
  
  text = '梵蒂冈本应认真的、负责任的检讨历史上有负于中国人民的错误行为，向中国人民道歉。'
  
  json_dict = {'sentence': text}
  
  begin = time.time()
  outputs = predictor.predict_json(json_dict)
  cost = time.time() - begin
  print(cost)
  tags = outputs['tags']
  print(tags)
  
  predicted_spans = predictor.bio_decode(outputs)
  print(predicted_spans)
  
  
  ```
  
  以上代码输出结果为: 
  ```text
  0.013086795806884766
  ['O', 'B-NR', 'I-NR', 'I-NR', 'B-AD', 'B-VV', 'B-VV', 'I-VV', 'B-DEC', 'B-PU', 'B-VV', 'I-VV', 'I-VV', 'B-DEC', 'B-NN', 'I-NN', 'B-NN', 'I-NN', 'B-LC', 'B-VE', 'B-VV', 'I-VV', 'B-NR', 'I-NR', 'B-NN', 'I-NN', 'B-DEG', 'B-NN', 'I-NN', 'B-NN', 'I-NN', 'B-PU', 'B-P', 'B-NR', 'I-NR', 'B-NN', 'I-NN', 'B-VV', 'I-VV', 'B-PU', 'O']
  [('梵蒂冈', 'NR'), ('本', 'AD'), ('应', 'VV'), ('认真', 'VV'), ('的', 'DEC'), ('、', 'PU'), ('负责任', 'VV'), ('的', 'DEC'), ('检讨', 'NN'), ('历史', 'NN'), ('上', 'LC'), ('有', 'VE'), ('负于', 'VV'), ('中国', 'NR'), ('人民', 'NN'), ('的', 'DEG'), ('错误', 'NN'), ('行为', 'NN'), ('，', 'PU'), ('向', 'P'), ('中国', 'NR'), ('人民', 'NN'), ('道歉', 'VV'), ('。', 'PU')]
  
  ```
  
  
  
  
  
  
  
  
  