Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

preprocess.sh 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  1. #!/bin/bash
  2. ENTITIES="NCBI-disease BC5CDR-disease BC5CDR-chem BC4CHEMD JNLPBA BC2GM linnaeus s800"
  3. MAX_LENGTH=128
  4. SCRIPT_FILE=named-entity-recognition/scripts/preprocess.py
  5. for ENTITY in $ENTITIES
  6. do
  7. echo "***** " $ENTITY " Preprocessing Start *****"
  8. DATA_DIR=datasets/NER/$ENTITY
  9. PREPROCESSED_DIR=preprocessed_datasets/NER/$ENTITY
  10. mkdir -p $PREPROCESSED_DIR
  11. # Replace tab to space
  12. cat $DATA_DIR/train.tsv | tr '\t' ' ' > $PREPROCESSED_DIR/train.txt.tmp
  13. cat $DATA_DIR/devel.tsv | tr '\t' ' ' > $PREPROCESSED_DIR/devel.txt.tmp
  14. cat $DATA_DIR/train_dev.tsv | tr '\t' ' ' > $PREPROCESSED_DIR/train_dev.txt.tmp
  15. cat $DATA_DIR/test.tsv | tr '\t' ' ' > $PREPROCESSED_DIR/test.txt.tmp
  16. echo "Replacing Done"
  17. # Preprocess for BERT-based models
  18. python $SCRIPT_FILE $PREPROCESSED_DIR/train.txt.tmp bert-base-cased $MAX_LENGTH > $PREPROCESSED_DIR/train.txt
  19. python $SCRIPT_FILE $PREPROCESSED_DIR/devel.txt.tmp bert-base-cased $MAX_LENGTH > $PREPROCESSED_DIR/devel.txt
  20. python $SCRIPT_FILE $PREPROCESSED_DIR/train_dev.txt.tmp bert-base-cased $MAX_LENGTH > $PREPROCESSED_DIR/train_dev.txt
  21. python $SCRIPT_FILE $PREPROCESSED_DIR/test.txt.tmp bert-base-cased $MAX_LENGTH > $PREPROCESSED_DIR/test.txt
  22. cat $PREPROCESSED_DIR/train.txt $PREPROCESSED_DIR/devel.txt $PREPROCESSED_DIR/test.txt | cut -d " " -f 2 | grep -v "^$"| sort | uniq > $PREPROCESSED_DIR/labels.txt
  23. echo "Removing .tmp files"
  24. rm $PREPROCESSED_DIR/*.tmp
  25. echo "***** " $ENTITY " Preprocessing Done *****"
  26. done
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...