lujin commited on
Commit
1557cd4
·
verified ·
1 Parent(s): b5bab43

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +4 -42
README.md CHANGED
@@ -35,50 +35,12 @@ library_name: transformers
35
  您可以使用 Hugging Face Transformers 库加载和使用此模型进行推理:
36
 
37
  ```python
38
- from transformers import pipeline, AutoTokenizer, AutoModelForTokenClassification
39
- from peft import PeftModel
40
- import torch
41
-
42
- # 定义标签列表(与训练时保持一致)
43
- LABEL_LIST = [
44
- 'O',
45
- 'B-TIME', 'I-TIME',
46
- 'B-LOCATION', 'I-LOCATION',
47
- 'B-PERSON', 'I-PERSON',
48
- 'B-ORGANIZATION', 'I-ORGANIZATION',
49
- 'B-PRODUCT', 'I-PRODUCT',
50
- 'B-EVENT', 'I-EVENT',
51
- 'B-TOPIC', 'I-TOPIC',
52
- 'B-CONCEPT', 'I-CONCEPT',
53
- 'B-SEARCH_INTENT', 'I-SEARCH_INTENT'
54
- ]
55
- id2label = {i: label for i, label in enumerate(LABEL_LIST)}
56
- label2id = {label: i for i, label in enumerate(LABEL_LIST)}
57
-
58
- # 模型ID (替换为您的实际仓库名)
59
- model_id = "lujin/search-ner-lora-model" # 例如: "lujin/search-ner-lora-model"
60
-
61
- # 加载 tokenizer
62
- tokenizer = AutoTokenizer.from_pretrained(model_id)
63
-
64
- # 加载基础模型
65
- base_model = AutoModelForTokenClassification.from_pretrained(
66
- model_id,
67
- num_labels=len(LABEL_LIST),
68
- id2label=id2label,
69
- label2id=label2id,
70
- ignore_mismatched_sizes=True
71
- )
72
-
73
- # 将模型切换到评估模式并移动到GPU
74
- if torch.cuda.is_available():
75
- base_model = base_model.cuda()
76
- base_model.eval()
77
-
78
- # 创建 Pipeline
79
  ner_pipe = pipeline(
80
  "token-classification",
81
- model=base_model,
82
  tokenizer=tokenizer,
83
  aggregation_strategy="simple",
84
  device=0 if torch.cuda.is_available() else -1
 
35
  您可以使用 Hugging Face Transformers 库加载和使用此模型进行推理:
36
 
37
  ```python
38
+ from transformers import AutoModelForTokenClassification,AutoTokenizer,pipeline
39
+ model = AutoModelForTokenClassification.from_pretrained('lujin/search-ner-lora-model')
40
+ tokenizer = AutoTokenizer.from_pretrained('lujin/search-ner-lora-model')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  ner_pipe = pipeline(
42
  "token-classification",
43
+ model=model,
44
  tokenizer=tokenizer,
45
  aggregation_strategy="simple",
46
  device=0 if torch.cuda.is_available() else -1