Cuckoo C4
模型简介
布谷鸟模型采用创新的下一词预测机制进行信息抽取,能够利用各类文本资源自我增强,尤其擅长吸收为大语言模型优化的数据。
模型特点
下一词预测范式
采用类似大语言模型的预测机制,通过标记上下文中的目标词元进行信息抽取
数据高效利用
能够吸收各类文本资源进行自我增强,包括大语言模型优化数据
多版本适配
提供基础版、指令增强版、彩虹版和超级彩虹版四个版本,适应不同需求
模型能力
命名实体识别
关系抽取
问答系统
文本理解
知识抽取
使用案例
信息抽取
实体识别
从文本中识别人物、地点、组织等实体
在CoNLL2003上达到79.94 F1分数
关系抽取
识别实体之间的关系
在CoNLL2004上达到70.47 F1分数
问答系统
阅读理解
回答基于文本内容的问题
在SQuAD上达到86.57 F1分数
🚀 布谷鸟模型(Cuckoo)🐦
布谷鸟(Cuckoo)是一个小型(3亿参数)的信息提取(IE)模型,它模仿大语言模型的下一个标记预测范式。该模型通过在给定的输入上下文中标记来预测下一个标记,而非从词汇表中检索。本仓库包含了论文 Cuckoo: An IE Free Rider Hatched by Massive Nutrition in LLM's Nest 中的模型。
布谷鸟与以往的信息提取预训练模型有很大不同,因为它可以利用任何文本资源来提升自身,尤其是借助为大语言模型精心整理的数据!
目前,我们开源了在以下数据上预训练的布谷鸟模型检查点:
- 从C4转换而来的1亿个下一个标记提取(NTE)实例。(布谷鸟 - C4 🐦)
- 布谷鸟 - C4 + 从有监督微调数据集TuluV3转换而来的260万个下一个标记提取(NTE)实例。(布谷鸟 - C4 - 指令 🐦🛠️)
- 布谷鸟 - C4 - 指令 + MultiNERD、MetaIE、NuNER、MRQA(不包括SQuAD、DROP)。(布谷鸟 - C4 - 彩虹 🌈🐦🛠️)
- 布谷鸟 - C4 - 彩虹 + 多个命名实体识别(NER)数据集、WizardLM数据集、多项选择问答数据集、MMLU、SQuAD、DROP、MNLI、SNLI。(布谷鸟 - C4 - 超级彩虹 🦸🌈🐦🛠️)
✨ 主要特性
- 创新的预测范式:模仿大语言模型的下一个标记预测范式,通过在输入上下文中标记来预测下一个标记,而非传统的从词汇表中检索方式。
- 数据利用高效:能够利用任何文本资源进行自我提升,特别是可以借助为大语言模型整理的数据,实现数据的高效利用。
- 多场景适应性:在多种信息提取任务中表现出色,如实体识别、关系理解、问答等,具有广泛的应用场景。
- 模型规模小巧:仅有3亿参数,在保证性能的同时,具有较低的计算资源需求和更快的推理速度。
🚀 快速开始
性能展示 🚀
开启布谷鸟模型的探索之旅,体验它在各类信息提取任务中不可思议的适应效率!
CoNLL2003 | BioNLP2004 | MIT - 餐厅 | MIT - 电影 | 平均值 | CoNLL2004 | ADE | 平均值 | SQuAD | SQuAD - V2 | DROP | 平均值 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
OPT - C4 - TuluV3 | 50.24 | 39.76 | 58.91 | 56.33 | 50.56 | 47.14 | 45.66 | 46.40 | 39.80 | 53.81 | 31.00 | 41.54 |
RoBERTa | 33.75 | 32.91 | 62.15 | 58.32 | 46.80 | 34.16 | 2.15 | 18.15 | 31.86 | 48.55 | 9.16 | 29.86 |
MRQA | 72.45 | 55.93 | 68.68 | 66.26 | 65.83 | 66.23 | 67.44 | 66.84 | 80.07 | 66.22 | 54.46 | 66.92 |
MultiNERD | 66.78 | 54.62 | 64.16 | 66.30 | 60.59 | 57.52 | 45.10 | 51.31 | 42.85 | 50.99 | 30.12 | 41.32 |
NuNER | 74.15 | 56.36 | 68.57 | 64.88 | 65.99 | 65.12 | 63.71 | 64.42 | 61.60 | 52.67 | 37.37 | 50.55 |
MetaIE | 71.33 | 55.63 | 70.08 | 65.23 | 65.57 | 64.81 | 64.40 | 64.61 | 74.59 | 62.54 | 30.73 | 55.95 |
布谷鸟 🐦🛠️ | 73.60 | 57.00 | 67.63 | 67.12 | 66.34 | 69.57 | 71.70 | 70.63 | 77.47 | 64.06 | 54.25 | 65.26 |
└─ 仅预训练 🐦 | 72.46 | 55.87 | 66.87 | 67.23 | 65.61 | 68.14 | 69.39 | 68.77 | 75.64 | 63.36 | 52.81 | 63.94 |
└─ 仅后训练 | 72.80 | 56.10 | 66.02 | 67.10 | 65.51 | 68.66 | 69.75 | 69.21 | 77.05 | 62.39 | 54.80 | 64.75 |
彩虹布谷鸟 🌈🐦🛠️ | 79.94 | 58.39 | 70.30 | 67.00 | 68.91 | 70.47 | 76.05 | 73.26 | 86.57 | 69.41 | 64.64 | 73.54 |
快速体验布谷鸟模型的下一个标记提取 ⚡
我们建议使用最强的超级彩虹布谷鸟 🦸🌈🐦🛠️ 进行零样本提取。
1️⃣ 首先加载模型和分词器
from transformers import AutoModelForTokenClassification, AutoTokenizer
import torch
import spacy
nlp = spacy.load("en_core_web_sm")
device = torch.device("cuda:0")
path = f"KomeijiForce/Cuckoo-C4-Super-Rainbow"
tokenizer = AutoTokenizer.from_pretrained(path)
tagger = AutoModelForTokenClassification.from_pretrained(path).to(device)
2️⃣ 定义下一个标记提取函数
def next_tokens_extraction(text):
def find_sequences(lst):
sequences = []
i = 0
while i < len(lst):
if lst[i] == 0:
start = i
end = i
i += 1
while i < len(lst) and lst[i] == 1:
end = i
i += 1
sequences.append((start, end+1))
else:
i += 1
return sequences
text = " ".join([token.text for token in nlp(text)])
inputs = tokenizer(text, return_tensors="pt").to(device)
tag_predictions = tagger(**inputs).logits[0].argmax(-1)
predictions = [tokenizer.decode(inputs.input_ids[0, seq[0]:seq[1]]).strip() for seq in find_sequences(tag_predictions)]
return predictions
3️⃣ 调用函数进行提取!
案例1:基本实体和关系理解
text = "Tom and Jack went to their trip in Paris."
for question in [
"What are the people mentioned here?",
"What is the city mentioned here?",
"Who goes with Tom together?",
"What do Tom and Jack go to Paris for?",
"Which city does George live in?",
]:
text = f"User:\n\n{text}\n\nQuestion: {question}\n\nAssistant:"
predictions = next_tokens_extraction(text)
print(question, predictions)
你将得到类似如下的结果:
What are the people mentioned here? ['Tom', 'Jack']
What is the city mentioned here? ['Paris']
Who goes with Tom together? ['Jack']
What do Tom and Jack go to Paris for? ['trip']
Which city does George live in? []
其中 [] 表示布谷鸟模型认为没有可提取的下一个标记。
案例2:更长的上下文
passage = f'''Ludwig van Beethoven (17 December 1770 – 26 March 1827) was a German composer and pianist. He is one of the most revered figures in the history of Western music; his works rank among the most performed of the classical music repertoire and span the transition from the Classical period to the Romantic era in classical music. His early period, during which he forged his craft, is typically considered to have lasted until 1802. From 1802 to around 1812, his middle period showed an individual development from the styles of Joseph Haydn and Wolfgang Amadeus Mozart, and is sometimes characterised as heroic. During this time, Beethoven began to grow increasingly deaf. In his late period, from 1812 to 1827, he extended his innovations in musical form and expression.'''
for question in [
"What are the people mentioned here?",
"What is the job of Beethoven?",
"How famous is Beethoven?",
"When did Beethoven's middle period showed an individual development?",
]:
text = f"User:\n\n{passage}\n\nQuestion: {question}\n\nAssistant:"
predictions = next_tokens_extraction(text)
print(question, predictions)
你将得到类似如下的结果:
What are the people mentioned here? ['Ludwig van Beethoven', 'Joseph Haydn', 'Wolfgang Amadeus Mozart']
What is the job of Beethoven? ['composer and pianist']
How famous is Beethoven? ['one of the most revered figures in the history of Western music']
When did Beethoven's middle period showed an individual development? ['1802']
案例3:知识问答
for obj in ["grass", "sea", "fire", "night"]:
text = f"User:\n\nChoices:\nred\nblue\ngreen.\n\nQuestion: What is the color of the {obj}?\n\nAssistant:\n\nAnswer:"
predictions = next_tokens_extraction(text)
print(obj, predictions)
你将得到类似如下的结果:
grass ['green']
sea ['blue']
fire ['red']
night []
这表明布谷鸟模型并非简单地提取可能的文本片段,而是具备理解上下文的知识。
📚 详细文档
文件信息
仓库包含以下文件信息:
special_tokens_map.json
{
"bos_token": {
"content": "<s>",
"lstrip": false,
"normalized": true,
"rstrip": false,
"single_word": false
},
"cls_token": {
"content": "<s>",
"lstrip": false,
"normalized": true,
"rstrip": false,
"single_word": false
},
"eos_token": {
"content": "</s>",
"lstrip": false,
"normalized": true,
"rstrip": false,
"single_word": false
},
"mask_token": {
"content": "<mask>",
"lstrip": true,
"normalized": false,
"rstrip": false,
"single_word": false
},
"pad_token": {
"content": "<pad>",
"lstrip": false,
"normalized": true,
"rstrip": false,
"single_word": false
},
"sep_token": {
"content": "</s>",
"lstrip": false,
"normalized": true,
"rstrip": false,
"single_word": false
},
"unk_token": {
"content": "<unk>",
"lstrip": false,
"normalized": true,
"rstrip": false,
"single_word": false
}
}
tokenizer_config.json
{
"add_prefix_space": true,
"added_tokens_decoder": {
"0": {
"content": "<s>",
"lstrip": false,
"normalized": true,
"rstrip": false,
"single_word": false,
"special": true
},
"1": {
"content": "<pad>",
"lstrip": false,
"normalized": true,
"rstrip": false,
"single_word": false,
"special": true
},
"2": {
"content": "</s>",
"lstrip": false,
"normalized": true,
"rstrip": false,
"single_word": false,
"special": true
},
"3": {
"content": "<unk>",
"lstrip": false,
"normalized": true,
"rstrip": false,
"single_word": false,
"special": true
},
"50264": {
"content": "<mask>",
"lstrip": true,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
}
},
"bos_token": "<s>",
"clean_up_tokenization_spaces": false,
"cls_token": "<s>",
"eos_token": "</s>",
"errors": "replace",
"mask_token": "<mask>",
"max_length": 512,
"model_max_length": 512,
"pad_token": "<pad>",
"sep_token": "</s>",
"stride": 0,
"tokenizer_class": "RobertaTokenizer",
"trim_offsets": true,
"truncation_side": "right",
"truncation_strategy": "longest_first",
"unk_token": "<unk>"
}
merges.txt
内容:"文件内容超过50 KB,过长无法显示。"
vocab.json
内容:"文件内容超过50 KB,过长无法显示。"
config.json
{
"_name_or_path": "models/ptr-large-c4-stage9",
"architectures": [
"RobertaForTokenClassification"
],
"attention_probs_dropout_prob": 0.1,
"bos_token_id": 0,
"classifier_dropout": null,
"eos_token_id": 2,
"finetuning_task": "ner",
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 1024,
"id2label": {
"0": "B",
"1": "I",
"2": "O"
},
"initializer_range": 0.02,
"intermediate_size": 4096,
"label2id": {
"B": 0,
"I": 1,
"O": 2
},
"layer_norm_eps": 1e-05,
"max_position_embeddings": 514,
"model_type": "roberta",
"num_attention_heads": 16,
"num_hidden_layers": 24,
"pad_token_id": 1,
"position_embedding_type": "absolute",
"torch_dtype": "float32",
"transformers_version": "4.45.2",
"type_vocab_size": 1,
"use_cache": true,
"vocab_size": 50265
}
tokenizer.json
内容:"文件内容超过50 KB,过长无法显示。"
📄 许可证
本项目采用MIT许可证。
Phi 2 GGUF
其他
Phi-2是微软开发的一个小型但强大的语言模型,具有27亿参数,专注于高效推理和高质量文本生成。
大型语言模型 支持多种语言
P
TheBloke
41.5M
205
Roberta Large
MIT
基于掩码语言建模目标预训练的大型英语语言模型,采用改进的BERT训练方法
大型语言模型 英语
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基础模型的蒸馏版本,在保持相近性能的同时更轻量高效,适用于序列分类、标记分类等自然语言处理任务。
大型语言模型 英语
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一个多语言大语言模型,针对多语言对话用例进行了优化,在常见的行业基准测试中表现优异。
大型语言模型 英语
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基于100种语言的2.5TB过滤CommonCrawl数据预训练的多语言模型,采用掩码语言建模目标进行训练。
大型语言模型 支持多种语言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基于Transformer架构的英语预训练模型,通过掩码语言建模目标在海量文本上训练,支持文本特征提取和下游任务微调
大型语言模型 英语
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI发布的开放预训练Transformer语言模型套件,参数量从1.25亿到1750亿,旨在对标GPT-3系列性能,同时促进大规模语言模型的开放研究。
大型语言模型 英语
O
facebook
6.3M
198
1
基于transformers库的预训练模型,适用于多种NLP任务
大型语言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多语言大语言模型系列,包含8B、70B和405B参数规模,支持8种语言和代码生成,优化了多语言对话场景。
大型语言模型
Transformers 支持多种语言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基础版是由Google开发的文本到文本转换Transformer模型,参数规模2.2亿,支持多语言NLP任务。
大型语言模型 支持多种语言
T
google-t5
5.4M
702
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98