Add pipeline tag and library name

#1
by nielsr HF Staff - opened
Files changed (1) hide show
  1. README.md +95 -10
README.md CHANGED
@@ -1,9 +1,13 @@
1
  ---
2
  license: mit
 
 
3
  ---
4
 
5
  # Cuckoo 🐦 [[Github]](https://github.com/KomeijiForce/Cuckoo)
6
 
 
 
7
  Cuckoo 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:
8
 
9
  ![cuckoo](https://github.com/user-attachments/assets/d000f275-82a7-4939-aca8-341c61a774dc)
@@ -40,9 +44,16 @@ Begin your journey with Cuckoo to experience unimaginable adaptation efficiency
40
  | └─ 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 |
41
  | 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** |
42
 
 
 
 
 
 
 
 
43
  ## Quick Experience with Cuckoo in Next Tokens Extraction ⚡
44
 
45
- We recommend using the strongest Super Rainbow Cuckoo 🦸🌈🐦🛠️ for zero-shot extraction.
46
 
47
  1️⃣ First load the model and the tokenizers
48
 
@@ -97,23 +108,23 @@ Case 1: Basic entity and relation understanding
97
  text = "Tom and Jack went to their trip in Paris."
98
 
99
  for question in [
100
- "What are the people mentioned here?",
101
  "What is the city mentioned here?",
102
  "Who goes with Tom together?",
103
  "What do Tom and Jack go to Paris for?",
104
- "Which city does George live in?",
105
  ]:
106
- text = f"User:\n\n{text}\n\nQuestion: {question}\n\nAssistant:"
107
- predictions = next_tokens_extraction(text)
108
  print(question, predictions)
109
  ```
110
  You will get things like,
111
  ```
112
- What are the people mentioned here? ['Tom', 'Jack']
113
  What is the city mentioned here? ['Paris']
114
  Who goes with Tom together? ['Jack']
115
  What do Tom and Jack go to Paris for? ['trip']
116
- Which city does George live in? []
117
  ```
118
  where [] indicates Cuckoo thinks there to be no next tokens for extraction.
119
 
@@ -143,8 +154,7 @@ When did Beethoven's middle period showed an individual development? ['1802']
143
  Case 3: Knowledge quiz
144
 
145
  ```python
146
- for obj in ["grass", "sea", "fire", "night"]:
147
- text = f"User:\n\nChoices:\nred\nblue\ngreen.\n\nQuestion: What is the color of the {obj}?\n\nAssistant:\n\nAnswer:"
148
  predictions = next_tokens_extraction(text)
149
  print(obj, predictions)
150
  ```
@@ -155,4 +165,79 @@ sea ['blue']
155
  fire ['red']
156
  night []
157
  ```
158
- which shows Cuckoo is not extracting any plausible spans but has the knowledge to understand the context.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ library_name: transformers
4
+ pipeline_tag: question-answering
5
  ---
6
 
7
  # Cuckoo 🐦 [[Github]](https://github.com/KomeijiForce/Cuckoo)
8
 
9
+ The Cuckoo family of models are extractive question answering models as described in the paper [Cuckoo: An IE Free Rider Hatched by Massive Nutrition in LLM's Nest](https://hf.co/papers/2502.11275).
10
+
11
  Cuckoo 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:
12
 
13
  ![cuckoo](https://github.com/user-attachments/assets/d000f275-82a7-4939-aca8-341c61a774dc)
 
44
  | └─ 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 |
45
  | 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** |
46
 
47
+ *(Super Rainbow Cuckoo 🦸🌈🐦🛠️ uses training sets except CoNLL2004 and ADE to boost its performance)*
48
+
49
+ | | CoNLL2003 | BioNLP2004 | MIT-Restaurant | MIT-Movie | Avg. | CoNLL2004 | ADE | Avg. | SQuAD | SQuAD-V2 | DROP | Avg. |
50
+ |----------------------|-----------|-----------|----------------|-----------|-------|-----------|-------|-------|-------|----------|-------|-------|
51
+ | Super Rainbow Cuckoo 🦸🌈🐦🛠️ | 88.38 | 68.33 | 76.79 | 69.39 | **75.22** | 72.96 | 80.06 | **76.51** | 89.54 | 74.52 | 74.89 | **79.65** |
52
+
53
+
54
  ## Quick Experience with Cuckoo in Next Tokens Extraction ⚡
55
 
56
+ We recommend using the strongest Super Rainbow Cuckoo 🦸🌈🐦🛠️ for zero-shot extraction. You can directly run the cases below in ```case_next_tokens_extraction.py```.
57
 
58
  1️⃣ First load the model and the tokenizers
59
 
 
108
  text = "Tom and Jack went to their trip in Paris."
109
 
110
  for question in [
111
+ "What is the person mentioned here?",
112
  "What is the city mentioned here?",
113
  "Who goes with Tom together?",
114
  "What do Tom and Jack go to Paris for?",
115
+ "Where does George live in?",
116
  ]:
117
+ prompt = f"User:\n\n{text}\n\nQuestion: {question}\n\nAssistant:"
118
+ predictions = next_tokens_extraction(prompt)
119
  print(question, predictions)
120
  ```
121
  You will get things like,
122
  ```
123
+ What is the person mentioned here? ['Tom', 'Jack']
124
  What is the city mentioned here? ['Paris']
125
  Who goes with Tom together? ['Jack']
126
  What do Tom and Jack go to Paris for? ['trip']
127
+ Where does George live in? []
128
  ```
129
  where [] indicates Cuckoo thinks there to be no next tokens for extraction.
130
 
 
154
  Case 3: Knowledge quiz
155
 
156
  ```python
157
+ for obj in ["grass", "sea", "fire", "night"]:\n text = f"User:\\n\\nChoices:\\nred\\nblue\\ngreen.\\n\\nQuestion: What is the color of the {obj}?\\n\\nAssistant:\\n\\nAnswer:"
 
158
  predictions = next_tokens_extraction(text)
159
  print(obj, predictions)
160
  ```
 
165
  fire ['red']
166
  night []
167
  ```
168
+ which shows Cuckoo is not extracting any plausible spans but has the knowledge to understand the context.
169
+
170
+ ## Few-shot Adaptation 🎯
171
+
172
+ 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.
173
+
174
+ 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.
175
+
176
+ For fine-tuning your own task, you need to create a Jsonlines file, each line contains {"words": [...], "ner": [...]}, For example:
177
+
178
+ ```json
179
+ {"words": ["I", "am", "John", "Smith", ".", "Person", ":"], "ner": ["O", "O", "B", "I", "O", "O", "O"]}
180
+ ```
181
+
182
+ <img src="https://github.com/user-attachments/assets/ef177466-d915-46d2-9201-5e672bb6ec23" style="width: 40%;" />
183
+
184
+ which indicates "John Smith" to be predicted as the next tokens.
185
+
186
+ You can refer to some prompts shown below for beginning:
187
+
188
+ | **Type** | **User Input** | **Assistant Response** |
189
+ |---------------------|----------------------------------------------------------------------------------------------------|----------------------------------------------------|
190
+ | Entity | **User:** [Context] Question: What is the [Label] mentioned? | **Assistant:** Answer: The [Label] is |
191
+ | Relation (Kill) | **User:** [Context] Question: Who does [Entity] kill? | **Assistant:** Answer: [Entity] kills |
192
+ | Relation (Live) | **User:** [Context] Question: Where does [Entity] live in? | **Assistant:** Answer: [Entity] lives in |
193
+ | Relation (Work) | **User:** [Context] Question: Who does [Entity] work for? | **Assistant:** Answer: [Entity] works for |
194
+ | Relation (Located) | **User:** [Context] Question: Where is [Entity] located in? | **Assistant:** Answer: [Entity] is located in |
195
+ | Relation (Based) | **User:** [Context] Question: Where is [Entity] based in? | **Assistant:** Answer: [Entity] is based in |
196
+ | Relation (Adverse) | **User:** [Context] Question: What is the adverse effect of [Entity]? | **Assistant:** Answer: The adverse effect of [Entity] is |
197
+ | Query | **User:** [Context] Question: [Question] | **Assistant:** Answer: |
198
+ | Instruction (Entity)| **User:** [Context] Question: What is the [Label] mentioned? ([Instruction]) | **Assistant:** Answer: The [Label] is |
199
+ | Instruction (Query) | **User:** [Context] Question: [Question] ([Instruction]) | **Assistant:** Answer: |
200
+
201
+ 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```.
202
+
203
+ ## Fly your own Cuckoo 🪽
204
+
205
+ 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.
206
+
207
+ ```bash
208
+ python run_ner.py \
209
+ --model_name_or_path roberta-large \
210
+ --train_file cuckoo.c4.example.json \
211
+ --output_dir models/cuckoo-c4-example \
212
+ --per_device_train_batch_size 4\
213
+ --gradient_accumulation_steps 16\
214
+ --num_train_epochs 1\
215
+ --save_steps 1000\
216
+ --learning_rate 0.00001\
217
+ --do_train \
218
+ --overwrite_output_dir
219
+ ```
220
+
221
+ 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.
222
+
223
+ ## 🐾 Citation
224
+
225
+ ```
226
+ @article{DBLP:journals/corr/abs-2502-11275,
227
+ author = {Letian Peng and
228
+ Zilong Wang and
229
+ Feng Yao and
230
+ Jingbo Shang},
231
+ title = {Cuckoo: An {IE} Free Rider Hatched by Massive Nutrition in {LLM}'s Nest},
232
+ journal = {CoRR},
233
+ volume = {abs/2502.11275},
234
+ year = {2025},
235
+ url = {https://doi.org/10.48550/arXiv.2502.11275},
236
+ doi = {10.48550/arXiv.2502.11275},
237
+ eprinttype = {arXiv},
238
+ eprint = {2502.11275},
239
+ timestamp = {Mon, 17 Feb 2025 19:32:20 +0000},
240
+ biburl = {https://dblp.org/rec/journals/corr/abs-2502-11275.bib},
241
+ bibsource = {dblp computer science bibliography, https://dblp.org}
242
+ }
243
+ ```