nielsr HF staff commited on
Commit
83a4fe6
·
verified ·
1 Parent(s): 4069038

Add pipeline tag and license

Browse files

This PR ensures the model is correctly tagged at https://huggingface.co/models?pipeline_tag=question-answering and adds the license.

Files changed (1) hide show
  1. README.md +85 -8
README.md CHANGED
@@ -1,11 +1,13 @@
1
  ---
2
  library_name: transformers
 
 
3
  tags: []
4
  ---
5
 
6
  # Cuckoo 🐦 [[Github]](https://github.com/KomeijiForce/Cuckoo)
7
 
8
- 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:
9
 
10
  ![cuckoo](https://github.com/user-attachments/assets/d000f275-82a7-4939-aca8-341c61a774dc)
11
 
@@ -98,23 +100,23 @@ Case 1: Basic entity and relation understanding
98
  text = "Tom and Jack went to their trip in Paris."
99
 
100
  for question in [
101
- "What are the people mentioned here?",
102
  "What is the city mentioned here?",
103
  "Who goes with Tom together?",
104
  "What do Tom and Jack go to Paris for?",
105
- "Which city does George live in?",
106
  ]:
107
- text = f"User:\n\n{text}\n\nQuestion: {question}\n\nAssistant:"
108
- predictions = next_tokens_extraction(text)
109
  print(question, predictions)
110
  ```
111
  You will get things like,
112
  ```
113
- What are the people mentioned here? ['Tom', 'Jack']
114
  What is the city mentioned here? ['Paris']
115
  Who goes with Tom together? ['Jack']
116
  What do Tom and Jack go to Paris for? ['trip']
117
- Which city does George live in? []
118
  ```
119
  where [] indicates Cuckoo thinks there to be no next tokens for extraction.
120
 
@@ -156,4 +158,79 @@ sea ['blue']
156
  fire ['red']
157
  night []
158
  ```
159
- which shows Cuckoo is not extracting any plausible spans but has the knowledge to understand the context.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  library_name: transformers
3
+ pipeline_tag: question-answering
4
+ license: apache-2.0
5
  tags: []
6
  ---
7
 
8
  # Cuckoo 🐦 [[Github]](https://github.com/KomeijiForce/Cuckoo)
9
 
10
+ [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:
11
 
12
  ![cuckoo](https://github.com/user-attachments/assets/d000f275-82a7-4939-aca8-341c61a774dc)
13
 
 
100
  text = "Tom and Jack went to their trip in Paris."
101
 
102
  for question in [
103
+ "What is the person mentioned here?",
104
  "What is the city mentioned here?",
105
  "Who goes with Tom together?",
106
  "What do Tom and Jack go to Paris for?",
107
+ "Where does George live in?",
108
  ]:
109
+ prompt = f"User:\n\n{text}\n\nQuestion: {question}\n\nAssistant:"
110
+ predictions = next_tokens_extraction(prompt)
111
  print(question, predictions)
112
  ```
113
  You will get things like,
114
  ```
115
+ What is the person mentioned here? ['Tom', 'Jack']
116
  What is the city mentioned here? ['Paris']
117
  Who goes with Tom together? ['Jack']
118
  What do Tom and Jack go to Paris for? ['trip']
119
+ Where does George live in? []
120
  ```
121
  where [] indicates Cuckoo thinks there to be no next tokens for extraction.
122
 
 
158
  fire ['red']
159
  night []
160
  ```
161
+ which shows Cuckoo is not extracting any plausible spans but has the knowledge to understand the context.
162
+
163
+ ## Few-shot Adaptation 🎯
164
+
165
+ 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.
166
+
167
+ 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.
168
+
169
+ For fine-tuning your own task, you need to create a Jsonlines file, each line contains {"words": [...], "ner": [...]}, For example:
170
+
171
+ ```json
172
+ {"words": ["I", "am", "John", "Smith", ".", "Person", ":"], "ner": ["O", "O", "B", "I", "O", "O", "O"]}
173
+ ```
174
+
175
+ <img src="https://github.com/user-attachments/assets/ef177466-d915-46d2-9201-5e672bb6ec23" style="width: 40%;" />
176
+
177
+ which indicates "John Smith" to be predicted as the next tokens.
178
+
179
+ You can refer to some prompts shown below for beginning:
180
+
181
+ | **Type** | **User Input** | **Assistant Response** |
182
+ |---------------------|----------------------------------------------------------------------------------------------------|----------------------------------------------------|
183
+ | Entity | **User:** [Context] Question: What is the [Label] mentioned? | **Assistant:** Answer: The [Label] is |
184
+ | Relation (Kill) | **User:** [Context] Question: Who does [Entity] kill? | **Assistant:** Answer: [Entity] kills |
185
+ | Relation (Live) | **User:** [Context] Question: Where does [Entity] live in? | **Assistant:** Answer: [Entity] lives in |
186
+ | Relation (Work) | **User:** [Context] Question: Who does [Entity] work for? | **Assistant:** Answer: [Entity] works for |
187
+ | Relation (Located) | **User:** [Context] Question: Where is [Entity] located in? | **Assistant:** Answer: [Entity] is located in |
188
+ | Relation (Based) | **User:** [Context] Question: Where is [Entity] based in? | **Assistant:** Answer: [Entity] is based in |
189
+ | Relation (Adverse) | **User:** [Context] Question: What is the adverse effect of [Entity]? | **Assistant:** Answer: The adverse effect of [Entity] is |
190
+ | Query | **User:** [Context] Question: [Question] | **Assistant:** Answer: |
191
+ | Instruction (Entity)| **User:** [Context] Question: What is the [Label] mentioned? ([Instruction]) | **Assistant:** Answer: The [Label] is |
192
+ | Instruction (Query) | **User:** [Context] Question: [Question] ([Instruction]) | **Assistant:** Answer: |
193
+
194
+ 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```.
195
+
196
+ ## Fly your own Cuckoo 🪽
197
+
198
+ 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.
199
+
200
+ ```bash
201
+ python run_ner.py \
202
+ --model_name_or_path roberta-large \
203
+ --train_file cuckoo.c4.example.json \
204
+ --output_dir models/cuckoo-c4-example \
205
+ --per_device_train_batch_size 4\
206
+ --gradient_accumulation_steps 16\
207
+ --num_train_epochs 1\
208
+ --save_steps 1000\
209
+ --learning_rate 0.00001\
210
+ --do_train \
211
+ --overwrite_output_dir
212
+ ```
213
+
214
+ 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.
215
+
216
+ ## 🐾 Citation
217
+
218
+ ```
219
+ @article{DBLP:journals/corr/abs-2502-11275,
220
+ author = {Letian Peng and
221
+ Zilong Wang and
222
+ Feng Yao and
223
+ Jingbo Shang},
224
+ title = {Cuckoo: An {IE} Free Rider Hatched by Massive Nutrition in {LLM}'s Nest},
225
+ journal = {CoRR},
226
+ volume = {abs/2502.11275},
227
+ year = {2025},
228
+ url = {https://doi.org/10.48550/arXiv.2502.11275},
229
+ doi = {10.48550/arXiv.2502.11275},
230
+ eprinttype = {arXiv},
231
+ eprint = {2502.11275},
232
+ timestamp = {Mon, 17 Feb 2025 19:32:20 +0000},
233
+ biburl = {https://dblp.org/rec/journals/corr/abs-2502-11275.bib},
234
+ bibsource = {dblp computer science bibliography, https://dblp.org}
235
+ }
236
+ ```