---
title: nlp_raner_named-entity-recognition_chinese-base-resume
canonical_url: "https://www.modelscope.cn/models/damo/nlp_raner_named-entity-recognition_chinese-base-resume"
md_url: "https://www.modelscope.cn/models/damo/nlp_raner_named-entity-recognition_chinese-base-resume.md"
repository: damo/nlp_raner_named-entity-recognition_chinese-base-resume
chinese_name: "RaNER命名实体识别-中文-简历领域-base"
last_updated: 2023-02-20
license: "Apache License 2.0"
pipeline_tag: named-entity-recognition
tasks:
  - named-entity-recognition
model_type:
  - structbert
library_name:
  - pytorch
frameworks:
  - PyTorch
language:
  - cn
domain:
  - nlp
downloads: 26164
stars: 20
tags:
  - Alibaba
  - NER
  - "ACL 2021"
  - "SemEval 2022"
  - "信息抽取"
---

# nlp_raner_named-entity-recognition_chinese-base-resume

> nlp_raner_named-entity-recognition_chinese-base-resume - damo 在 ModelScope 开源的模型。该模型是基于检索增强(RaNer)方法在中文Resume数据集训练的模型。本方法采用Transformer-CRF模型，使用StructBERT作为预训练模型底座，结合使用外部工具召回的相关句子作为额外上下文，使用Multi-view Training方式进行训练。

damo/nlp_raner_named-entity-recognition_chinese-base-resume 是 ModelScope 魔搭社区上的named-entity-recognition模型，采用 Apache License 2.0 许可。

- **Repository**: damo/nlp_raner_named-entity-recognition_chinese-base-resume
- **License**: Apache License 2.0
- **Tasks**: named-entity-recognition
- **Tags**: Alibaba, NER, ACL 2021, SemEval 2022, 信息抽取
- **Downloads**: 26164
- **Stars**: 20
- **Last updated**: 2023-02-20

Source: https://www.modelscope.cn/models/damo/nlp_raner_named-entity-recognition_chinese-base-resume

---

# RANER介绍

## 模型描述
本方法采用Transformer-CRF模型，使用StructBERT作为预训练模型底座，结合使用外部工具召回的相关句子作为额外上下文，使用Multi-view Training方式进行训练。
模型结构如下图所示：

![模型结构](description/model_image.jpg)

可参考论文：[Improving Named Entity Recognition by External Context Retrieving and Cooperative Learning](https://aclanthology.org/2021.acl-long.142/)


## 期望模型使用方式以及适用范围
本模型主要用于给输入中文句子产出命名实体识别结果。用户可以自行尝试输入中文句子。具体调用方式请参考代码示例。

### 如何使用
在安装ModelScope完成之后即可使用named-entity-recognition(命名实体识别)的能力, 默认单句长度不超过512。

#### 代码范例
```python
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

ner_pipeline = pipeline(Tasks.named_entity_recognition, 'damo/nlp_raner_named-entity-recognition_chinese-base-resume')
result = ner_pipeline('常建良，男，')

print(result)
# {'output': [{'type': 'NAME', 'start': 0, 'end': 3, 'span': '常建良'}]}
```

#### 基于AdaSeq进行微调和推理（仅需一行命令）
**AdaSeq**是一个基于ModelScope的一站式NLP序列理解开源工具箱，支持高效训练自定义模型，旨在提高开发者和研究者们的开发和创新效率，助力模型快速定制和前沿论文工作落地。

1. 安装AdaSeq

```shell
pip install adaseq
```

2. 模型微调

准备训练配置，将下面的代码保存为train.yaml。

该配置中的数据集为示例数据集resume，如需使用自定义数据或调整参数，可参考《[AdaSeq模型训练最佳实践](https://github.com/modelscope/AdaSeq/blob/master/docs/tutorials/training_a_model_zh.md)》，准备数据或修改配置文件。AdaSeq中也提供了大量的[模型、论文、比赛复现示例]([https://github.com/modelscope/AdaSeq/tree/master/examples](https://github.com/modelscope/AdaSeq/tree/master/examples))，欢迎大家使用。
```yaml
experiment:
  exp_dir: experiments/
  exp_name: resume
  seed: 42

task: named-entity-recognition

dataset:
  name: damo/resume_ner

preprocessor:
  type: sequence-labeling-preprocessor
  max_length: 150

data_collator: SequenceLabelingDataCollatorWithPadding

model:
  type: sequence-labeling-model
  embedder:
    model_name_or_path: damo/nlp_raner_named-entity-recognition_chinese-base-resume
  dropout: 0.1
  use_crf: true

train:
  max_epochs: 20
  dataloader:
    batch_size_per_gpu: 32
  optimizer:
    type: AdamW
    lr: 5.0e-5
    param_groups:
      - regex: crf
        lr: 5.0e-1
  lr_scheduler:
    type: LinearLR
    start_factor: 1.0
    end_factor: 0.0
    total_iters: 20

evaluation:
  dataloader:
    batch_size_per_gpu: 128
  metrics:
    - type: ner-metric
```

运行命令开始训练。训练需要12G显存，可以根据实际GPU情况调整batch_size等参数。

```shell
adaseq train -c train.yaml
```

3. 模型推理

模型会保存在 `./experiments/resume/${yymmddHHMMSS.ffffff}/output/`

可以将上文推理示例代码中的model_id替换为本地路径（绝对路径）进行推理

保存的模型也可上传到ModelScope进行使用


### 模型局限性以及可能的偏差
本模型基于Resume数据集(简历领域)上训练，在垂类领域中文文本上的NER效果会有降低，请用户自行评测后决定如何使用。


## 训练数据介绍
- [Resume](https://aclanthology.org/P18-1144/) 简历领域中文命名实体识别公开数据集，包括国籍、教育背景、籍贯、人名、组织名、专业、民族、职称，共4761个句子。

| 实体类型 | 英文名 |
|----------|--------|
| 国籍     | CONT    |
| 教育背景     | EDU    |
| 籍贯     | LOC    |
| 人名   | NAME    |
| 组织名   | ORG   |
| 专业   |  PRO  |
| 民族 | RACE   |
| 职称   | TITLE   |

## 数据评估及结果
模型在Resume测试数据评估结果:

| Dataset | Precision | Recall | F1 |
| --- | --- | --- | --- |
| Resume | 97.04 | 96.69 | 96.87 |

各个类型的性能如下: 
| Dataset | Precision | Recall | F1 |
| --- | --- | --- | --- |
| CONT | 100.00 | 100.00 | 100.00 |
| EDU | 99.07 | 94.64 | 96.80|
| LOC | 100.00 | 100.00 | 100.00|
| NAME | 100.00 | 99.11 | 99.55|
| ORG | 95.87 | 96.56 | 96.22|
| PRO | 91.67 | 100.00 | 95.65|
| RACE | 100.00 | 100.00 | 100.00 | 
| TITLE | 97.25 | 96.37 | 96.81 |

### 相关论文以及引用信息
如果你觉得这个该模型对有所帮助，请考虑引用下面的相关的论文：

```BibTeX
@inproceedings{wang-etal-2021-improving,
    title = "Improving Named Entity Recognition by External Context Retrieving and Cooperative Learning",
    author = "Wang, Xinyu  and
      Jiang, Yong  and
      Bach, Nguyen  and
      Wang, Tao  and
      Huang, Zhongqiang  and
      Huang, Fei  and
      Tu, Kewei",
    booktitle = "Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers)",
    month = aug,
    year = "2021",
    address = "Online",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2021.acl-long.142",
    pages = "1800--1812",
}

@inproceedings{wang-etal-2022-damo,
    title = "{DAMO}-{NLP} at {S}em{E}val-2022 Task 11: A Knowledge-based System for Multilingual Named Entity Recognition",
    author = "Wang, Xinyu  and
      Shen, Yongliang  and
      Cai, Jiong  and
      Wang, Tao  and
      Wang, Xiaobin  and
      Xie, Pengjun  and
      Huang, Fei  and
      Lu, Weiming  and
      Zhuang, Yueting  and
      Tu, Kewei  and
      Lu, Wei  and
      Jiang, Yong",
    booktitle = "Proceedings of the 16th International Workshop on Semantic Evaluation (SemEval-2022)",
    month = jul,
    year = "2022",
    address = "Seattle, United States",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2022.semeval-1.200",
    pages = "1457--1468",
}
```
