---
title: nlp_raner_named-entity-recognition_chinese-base-bank
canonical_url: "https://www.modelscope.cn/models/damo/nlp_raner_named-entity-recognition_chinese-base-bank"
md_url: "https://www.modelscope.cn/models/damo/nlp_raner_named-entity-recognition_chinese-base-bank.md"
repository: damo/nlp_raner_named-entity-recognition_chinese-base-bank
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:
  - sbert-base
library_name:
  - pytorch
frameworks:
  - PyTorch
language:
  - cn
domain:
  - nlp
downloads: 41509
stars: 3
tags:
  - Alibaba
  - NER
---

# nlp_raner_named-entity-recognition_chinese-base-bank

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

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

- **Repository**: damo/nlp_raner_named-entity-recognition_chinese-base-bank
- **License**: Apache License 2.0
- **Tasks**: named-entity-recognition
- **Tags**: Alibaba, NER
- **Downloads**: 41509
- **Stars**: 3
- **Last updated**: 2023-02-20

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

---

# RANER介绍

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

![模型结构](description/model_image_high_res.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-bank')
result = ner_pipeline('请问中信银行信用卡业务怎么办理')

print(result)
```


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

1. 安装AdaSeq

```shell
pip install adaseq
```

2. 模型微调

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

该配置中的数据集为示例数据集toy_msra，如需使用自定义数据或调整参数，可参考《[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: toy_msra
  seed: 42

task: named-entity-recognition

dataset:
  name: damo/toy_msra

preprocessor:
  type: sequence-labeling-preprocessor
  max_length: 100

data_collator: SequenceLabelingDataCollatorWithPadding

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

train:
  max_epochs: 5
  dataloader:
    batch_size_per_gpu: 8
  optimizer:
    type: AdamW
    lr: 5.0e-5
    param_groups:
      - regex: crf
        lr: 5.0e-1
    options:
      cumulative_iters: 4

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

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

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

3. 模型推理

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

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

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

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

## 训练数据介绍
- [bank](https://github.com/liucongg/NLPDataSet)银行借贷业务领域中文命名实体识别公开数据集，包括4种实体类型，共1500个句子。

| 实体类型 | 英文名 |
|----------|--------|
| 银行名 | BANK |
| 客户提到的形容词 | COMMENTS_ADJ |
| 客户提到的名词 | COMMENTS_N |
| 银行金融产品名 | PRODUCT |

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

| Dataset | Precision | Recall | F1 |
| --- | --- | --- | --- |
| bank | 84.13 | 87.75 | 85.9 |

各个类型的性能如下: 
| Dataset | Precision | Recall | F1 |
| --- | --- | --- | --- |
| BANK | 94.28 | 96.92 | 95.58 |
| COMMENTS_ADJ | 71.69 | 78.28 | 74.84 |
| COMMENTS_N | 94.98 | 92.35 | 93.65 |
| PRODUCT | 85.03 | 91.91 | 88.34 |

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

```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",
}
```
