File size: 2,229 Bytes
8d6e00d
b5bab43
 
 
 
 
8d6e00d
 
 
b5bab43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1557cd4
 
 
b5bab43
 
1557cd4
b5bab43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
base_model: uer/roberta-base-finetuned-cluener2020-chinese
tags:
- token-classification
- ner
- chinese
library_name: transformers
---

# LoRA 微调中文NER模型

这是一个使用 LoRA (Low-Rank Adaptation) 技术微调的中文命名实体识别 (NER) 模型。

## 模型概述

-   **基础模型**: `uer/roberta-base-finetuned-cluener2020-chinese`
-   **任务**: 命名实体识别 (Token Classification)
-   **LoRA 配置**:
    -   `r`: 8
    -   `lora_alpha`: 16
    -   `lora_dropout`: 0.1
-   **支持的实体类型**:
    -   TIME: 时间
    -   LOCATION: 地点
    -   PERSON: 人名
    -   ORGANIZATION: 组织机构
    -   PRODUCT: 产品
    -   EVENT: 事件
    -   TOPIC: 主题
    -   CONCEPT: 概念
    -   SEARCH_INTENT: 搜索意图

## 使用方法

您可以使用 Hugging Face Transformers 库加载和使用此模型进行推理:

```python
from transformers import AutoModelForTokenClassification,AutoTokenizer,pipeline
model = AutoModelForTokenClassification.from_pretrained('lujin/search-ner-lora-model')
tokenizer = AutoTokenizer.from_pretrained('lujin/search-ner-lora-model')
ner_pipe = pipeline(
    "token-classification",
    model=model,
    tokenizer=tokenizer,
    aggregation_strategy="simple",
    device=0 if torch.cuda.is_available() else -1
)

# 示例文本
text = "对比 MacBook Pro 和 MacBook Air"
predictions = ner_pipe(text)
for entity in predictions:
    print(f"实体: {entity['word']}, 标签: {entity['entity_group']}, 置信度: {entity['score']:.4f}")

text = "明天在北京故宫博物院举行长城文化论坛"
predictions = ner_pipe(text)
for entity in predictions:
    print(f"实体: {entity['word']}, 标签: {entity['entity_group']}, 置信度: {entity['score']:.4f}")
```

## 训练详情

-   **数据集**: 使用私有数据集进行训练
-   **训练框架**: Hugging Face Transformers, PEFT (LoRA)
-   **训练参数**: 
    -   学习率: 0.0003
    -   批次大小: 16
    -   训练轮数: 10

## 评估结果 (在验证集上)

-   F1 Score: 1.0000
-   Precision: 1.0000
-   Recall: 1.0000

## 局限性

此模型在训练时使用的私有数据集上表现良好。在其他领域或特定语料上可能需要进一步微调。