[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-plkmo--BERT-Relation-Extraction":3,"tool-plkmo--BERT-Relation-Extraction":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",140436,2,"2026-04-05T23:32:43",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":70,"readme_en":71,"readme_zh":72,"quickstart_zh":73,"use_case_zh":74,"hero_image_url":75,"owner_login":76,"owner_name":77,"owner_avatar_url":78,"owner_bio":79,"owner_company":80,"owner_location":81,"owner_email":82,"owner_twitter":80,"owner_website":83,"owner_url":84,"languages":85,"stars":94,"forks":95,"last_commit_at":96,"license":97,"difficulty_score":10,"env_os":98,"env_gpu":99,"env_ram":98,"env_deps":100,"category_tags":109,"github_topics":110,"view_count":23,"oss_zip_url":80,"oss_zip_packed_at":80,"status":16,"created_at":118,"updated_at":119,"faqs":120,"releases":151},2337,"plkmo\u002FBERT-Relation-Extraction","BERT-Relation-Extraction","PyTorch implementation for \"Matching the Blanks: Distributional Similarity for Relation Learning\" paper","BERT-Relation-Extraction 是一个基于 PyTorch 开发的开源项目，旨在高效提取文本中实体间的语义关系。它复现了 ACL 2019 论文《Matching the Blanks》的核心算法，并扩展支持了 ALBERT 和 BioBERT 等先进预训练模型。\n\n在自然语言处理中，准确判断两个实体（如“人物”与“地点”）之间的具体关系往往具有挑战性。传统方法依赖大量标注数据，而 BERT-Relation-Extraction 通过独特的“匹配空白”（Matching the Blanks）机制，利用分布相似性进行无监督预训练，显著降低了对标注数据的依赖，同时在 SemEval 等标准任务上实现了高精度的关系分类。\n\n该工具特别适合 NLP 研究人员、AI 开发者以及需要构建知识图谱的数据工程师使用。无论是处理通用新闻文本还是生物医学文献（借助 BioBERT），用户都能灵活调用。其技术亮点在于将实体掩码预训练与微调任务相结合，既支持从零开始的深度训练，也允许直接加载预训练权重进行快速推理。只需简单标记句子中的实体，即可即时获得如“因果”、“部分 - 整体”等关系","BERT-Relation-Extraction 是一个基于 PyTorch 开发的开源项目，旨在高效提取文本中实体间的语义关系。它复现了 ACL 2019 论文《Matching the Blanks》的核心算法，并扩展支持了 ALBERT 和 BioBERT 等先进预训练模型。\n\n在自然语言处理中，准确判断两个实体（如“人物”与“地点”）之间的具体关系往往具有挑战性。传统方法依赖大量标注数据，而 BERT-Relation-Extraction 通过独特的“匹配空白”（Matching the Blanks）机制，利用分布相似性进行无监督预训练，显著降低了对标注数据的依赖，同时在 SemEval 等标准任务上实现了高精度的关系分类。\n\n该工具特别适合 NLP 研究人员、AI 开发者以及需要构建知识图谱的数据工程师使用。无论是处理通用新闻文本还是生物医学文献（借助 BioBERT），用户都能灵活调用。其技术亮点在于将实体掩码预训练与微调任务相结合，既支持从零开始的深度训练，也允许直接加载预训练权重进行快速推理。只需简单标记句子中的实体，即可即时获得如“因果”、“部分 - 整体”等关系预测结果，是探索关系抽取领域的实用利器。","# BERT(S) for Relation Extraction\n\n## Overview\nA PyTorch implementation of the models for the paper [\"Matching the Blanks: Distributional Similarity for Relation Learning\"](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1906.03158.pdf) published in ACL 2019.  \nNote: This is not an official repo for the paper.  \nAdditional models for relation extraction, implemented here based on the paper's methodology:  \n- ALBERT (https:\u002F\u002Farxiv.org\u002Fabs\u002F1909.11942)   \n- BioBERT (https:\u002F\u002Farxiv.org\u002Fabs\u002F1901.08746)\n\nFor more conceptual details on the implementation, please see https:\u002F\u002Ftowardsdatascience.com\u002Fbert-s-for-relation-extraction-in-nlp-2c7c3ab487c4\n\nIf you like my work, please consider sponsoring by clicking the sponsor button at the top.\n\n## Requirements\nRequirements: Python (3.8+)\n```bash\npython3 -m pip install -r requirements.txt\npython3 -m spacy download en_core_web_lg\n```\n\nPre-trained BERT models (ALBERT, BERT) courtesy of HuggingFace.co (https:\u002F\u002Fhuggingface.co)   \nPre-trained BioBERT model courtesy of https:\u002F\u002Fgithub.com\u002Fdmis-lab\u002Fbiobert   \n\nTo use BioBERT(biobert_v1.1_pubmed), download & unzip the model from [here](https:\u002F\u002Fgithub.com\u002Fdmis-lab\u002Fbiobert) to .\u002Fadditional_models folder.   \n\n## Training by matching the blanks (BERT\u003Csub>EM\u003C\u002Fsub> + MTB)\nRun main_pretraining.py with arguments below. Pre-training data can be any .txt continuous text file.  \nWe use Spacy NLP to grab pairwise entities (within a window size of 40 tokens length) from the text to form relation statements for pre-training. Entities recognition are based on NER and dependency tree parsing of objects\u002Fsubjects.  \n\nThe pre-training data taken from CNN dataset (cnn.txt) that I've used can be downloaded [here.](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1aMiIZXLpO7JF-z_Zte3uH7OCo4Uk_0do\u002Fview?usp=sharing)   \nDownload and save as .\u002Fdata\u002Fcnn.txt   \nHowever, do note that the paper uses wiki dumps data for MTB pre-training which is much larger than the CNN dataset.   \n\nNote: Pre-training can take a long time, depending on available GPU. It is possible to directly fine-tune on the relation-extraction task and still get reasonable results, following the section below.  \n\n```bash\nmain_pretraining.py [-h] \n\t[--pretrain_data TRAIN_PATH] \n\t[--batch_size BATCH_SIZE]\n\t[--freeze FREEZE]  \n\t[--gradient_acc_steps GRADIENT_ACC_STEPS]\n\t[--max_norm MAX_NORM]\n\t[--fp16 FP_16]  \n\t[--num_epochs NUM_EPOCHS]\n\t[--lr LR]\n\t[--model_no MODEL_NO (0: BERT ; 1: ALBERT ; 2: BioBERT)]  \n\t[--model_size MODEL_SIZE (BERT: 'bert-base-uncased', 'bert-large-uncased';   \n\t\t\t\tALBERT: 'albert-base-v2', 'albert-large-v2';   \n\t\t\t\tBioBERT: 'bert-base-uncased' (biobert_v1.1_pubmed))]\n```\n\n## Fine-tuning on SemEval2010 Task 8 (BERT\u003Csub>EM\u003C\u002Fsub>\u002FBERT\u003Csub>EM\u003C\u002Fsub> + MTB)\nRun main_task.py with arguments below. Requires SemEval2010 Task 8 dataset, available [here.](https:\u002F\u002Fgithub.com\u002Fsahitya0000\u002FRelation-Classification\u002Fblob\u002Fmaster\u002Fcorpus\u002FSemEval2010_task8_all_data.zip) Download & unzip to .\u002Fdata\u002F folder.\n\n```bash\nmain_task.py [-h] \n\t[--train_data TRAIN_DATA]\n\t[--test_data TEST_DATA]\n\t[--use_pretrained_blanks USE_PRETRAINED_BLANKS]\n\t[--num_classes NUM_CLASSES] \n\t[--batch_size BATCH_SIZE]\n\t[--gradient_acc_steps GRADIENT_ACC_STEPS]\n\t[--max_norm MAX_NORM]\n\t[--fp16 FP_16]  \n\t[--num_epochs NUM_EPOCHS]\n\t[--lr LR]\n\t[--model_no MODEL_NO (0: BERT ; 1: ALBERT ; 2: BioBERT)]  \n\t[--model_size MODEL_SIZE (BERT: 'bert-base-uncased', 'bert-large-uncased';   \n\t\t\t\tALBERT: 'albert-base-v2', 'albert-large-v2';   \n\t\t\t\tBioBERT: 'bert-base-uncased' (biobert_v1.1_pubmed))]    \n\t[--train TRAIN]\n\t[--infer INFER]\n```\n\n### Inference (--infer=1)\nTo infer a sentence, you can annotate entity1 & entity2 of interest within the sentence with their respective entities tags [E1], [E2]. \nExample:\n```bash\nType input sentence ('quit' or 'exit' to terminate):\nThe surprise [E1]visit[\u002FE1] caused a [E2]frenzy[\u002FE2] on the already chaotic trading floor.\n\nSentence:  The surprise [E1]visit[\u002FE1] caused a [E2]frenzy[\u002FE2] on the already chaotic trading floor.\nPredicted:  Cause-Effect(e1,e2) \n```\n\n```python\nfrom src.tasks.infer import infer_from_trained\n\ninferer = infer_from_trained(args, detect_entities=False)\ntest = \"The surprise [E1]visit[\u002FE1] caused a [E2]frenzy[\u002FE2] on the already chaotic trading floor.\"\ninferer.infer_sentence(test, detect_entities=False)\n```\n```bash\nSentence:  The surprise [E1]visit[\u002FE1] caused a [E2]frenzy[\u002FE2] on the already chaotic trading floor.\nPredicted:  Cause-Effect(e1,e2) \n```\n\nThe script can also automatically detect potential entities in an input sentence, in which case all possible relation combinations are inferred:\n```python\ninferer = infer_from_trained(args, detect_entities=True)\ntest2 = \"After eating the chicken, he developed a sore throat the next morning.\"\ninferer.infer_sentence(test2, detect_entities=True)\n```\n```bash\nSentence:  [E2]After eating the chicken[\u002FE2] , [E1]he[\u002FE1] developed a sore throat the next morning .\nPredicted:  Other \n\nSentence:  After eating the chicken , [E1]he[\u002FE1] developed [E2]a sore throat[\u002FE2] the next morning .\nPredicted:  Other \n\nSentence:  [E1]After eating the chicken[\u002FE1] , [E2]he[\u002FE2] developed a sore throat the next morning .\nPredicted:  Other \n\nSentence:  [E1]After eating the chicken[\u002FE1] , he developed [E2]a sore throat[\u002FE2] the next morning .\nPredicted:  Other \n\nSentence:  After eating the chicken , [E2]he[\u002FE2] developed [E1]a sore throat[\u002FE1] the next morning .\nPredicted:  Other \n\nSentence:  [E2]After eating the chicken[\u002FE2] , he developed [E1]a sore throat[\u002FE1] the next morning .\nPredicted:  Cause-Effect(e2,e1) \n```\n\n## FewRel Task\nDownload the FewRel 1.0 dataset [here.](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1ljobnuzxStFQJSlN4ZHMcMhZtEYaRAHy?usp=sharing) and unzip to .\u002Fdata\u002F folder.  \nRun main_task.py with argument 'task' set as 'fewrel'.\n```bash\npython main_task.py --task fewrel\n```\nResults:  \n(5-way 1-shot)  \nBERT\u003Csub>EM\u003C\u002Fsub> without MTB, not trained on any FewRel data  \n| Model size | Accuracy (41646 samples) |\n|------------|--------------------------|\n| bert-base-uncased  | 62.229 %         |\n| bert-large-uncased | 72.766 %         |\n\n\n## Benchmark Results\n\n### SemEval2010 Task 8\n1) Base architecture: BERT base uncased (12-layer, 768-hidden, 12-heads, 110M parameters)\n\nWithout MTB pre-training: F1 results when trained on 100 % training data:\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fplkmo_BERT-Relation-Extraction_readme_6767bb9671fb.png) \n\n\n2) Base architecture: ALBERT base uncased (12 repeating layers, 128 embedding, 768-hidden, 12-heads, 11M parameters)  \n\nWithout MTB pre-training: F1 results when trained on 100 % training data:\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fplkmo_BERT-Relation-Extraction_readme_ef942f0f5b83.png) \n\n## To add\n- inference & results on benchmarks (SemEval2010 Task 8) with MTB pre-training\n- felrel task\n\n","# 用于关系抽取的 BERT(S)\n\n## 概述\n这是一个基于 PyTorch 的实现，用于 ACL 2019 年发表的论文《匹配空缺：用于关系学习的分布相似性》（https:\u002F\u002Farxiv.org\u002Fpdf\u002F1906.03158.pdf）中的模型。  \n注意：这不是该论文的官方仓库。  \n在此基础上，我们还实现了以下基于该论文方法的关系抽取模型：  \n- ALBERT (https:\u002F\u002Farxiv.org\u002Fabs\u002F1909.11942)   \n- BioBERT (https:\u002F\u002Farxiv.org\u002Fabs\u002F1901.08746)\n\n有关实现的更多概念性细节，请参阅：https:\u002F\u002Ftowardsdatascience.com\u002Fbert-s-for-relation-extraction-in-nlp-2c7c3ab487c4\n\n如果您喜欢我的工作，请考虑通过点击顶部的赞助按钮来支持我。\n\n## 需求\n需求：Python (3.8+)  \n```bash\npython3 -m pip install -r requirements.txt\npython3 -m spacy download en_core_web_lg\n```\n\n预训练的 BERT 模型（ALBERT、BERT）由 HuggingFace.co (https:\u002F\u002Fhuggingface.co) 提供；  \n预训练的 BioBERT 模型由 https:\u002F\u002Fgithub.com\u002Fdmis-lab\u002Fbiobert 提供。  \n\n要使用 BioBERT (biobert_v1.1_pubmed)，请从 [这里](https:\u002F\u002Fgithub.com\u002Fdmis-lab\u002Fbiobert) 下载并解压模型到 .\u002Fadditional_models 文件夹中。  \n\n## 通过匹配空缺进行预训练（BERT\u003Csub>EM\u003C\u002Fsub> + MTB）\n运行 main_pretraining.py，并传入以下参数。预训练数据可以是任何 .txt 格式的连续文本文件。  \n我们使用 Spacy NLP 从文本中提取成对实体（窗口大小为 40 个标记），以形成用于预训练的关系语句。实体识别基于 NER 和主语\u002F宾语的依存句法分析。  \n\n我使用的 CNN 数据集（cnn.txt）预训练数据可在此下载：[链接](https:\u002F\u002Fdrive.google.com\u002Ffile\u002Fd\u002F1aMiIZXLpO7JF-z_Zte3uH7OCo4Uk_0do\u002Fview?usp=sharing)。  \n请下载并保存为 .\u002Fdata\u002Fcnn.txt。  \n不过请注意，论文中用于 MTB 预训练的数据是维基百科转储文件，其规模远大于 CNN 数据集。  \n\n注意：预训练可能需要较长时间，具体取决于可用的 GPU。您也可以直接在关系抽取任务上进行微调，同样可以获得合理的结果，详见下文。  \n\n```bash\nmain_pretraining.py [-h] \n\t[--pretrain_data TRAIN_PATH] \n\t[--batch_size BATCH_SIZE]\n\t[--freeze FREEZE]  \n\t[--gradient_acc_steps GRADIENT_ACC_STEPS]\n\t[--max_norm MAX_NORM]\n\t[--fp16 FP_16]  \n\t[--num_epochs NUM_EPOCHS]\n\t[--lr LR]\n\t[--model_no MODEL_NO (0: BERT ; 1: ALBERT ; 2: BioBERT)]  \n\t[--model_size MODEL_SIZE (BERT: 'bert-base-uncased', 'bert-large-uncased';   \n\t\t\t\tALBERT: 'albert-base-v2', 'albert-large-v2';   \n\t\t\t\tBioBERT: 'bert-base-uncased' (biobert_v1.1_pubmed))]\n```\n\n## 在 SemEval2010 Task 8 上进行微调（BERT\u003Csub>EM\u003C\u002Fsub>\u002FBERT\u003Csub>EM\u003C\u002Fsub> + MTB）\n运行 main_task.py，并传入以下参数。需要 SemEval2010 Task 8 数据集，可在此下载：[链接](https:\u002F\u002Fgithub.com\u002Fsahitya0000\u002FRelation-Classification\u002Fblob\u002Fmaster\u002Fcorpus\u002FSemEval2010_task8_all_data.zip)。请下载并解压到 .\u002Fdata\u002F 文件夹中。\n\n```bash\nmain_task.py [-h] \n\t[--train_data TRAIN_DATA]\n\t[--test_data TEST_DATA]\n\t[--use_pretrained_blanks USE_PRETRAINED_BLANKS]\n\t[--num_classes NUM_CLASSES] \n\t[--batch_size BATCH_SIZE]\n\t[--gradient_acc_steps GRADIENT_ACC_STEPS]\n\t[--max_norm MAX_NORM]\n\t[--fp16 FP_16]  \n\t[--num_epochs NUM_EPOCHS]\n\t[--lr LR]\n\t[--model_no MODEL_NO (0: BERT ; 1: ALBERT ; 2: BioBERT)]  \n\t[--model_size MODEL_SIZE (BERT: 'bert-base-uncased', 'bert-large-uncased';   \n\t\t\t\tALBERT: 'albert-base-v2', 'albert-large-v2';   \n\t\t\t\tBioBERT: 'bert-base-uncased' (biobert_v1.1_pubmed))]    \n\t[--train TRAIN]\n\t[--infer INFER]\n```\n\n### 推理 (--infer=1)\n要对一句话进行推理，您可以将句子中感兴趣的实体1和实体2分别用标签 [E1] 和 [E2] 标注。  \n示例：\n```bash\n输入句子（输入 'quit' 或 'exit' 结束）：\nThe surprise [E1]visit[\u002FE1] caused a [E2]frenzy[\u002FE2] on the already chaotic trading floor.\n\n句子： The surprise [E1]visit[\u002FE1] caused a [E2]frenzy[\u002FE2] on the already chaotic trading floor.\n预测： Cause-Effect(e1,e2) \n```\n\n```python\nfrom src.tasks.infer import infer_from_trained\n\ninferer = infer_from_trained(args, detect_entities=False)\ntest = \"The surprise [E1]visit[\u002FE1] caused a [E2]frenzy[\u002FE2] on the already chaotic trading floor.\"\ninferer.infer_sentence(test, detect_entities=False)\n```\n```bash\n句子： The surprise [E1]visit[\u002FE1] caused a [E2]frenzy[\u002FE2] on the already chaotic trading floor.\n预测： Cause-Effect(e1,e2) \n```\n\n该脚本还可以自动检测输入句子中的潜在实体，在这种情况下会推断出所有可能的关系组合：  \n```python\ninferer = infer_from_trained(args, detect_entities=True)\ntest2 = \"After eating the chicken, he developed a sore throat the next morning.\"\ninferer.infer_sentence(test2, detect_entities=True)\n```\n```bash\n句子： [E2]After eating the chicken[\u002FE2] , [E1]he[\u002FE1] developed a sore throat the next morning .\n预测： Other \n\n句子： After eating the chicken , [E1]he[\u002FE1] developed [E2]a sore throat[\u002FE2] the next morning .\n预测： Other \n\n句子： [E1]After eating the chicken[\u002FE1] , [E2]he[\u002FE2] developed a sore throat the next morning .\n预测： Other \n\n句子： [E1]After eating the chicken[\u002FE1] , he developed [E2]a sore throat[\u002FE2] the next morning .\n预测： Other \n\n句子： After eating the chicken , [E2]he[\u002FE2] developed [E1]a sore throat[\u002FE1] the next morning .\n预测： Other \n\n句子： [E2]After eating the chicken[\u002FE2] , he developed [E1]a sore throat[\u002FE1] the next morning .\n预测： Cause-Effect(e2,e1) \n```\n\n## FewRel 任务\n请在此下载 FewRel 1.0 数据集：[链接](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1ljobnuzxStFQJSlN4ZHMcMhZtEYaRAHy?usp=sharing)，并解压到 .\u002Fdata\u002F 文件夹中。  \n运行 main_task.py，并将参数 'task' 设置为 'fewrel'。  \n```bash\npython main_task.py --task fewrel\n```\n结果如下：  \n(5-way 1-shot)  \nBERT\u003Csub>EM\u003C\u002Fsub> 未使用 MTB，未在任何 FewRel 数据上训练  \n| 模型尺寸 | 准确率（41646 个样本） |\n|------------|--------------------------|\n| bert-base-uncased  | 62.229 %         |\n| bert-large-uncased | 72.766 %         |\n\n\n## 基准测试结果\n\n### SemEval2010 Task 8\n1) 基础架构：BERT base uncased（12 层，768 隐藏层，12 头注意力，1.1 亿参数）\n\n未使用 MTB 预训练：在 100% 训练数据上训练时的 F1 分数：  \n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fplkmo_BERT-Relation-Extraction_readme_6767bb9671fb.png) \n\n\n2) 基础架构：ALBERT base uncased（12 重复层，128 嵌入维度，768 隐藏层，12 头注意力，1100 万参数）  \n\n未使用 MTB 预训练：在 100% 训练数据上训练时的 F1 分数：  \n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fplkmo_BERT-Relation-Extraction_readme_ef942f0f5b83.png) \n\n## 待补充\n- 使用 MTB 预训练后在基准测试（SemEval2010 Task 8）上的推理与结果\n- felrel 任务","# BERT-Relation-Extraction 快速上手指南\n\n本指南基于 ACL 2019 论文《Matching the Blanks: Distributional Similarity for Relation Learning》的 PyTorch 实现，支持 BERT、ALBERT 和 BioBERT 模型进行关系抽取任务。\n\n## 环境准备\n\n**系统要求：**\n- Python 3.8 或更高版本\n- GPU 环境（推荐，用于加速预训练和微调）\n- Git\n\n**前置依赖：**\n- PyTorch\n- HuggingFace Transformers (用于加载 BERT\u002FALBERT)\n- Spacy (用于实体识别和依存句法分析)\n- 其他依赖见 `requirements.txt`\n\n## 安装步骤\n\n1. **克隆仓库并安装依赖**\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002Fplkmo\u002FBERT-Relation-Extraction.git\n   cd BERT-Relation-Extraction\n   python3 -m pip install -r requirements.txt\n   ```\n   > **提示**：国内用户建议使用清华或阿里镜像源加速安装：\n   > `python3 -m pip install -r requirements.txt -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple`\n\n2. **下载 Spacy 英文模型**\n   ```bash\n   python3 -m spacy download en_core_web_lg\n   ```\n   > **提示**：若下载缓慢，可手动下载模型文件后离线安装，或使用国内镜像配置。\n\n3. **准备预训练模型（可选）**\n   - **BERT \u002F ALBERT**：代码运行时会自动从 HuggingFace 下载。\n   - **BioBERT**：需手动下载。\n     1. 访问 [BioBERT GitHub](https:\u002F\u002Fgithub.com\u002Fdmis-lab\u002Fbiobert) 下载 `biobert_v1.1_pubmed` 模型。\n     2. 解压并将文件夹放入项目根目录下的 `.\u002Fadditional_models` 文件夹中。\n\n4. **准备数据集**\n   - **SemEval2010 Task 8 (微调必备)**：\n     下载 [数据集链接](https:\u002F\u002Fgithub.com\u002Fsahitya0000\u002FRelation-Classification\u002Fblob\u002Fmaster\u002Fcorpus\u002FSemEval2010_task8_all_data.zip)，解压至 `.\u002Fdata\u002F` 目录。\n   - **预训练数据 (可选)**：\n     如需复现论文的 MTB 预训练，可下载 CNN 数据集保存为 `.\u002Fdata\u002Fcnn.txt`，或使用更大的 Wiki dumps 数据。\n\n## 基本使用\n\n### 1. 直接推理（无需训练）\n\n如果你已有训练好的模型，可以直接对句子进行关系推断。实体需用 `[E1]...[\u002FE1]` 和 `[E2]...[\u002FE2]` 标签标记。\n\n**命令行交互模式：**\n```bash\npython main_task.py --infer 1 --model_no 0 --model_size 'bert-base-uncased'\n```\n输入示例：\n```text\nType input sentence ('quit' or 'exit' to terminate):\nThe surprise [E1]visit[\u002FE1] caused a [E2]frenzy[\u002FE2] on the already chaotic trading floor.\n```\n输出示例：\n```text\nSentence:  The surprise [E1]visit[\u002FE1] caused a [E2]frenzy[\u002FE2] on the already chaotic trading floor.\nPredicted:  Cause-Effect(e1,e2) \n```\n\n**Python 代码调用模式：**\n```python\nfrom src.tasks.infer import infer_from_trained\nimport argparse\n\n# 模拟参数配置 (实际使用时请加载你的 args)\nargs = argparse.Namespace()\nargs.model_no = 0\nargs.model_size = 'bert-base-uncased'\n# ... 其他必要参数\n\n# 初始化推断器 (detect_entities=False 表示实体已标记)\ninferer = infer_from_trained(args, detect_entities=False)\n\ntest_sentence = \"The surprise [E1]visit[\u002FE1] caused a [E2]frenzy[\u002FE2] on the already chaotic trading floor.\"\nresult = inferer.infer_sentence(test_sentence, detect_entities=False)\nprint(result)\n```\n\n**自动实体检测模式：**\n若未标记实体，可设置 `detect_entities=True`，系统将自动尝试识别所有可能的实体组合并预测关系：\n```python\ninferer = infer_from_trained(args, detect_entities=True)\ntest_sentence = \"After eating the chicken, he developed a sore throat the next morning.\"\n# 系统将输出多种实体组合的预测结果\ninferer.infer_sentence(test_sentence, detect_entities=True)\n```\n\n### 2. 微调模型 (Fine-tuning)\n\n使用 SemEval2010 Task 8 数据集微调模型：\n\n```bash\npython main_task.py \\\n    --train_data .\u002Fdata\u002Ftrain.txt \\\n    --test_data .\u002Fdata\u002Ftest.txt \\\n    --model_no 0 \\\n    --model_size 'bert-base-uncased' \\\n    --num_epochs 10 \\\n    --lr 2e-5 \\\n    --batch_size 16 \\\n    --train 1\n```\n\n### 3. MTB 预训练 (进阶)\n\n若需从头进行“匹配空白”(Matching the Blanks) 预训练：\n\n```bash\npython main_pretraining.py \\\n    --pretrain_data .\u002Fdata\u002Fcnn.txt \\\n    --model_no 0 \\\n    --model_size 'bert-base-uncased' \\\n    --num_epochs 5 \\\n    --batch_size 32\n```\n> **注意**：预训练耗时较长，建议仅在拥有充足 GPU 资源且需要特定领域适配时进行。一般情况下，直接使用预训练权重进行微调即可获得良好效果。","某金融科技公司的情报团队需要从海量财经新闻中自动提取实体间的因果关系，以构建实时风险预警图谱。\n\n### 没有 BERT-Relation-Extraction 时\n- **规则维护成本高**：依赖人工编写正则表达式匹配“导致”、“引发”等关键词，无法覆盖“造成”、“致使”等多样化表达，漏报率极高。\n- **语境理解能力弱**：难以区分字面相似但逻辑相反的句子（如否定句或假设句），常将“未造成损失”错误识别为存在因果关系。\n- **领域适配困难**：通用模型缺乏对金融术语（如“流动性枯竭”、“抛售潮”）的敏感度，在专业文本上准确率大幅下降。\n- **标注数据依赖重**：训练新模型需要大量人工标注的“实体 - 关系”对数据，耗时耗力且启动周期长。\n\n### 使用 BERT-Relation-Extraction 后\n- **语义泛化能力强**：利用 MTB（Matching the Blanks）预训练机制，模型能自动学习分布相似性，精准识别各种隐含的因果表述，无需穷举关键词。\n- **深层逻辑判断准**：基于 BERT\u002FBioBERT 的上下文编码能力，有效处理否定、倒装等复杂句式，显著降低误报率。\n- **领域迁移更灵活**：直接加载 BioBERT 或在财经语料上进行空白匹配预训练，快速适配金融场景，大幅提升专业实体关系的抽取精度。\n- **冷启动门槛低**：支持在无标注数据情况下先进行自监督预训练，仅需少量样本微调即可达到可用效果，极大缩短项目上线时间。\n\nBERT-Relation-Extraction 通过创新的空白匹配预训练策略，让机器像人类一样理解实体间潜在的语义关联，将非结构化文本转化为高价值知识图谱的效率提升了数倍。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fplkmo_BERT-Relation-Extraction_e91b3a7e.png","plkmo","Wee Tee, Soh","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fplkmo_c826cee5.jpg","NLP, mostly",null,"Singapore","weeteesoh345@gmail.com","https:\u002F\u002Fmedium.com\u002F@weeteesoh345","https:\u002F\u002Fgithub.com\u002Fplkmo",[86,90],{"name":87,"color":88,"percentage":89},"Python","#3572A5",100,{"name":91,"color":92,"percentage":93},"Shell","#89e051",0,603,134,"2026-04-02T16:53:30","Apache-2.0","未说明","必需（预训练耗时取决于可用 GPU），具体型号、显存大小及 CUDA 版本未说明",{"notes":101,"python":102,"dependencies":103},"1. 需手动下载并解压 BioBERT 模型至 .\u002Fadditional_models 文件夹。2. 预训练数据（如 CNN 数据集或 Wiki dumps）和微调数据（SemEval2010 Task 8, FewRel）需单独下载并放置于指定目录。3. 预训练过程可能非常耗时，建议根据硬件条件调整批次大小或使用混合精度训练 (--fp16)。4. 推理时支持自动实体检测或手动标注实体标签 ([E1], [E2])。","3.8+",[104,105,106,107,108],"torch (PyTorch)","spacy","en_core_web_lg (Spacy 模型)","transformers (隐含，用于加载 HuggingFace BERT\u002FALBERT)","requirements.txt 中定义的其他依赖",[13,26],[111,112,113,114,115,116,117],"bert","albert","natural-language-processing","nlp","pytorch","relation-extraction","relationships","2026-03-27T02:49:30.150509","2026-04-06T11:30:52.759186",[121,126,131,136,141,146],{"id":122,"question_zh":123,"answer_zh":124,"source_url":125},10729,"运行代码时提示找不到 '.\u002Fdata\u002FBERT_tokenizer.pkl' 文件，该如何解决？","该错误通常是因为缺少 SemEval2010 Task 8 数据集。请从以下链接下载数据并解压到 .\u002Fdata\u002F 文件夹中：https:\u002F\u002Fgithub.com\u002Fsahitya0000\u002FRelation-Classification\u002Fblob\u002Fmaster\u002Fcorpus\u002FSemEval2010_task8_all_data.zip。下载后确保目录结构正确，项目会自动处理 tokenizer 文件的生成或加载。","https:\u002F\u002Fgithub.com\u002Fplkmo\u002FBERT-Relation-Extraction\u002Fissues\u002F45",{"id":127,"question_zh":128,"answer_zh":129,"source_url":130},10730,"在 SemEval2010 Task 8 数据集上运行 main_task.py 时出现 'AssertionError: assert re.match(\"^Comment\", comment)' 错误怎么办？","这通常是因为指定了错误的测试数据文件夹路径。请检查 main_task.py 中提供的默认参数，确保 --train_data 和 --test_data 指向正确的文件路径（例如 TRAIN_FILE.TXT 和 TEST_FILE.txt），不要混淆训练集和测试集的文件夹层级。","https:\u002F\u002Fgithub.com\u002Fplkmo\u002FBERT-Relation-Extraction\u002Fissues\u002F26",{"id":132,"question_zh":133,"answer_zh":134,"source_url":135},10731,"使用 'bert-large-uncased' 模型时出现 'RuntimeError: size mismatch' 维度不匹配错误，如何解决？","该问题与模型输出表示方式有关。项目默认使用 'Bert_em'（实体标记 - 实体起始表示）以获得最佳结果。请确保您的配置与论文中描述的输出类型一致，检查是否错误地使用了 'Entity mention pooling' 或 '[CLS] token' 等其他表示方式，导致分类层输入维度与预定义权重不匹配。","https:\u002F\u002Fgithub.com\u002Fplkmo\u002FBERT-Relation-Extraction\u002Fissues\u002F17",{"id":137,"question_zh":138,"answer_zh":139,"source_url":140},10732,"微调后的模型 F1 分数非常低（例如 0.59 左右），可能是什么原因？","首先，请重新克隆仓库以获取修正后的 MTB 模型实现，之前的版本存在错误（参考 Issue #9）。其次，MTB 预训练在大量微调数据上收益递减，尝试减少预训练轮数（例如 2 个 epoch）或使用 Bert-uncased 预训练模型可能在 SemEval 数据集上表现更好（F1 可达 0.76+）。","https:\u002F\u002Fgithub.com\u002Fplkmo\u002FBERT-Relation-Extraction\u002Fissues\u002F8",{"id":142,"question_zh":143,"answer_zh":144,"source_url":145},10733,"如何使用已训练好的模型进行推理（Inference）？需要指定模型文件路径吗？","进行推理时，--model_size 参数应设置为与训练时相同的模型名称（例如 'albert-large-v2'），而不需要手动指定生成的 .pth.tar 文件路径。脚本会自动检测并加载保存的最佳模型或最新检查点。只需将 --train 设为 0 并将 --infer 设为 1 即可。","https:\u002F\u002Fgithub.com\u002Fplkmo\u002FBERT-Relation-Extraction\u002Fissues\u002F21",{"id":147,"question_zh":148,"answer_zh":149,"source_url":150},10734,"代码中是否包含了正确的 MTB（Matching The Blanks）损失函数实现？","早期版本中存在实现错误，已在新版本中修正。目前的实现会在 NCE 批处理后，计算每个关系陈述与其他陈述之间的对比损失（包括点积运算和二元分类器比较）。如果您发现结果异常，请确保使用的是最新提交的代码。","https:\u002F\u002Fgithub.com\u002Fplkmo\u002FBERT-Relation-Extraction\u002Fissues\u002F9",[]]