KomeijiForce commited on
Commit
7f0220b
·
verified ·
1 Parent(s): 3db94ae

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +218 -182
README.md CHANGED
@@ -1,199 +1,235 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  library_name: transformers
3
+ pipeline_tag: token-classification
4
+ license: apache-2.0
5
  ---
6
 
7
+ # Cuckoo 🐦 [[Github]](https://github.com/KomeijiForce/Cuckoo)
8
 
9
+ [Cuckoo: An IE Free Rider Hatched by Massive Nutrition in LLM's Nest](https://huggingface.co/papers/2502.11275) is a small (300M) information extraction (IE) model that imitates the next token prediction paradigm of large language models. Instead of retrieving from the vocabulary, Cuckoo predicts the next tokens by tagging them in the given input context as shown below:
10
 
11
+ ![cuckoo](https://github.com/user-attachments/assets/d000f275-82a7-4939-aca8-341c61a774dc)
12
 
13
+ Cuckoo is substantially different from previous IE pre-training because it can use any text resource to enhance itself, especially by taking a free ride on data curated for LLMs!
14
 
15
+ ![image](https://github.com/user-attachments/assets/f4106f82-6c07-4961-a654-eca7d69428a6)
16
 
 
17
 
18
+ Currently, we open-source checkpoints of Cuckoos that are pre-trained on:
19
 
20
+ 1) 100M next tokens extraction (NTE) instances converted from C4. ([Cuckoo-C4](https://huggingface.co/KomeijiForce/Cuckoo-C4) 🐦)
21
 
22
+ 2) Cuckoo-C4 + 2.6M next token extraction (NTE) instances converted from a supervised fine-tuning dataset, TuluV3. ([Cuckoo-C4-Instruct](https://huggingface.co/KomeijiForce/Cuckoo-C4-Instruct) 🐦🛠️)
 
 
 
 
 
 
23
 
24
+ 3) Cuckoo-C4-Instruct + MultiNERD, MetaIE, NuNER, MRQA (excluding SQuAD, DROP). ([Cuckoo-C4-Rainbow](https://huggingface.co/KomeijiForce/Cuckoo-C4-Rainbow) 🌈🐦🛠️)
25
 
26
+ 4) Cuckoo-C4-Rainbow + Multiple NER Datasets, WizardLM Dataset, Multiple Choice QA Datasets, MMLU, SQuAD, DROP, MNLI, SNLI. ([Cuckoo-C4-Super-Rainbow](https://huggingface.co/KomeijiForce/Cuckoo-C4-Super-Rainbow) 🦸🌈🐦🛠️)
27
 
28
+ ## Performance Demonstration 🚀
 
 
29
 
30
+ Begin your journey with Cuckoo to experience unimaginable adaptation efficiency for all kinds of IE tasks!
31
 
32
+ | | CoNLL2003 | BioNLP2004 | MIT-Restaurant | MIT-Movie | Avg. | CoNLL2004 | ADE | Avg. | SQuAD | SQuAD-V2 | DROP | Avg. |
33
+ |----------------------|-----------|-----------|----------------|-----------|------|-----------|-----|------|-------|----------|------|------|
34
+ | 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 |
35
+ | 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 |
36
+ | 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 |
37
+ | 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 |
38
+ | 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 |
39
+ | 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 |
40
+ | Cuckoo 🐦🛠️ | 73.60 | 57.00 | 67.63 | 67.12 | 66.34 | 69.57 | 71.70 | 70.63 | 77.47 | 64.06 | 54.25 | 65.26 |
41
+ | └─ Only Pre-train 🐦 | 72.46 | 55.87 | 66.87 | 67.23 | 65.61 | 68.14 | 69.39 | 68.77 | 75.64 | 63.36 | 52.81 | 63.94 |
42
+ | └─ Only Post-train | 72.80 | 56.10 | 66.02 | 67.10 | 65.51 | 68.66 | 69.75 | 69.21 | 77.05 | 62.39 | 54.80 | 64.75 |
43
+ | Rainbow Cuckoo 🌈🐦🛠️ | 79.94 | 58.39 | 70.30 | 67.00 | **68.91** | 70.47 | 76.05 | **73.26** | 86.57 | 69.41 | 64.64 | **73.54** |
44
+
45
+ ## Quick Experience with Cuckoo in Next Tokens Extraction ⚡
46
+
47
+ We recommend using the strongest Super Rainbow Cuckoo 🦸🌈🐦🛠️ for zero-shot extraction.
48
+
49
+ 1️⃣ First load the model and the tokenizers
50
+
51
+ ```python
52
+ from transformers import AutoModelForTokenClassification, AutoTokenizer
53
+ import torch
54
+ import spacy
55
+
56
+ nlp = spacy.load("en_core_web_sm")
57
+
58
+ device = torch.device("cuda:0")
59
+ path = f"KomeijiForce/Cuckoo-C4-Super-Rainbow"
60
+ tokenizer = AutoTokenizer.from_pretrained(path)
61
+ tagger = AutoModelForTokenClassification.from_pretrained(path).to(device)
62
+ ```
63
+
64
+ 2️⃣ Define the next tokens extraction function
65
+ ```python
66
+ def next_tokens_extraction(text):
67
+
68
+ def find_sequences(lst):
69
+ sequences = []
70
+ i = 0
71
+ while i < len(lst):
72
+ if lst[i] == 0:
73
+ start = i
74
+ end = i
75
+ i += 1
76
+ while i < len(lst) and lst[i] == 1:
77
+ end = i
78
+ i += 1
79
+ sequences.append((start, end+1))
80
+ else:
81
+ i += 1
82
+ return sequences
83
+
84
+ text = " ".join([token.text for token in nlp(text)])
85
+
86
+ inputs = tokenizer(text, return_tensors="pt").to(device)
87
+ tag_predictions = tagger(**inputs).logits[0].argmax(-1)
88
+
89
+ predictions = [tokenizer.decode(inputs.input_ids[0, seq[0]:seq[1]]).strip() for seq in find_sequences(tag_predictions)]
90
+
91
+ return predictions
92
+ ```
93
+
94
+ 3️⃣ Call the function for extraction!
95
+
96
+ Case 1: Basic entity and relation understanding
97
+
98
+ ```python
99
+ text = "Tom and Jack went to their trip in Paris."
100
+
101
+ for question in [
102
+ "What is the person mentioned here?",
103
+ "What is the city mentioned here?",
104
+ "Who goes with Tom together?",
105
+ "What do Tom and Jack go to Paris for?",
106
+ "Where does George live in?",
107
+ ]:
108
+ prompt = f"User:\n\n{text}\n\nQuestion: {question}\n\nAssistant:"
109
+ predictions = next_tokens_extraction(prompt)
110
+ print(question, predictions)
111
+ ```
112
+ You will get things like,
113
+ ```
114
+ What is the person mentioned here? ['Tom', 'Jack']
115
+ What is the city mentioned here? ['Paris']
116
+ Who goes with Tom together? ['Jack']
117
+ What do Tom and Jack go to Paris for? ['trip']
118
+ Where does George live in? []
119
+ ```
120
+ where [] indicates Cuckoo thinks there to be no next tokens for extraction.
121
+
122
+ Case 2: Longer context
123
+
124
+ ```python
125
+ 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.'''
126
+
127
+ for question in [
128
+ "What are the people mentioned here?",
129
+ "What is the job of Beethoven?",
130
+ "How famous is Beethoven?",
131
+ "When did Beethoven's middle period showed an individual development?",
132
+ ]:
133
+ text = f"User:\n\n{passage}\n\nQuestion: {question}\n\nAssistant:"
134
+ predictions = next_tokens_extraction(text)
135
+ print(question, predictions)
136
+ ```
137
+ You will get things like,
138
+ ```
139
+ What are the people mentioned here? ['Ludwig van Beethoven', 'Joseph Haydn', 'Wolfgang Amadeus Mozart']
140
+ What is the job of Beethoven? ['composer and pianist']
141
+ How famous is Beethoven? ['one of the most revered figures in the history of Western music']
142
+ When did Beethoven's middle period showed an individual development? ['1802']
143
+ ```
144
+
145
+ Case 3: Knowledge quiz
146
+
147
+ ```python
148
+ for obj in ["grass", "sea", "fire", "night"]:
149
+ text = f"User:\n\nChoices:\nred\nblue\ngreen.\n\nQuestion: What is the color of the {obj}?\n\nAssistant:\n\nAnswer:"
150
+ predictions = next_tokens_extraction(text)
151
+ print(obj, predictions)
152
+ ```
153
+ You will get things like,
154
+ ```
155
+ grass ['green']
156
+ sea ['blue']
157
+ fire ['red']
158
+ night []
159
+ ```
160
+ which shows Cuckoo is not extracting any plausible spans but has the knowledge to understand the context.
161
+
162
+ ## Few-shot Adaptation 🎯
163
+
164
+ Cuckoo 🐦 is an expert in few-shot adaptation to your own tasks, taking CoNLL2003 as an example, run ```bash run_downstream.sh conll2003.5shot KomeijiForce/Cuckoo-C4-Rainbow```, you will get a fine-tuned model in ```models/cuckoo-conll2003.5shot```. Then you can benchmark the model with the script ```python eval_conll2003.py```, which will show you an F1 performance of around 80.
165
+
166
+ You can also train the adaptation to machine reading comprehension (SQuAD), run ```bash run_downstream.sh squad.32shot KomeijiForce/Cuckoo-C4-Rainbow```, you will get a fine-tuned model in ```models/cuckoo-squad.32shot```. Then you can benchmark the model with the script ```python eval_squad.py```, which will show you an F1 performance of around 88.
167
+
168
+ For fine-tuning your own task, you need to create a Jsonlines file, each line contains {"words": [...], "ner": [...]}, For example:
169
+
170
+ ```json
171
+ {"words": ["I", "am", "John", "Smith", ".", "Person", ":"], "ner": ["O", "O", "B", "I", "O", "O", "O"]}
172
+ ```
173
+
174
+ <img src="https://github.com/user-attachments/assets/ef177466-d915-46d2-9201-5e672bb6ec23" style="width: 40%;" />
175
+
176
+ which indicates "John Smith" to be predicted as the next tokens.
177
+
178
+ You can refer to some prompts shown below for beginning:
179
+
180
+ | **Type** | **User Input** | **Assistant Response** |
181
+ |---------------------|----------------------------------------------------------------------------------------------------|----------------------------------------------------|
182
+ | Entity | **User:** [Context] Question: What is the [Label] mentioned? | **Assistant:** Answer: The [Label] is |
183
+ | Relation (Kill) | **User:** [Context] Question: Who does [Entity] kill? | **Assistant:** Answer: [Entity] kills |
184
+ | Relation (Live) | **User:** [Context] Question: Where does [Entity] live in? | **Assistant:** Answer: [Entity] lives in |
185
+ | Relation (Work) | **User:** [Context] Question: Who does [Entity] work for? | **Assistant:** Answer: [Entity] works for |
186
+ | Relation (Located) | **User:** [Context] Question: Where is [Entity] located in? | **Assistant:** Answer: [Entity] is located in |
187
+ | Relation (Based) | **User:** [Context] Question: Where is [Entity] based in? | **Assistant:** Answer: [Entity] is based in |
188
+ | Relation (Adverse) | **User:** [Context] Question: What is the adverse effect of [Entity]? | **Assistant:** Answer: The adverse effect of [Entity] is |
189
+ | Query | **User:** [Context] Question: [Question] | **Assistant:** Answer: |
190
+ | Instruction (Entity)| **User:** [Context] Question: What is the [Label] mentioned? ([Instruction]) | **Assistant:** Answer: The [Label] is |
191
+ | Instruction (Query) | **User:** [Context] Question: [Question] ([Instruction]) | **Assistant:** Answer: |
192
+
193
+ After building your own downstream dataset, save it into ```my_downstream.json```, and then run the command ```bash run_downstream.sh my_downstream KomeijiForce/Cuckoo-C4-Rainbow```. You will find an adapted Cuckoo in ```models/cuckoo-my_downstream```.
194
+
195
+ ## Fly your own Cuckoo 🪽
196
+
197
+ We include the script to transform texts to NTE instances in the file ```nte_data_collection.py```, which takes C4 as an example, the converted results can be checked in ```cuckoo.c4.example.json```. The script is designed to be easily adapted to other resources like entity, query, and questions and you can modify your own data to NTE to fly your own Cuckoo! Run the ```run_cuckoo.sh``` script to try an example pre-training.
198
+
199
+ ```bash
200
+ python run_ner.py \
201
+ --model_name_or_path roberta-large \
202
+ --train_file cuckoo.c4.example.json \
203
+ --output_dir models/cuckoo-c4-example \
204
+ --per_device_train_batch_size 4\
205
+ --gradient_accumulation_steps 16\
206
+ --num_train_epochs 1\
207
+ --save_steps 1000\
208
+ --learning_rate 0.00001\
209
+ --do_train \
210
+ --overwrite_output_dir
211
+ ```
212
+
213
+ You will get an example Cuckoo model in ```models/cuckoo-c4-example```, it might not perform well if you pre-train with too little data. You may adjust the hyperparameters inside ```nte_data_collection.py``` or modify the conversion for your own resources to enable better pre-training performance.
214
+
215
+ ## 🐾 Citation
216
+
217
+ ```
218
+ @article{DBLP:journals/corr/abs-2502-11275,
219
+ author = {Letian Peng and
220
+ Zilong Wang and
221
+ Feng Yao and
222
+ Jingbo Shang},
223
+ title = {Cuckoo: An {IE} Free Rider Hatched by Massive Nutrition in {LLM}'s Nest},
224
+ journal = {CoRR},
225
+ volume = {abs/2502.11275},
226
+ year = {2025},
227
+ url = {https://doi.org/10.48550/arXiv.2502.11275},
228
+ doi = {10.48550/arXiv.2502.11275},
229
+ eprinttype = {arXiv},
230
+ eprint = {2502.11275},
231
+ timestamp = {Mon, 17 Feb 2025 19:32:20 +0000},
232
+ biburl = {https://dblp.org/rec/journals/corr/abs-2502-11275.bib},
233
+ bibsource = {dblp computer science bibliography, https://dblp.org}
234
+ }
235
+ ```