from transformers import pipeline # 加载模型 ner_pipeline = pipeline("ner", model="./models/resume_ner_model", tokenizer="./models/resume_ner_model") # 解析文本 def parse_resume(text): results = ner_pipeline(text) parsed_data = [] current_entity = {} for result in results: if result["entity"].startswith("B-"): if current_entity: parsed_data.append(current_entity) current_entity = { "label": result["entity"][2:], "text": result["word"] } elif result["entity"].startswith("I-"): current_entity["text"] += result["word"] if current_entity: parsed_data.append(current_entity) return parsed_data # 示例 text = "2001.09--2005.07  佳木斯大学中文系汉语言文学专业学生" results = parse_resume(text) print(results)