├── .gitignore
├── bin
└── cr
│ ├── Event.class
│ ├── Note.class
│ ├── Song.class
│ ├── Span.class
│ ├── CRMain.class
│ ├── SongUtil.class
│ ├── SpanLabel.class
│ ├── WordLabel.class
│ ├── IFeatureType.class
│ ├── SongEvaluator.class
│ ├── SongNetwork.class
│ ├── CRMain$Simplify.class
│ ├── SongEvaluator$Statistics.class
│ ├── WordWeakSemiCRFFeatureManager.class
│ ├── WordWeakSemiCRFNetworkCompiler.class
│ ├── WordWeakSemiCRFFeatureManager$Argument.class
│ ├── WordWeakSemiCRFFeatureManager$Weight.class
│ ├── WordWeakSemiCRFNetworkCompiler$NodeType.class
│ └── WordWeakSemiCRFFeatureManager$FeatureType.class
├── lib
├── xom-1.2.10.jar
├── commons-lang3-3.5.jar
└── statnlp-core-2015.1-SNAPSHOT.jar
├── sample_output_files
├── Tue Jul 31 13:56:06 EDT 2018 Fold 1.model
├── Tue Jul 31 13:56:06 EDT 2018 Fold 1.model.txt
├── feature_count2.txt
├── feature_count9.txt
└── feature_count6.txt
├── src
└── cr
│ ├── IFeatureType.java
│ ├── SongNetwork.java
│ ├── SpanLabel.java
│ ├── Event.java
│ ├── WordLabel.java
│ ├── Note.java
│ ├── Span.java
│ ├── Song.java
│ ├── WordWeakSemiCRFNetworkCompiler.java
│ ├── SongEvaluator.java
│ ├── SongUtil.java
│ └── CRMain.java
├── folds
├── test1.txt
├── test10.txt
├── test2.txt
├── test3.txt
├── test4.txt
├── test5.txt
├── test6.txt
├── test7.txt
├── test8.txt
├── test9.txt
├── train1.txt
├── train10.txt
├── train2.txt
├── train3.txt
├── train4.txt
├── train5.txt
├── train6.txt
├── train7.txt
├── train8.txt
└── train9.txt
├── fold_gen
├── all_songs.txt
└── fold_gen.py
├── bach_dataset_chords.txt
├── run-folds.sh
├── README.md
└── musicxml_parser
└── musicxml_parser.py
/.gitignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 |
--------------------------------------------------------------------------------
/bin/cr/Event.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/Event.class
--------------------------------------------------------------------------------
/bin/cr/Note.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/Note.class
--------------------------------------------------------------------------------
/bin/cr/Song.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/Song.class
--------------------------------------------------------------------------------
/bin/cr/Span.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/Span.class
--------------------------------------------------------------------------------
/lib/xom-1.2.10.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/lib/xom-1.2.10.jar
--------------------------------------------------------------------------------
/bin/cr/CRMain.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/CRMain.class
--------------------------------------------------------------------------------
/bin/cr/SongUtil.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/SongUtil.class
--------------------------------------------------------------------------------
/bin/cr/SpanLabel.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/SpanLabel.class
--------------------------------------------------------------------------------
/bin/cr/WordLabel.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/WordLabel.class
--------------------------------------------------------------------------------
/bin/cr/IFeatureType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/IFeatureType.class
--------------------------------------------------------------------------------
/bin/cr/SongEvaluator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/SongEvaluator.class
--------------------------------------------------------------------------------
/bin/cr/SongNetwork.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/SongNetwork.class
--------------------------------------------------------------------------------
/lib/commons-lang3-3.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/lib/commons-lang3-3.5.jar
--------------------------------------------------------------------------------
/bin/cr/CRMain$Simplify.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/CRMain$Simplify.class
--------------------------------------------------------------------------------
/lib/statnlp-core-2015.1-SNAPSHOT.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/lib/statnlp-core-2015.1-SNAPSHOT.jar
--------------------------------------------------------------------------------
/bin/cr/SongEvaluator$Statistics.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/SongEvaluator$Statistics.class
--------------------------------------------------------------------------------
/bin/cr/WordWeakSemiCRFFeatureManager.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/WordWeakSemiCRFFeatureManager.class
--------------------------------------------------------------------------------
/bin/cr/WordWeakSemiCRFNetworkCompiler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/WordWeakSemiCRFNetworkCompiler.class
--------------------------------------------------------------------------------
/bin/cr/WordWeakSemiCRFFeatureManager$Argument.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/WordWeakSemiCRFFeatureManager$Argument.class
--------------------------------------------------------------------------------
/bin/cr/WordWeakSemiCRFFeatureManager$Weight.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/WordWeakSemiCRFFeatureManager$Weight.class
--------------------------------------------------------------------------------
/bin/cr/WordWeakSemiCRFNetworkCompiler$NodeType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/WordWeakSemiCRFNetworkCompiler$NodeType.class
--------------------------------------------------------------------------------
/bin/cr/WordWeakSemiCRFFeatureManager$FeatureType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/bin/cr/WordWeakSemiCRFFeatureManager$FeatureType.class
--------------------------------------------------------------------------------
/sample_output_files/Tue Jul 31 13:56:06 EDT 2018 Fold 1.model:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kristenmasada/chord_recognition_semi_crf/HEAD/sample_output_files/Tue Jul 31 13:56:06 EDT 2018 Fold 1.model
--------------------------------------------------------------------------------
/src/cr/IFeatureType.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | /**
4 | * Interface to FeatureType in FeatureManager
5 | * Each feature can be disabled/enabled
6 | * @author Aldrian Obaja
7 | *
8 | */
9 |
10 | public interface IFeatureType {
11 | public void enable();
12 | public void disable();
13 | public boolean enabled();
14 | }
15 |
--------------------------------------------------------------------------------
/folds/test1.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003306b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/013705channotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/002806b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/005708b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003109b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/001606b_annotated_events.xml
7 |
--------------------------------------------------------------------------------
/folds/test10.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003608b2annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/003907b_annotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/000206b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/014806bvannotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/014403b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/013906b_annotated_events.xml
7 |
--------------------------------------------------------------------------------
/folds/test2.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/014608b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/000408b_annotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/014406b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/012306b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/000707b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/015403b_annotated_events.xml
7 |
--------------------------------------------------------------------------------
/folds/test3.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003006b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/015305b_annotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/002908channotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/014505b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003806b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/000907b_annotated_events.xml
7 |
--------------------------------------------------------------------------------
/folds/test4.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003907bvannotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/001207b_annotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/000507b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/001805b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/004006b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/015309b_annotated_events.xml
7 |
--------------------------------------------------------------------------------
/folds/test5.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/002506b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/001306b_annotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/004008b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/015505b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/014007b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/000306b_annotated_events.xml
7 |
--------------------------------------------------------------------------------
/folds/test6.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/015105b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/012206b_annotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/015301b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/001907channotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/014500baannotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/012106b_annotated_events.xml
7 |
--------------------------------------------------------------------------------
/folds/test7.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/000106b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/012606bvannotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/015408b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/012705b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/012506b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/001707b_annotated_events.xml
7 |
--------------------------------------------------------------------------------
/folds/test8.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/012406b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/012606b_annotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/013506b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/012805b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/012006b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/000606b_annotated_events.xml
7 |
--------------------------------------------------------------------------------
/folds/test9.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/001106b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/002406bsannotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/014806b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/001007b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003206b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/014505bvannotated_events.xml
7 |
--------------------------------------------------------------------------------
/fold_gen/all_songs.txt:
--------------------------------------------------------------------------------
1 | 003306b_
2 | 013705ch
3 | 002806b_
4 | 005708b_
5 | 003109b_
6 | 001606b_
7 | 014608b_
8 | 000408b_
9 | 014406b_
10 | 012306b_
11 | 000707b_
12 | 015403b_
13 | 003006b_
14 | 015305b_
15 | 002908ch
16 | 014505b_
17 | 003806b_
18 | 000907b_
19 | 003907bv
20 | 001207b_
21 | 000507b_
22 | 001805b_
23 | 004006b_
24 | 015309b_
25 | 002506b_
26 | 001306b_
27 | 004008b_
28 | 015505b_
29 | 014007b_
30 | 000306b_
31 | 015105b_
32 | 012206b_
33 | 015301b_
34 | 001907ch
35 | 014500ba
36 | 012106b_
37 | 000106b_
38 | 012606bv
39 | 015408b_
40 | 012705b_
41 | 012506b_
42 | 001707b_
43 | 012406b_
44 | 012606b_
45 | 013506b_
46 | 012805b_
47 | 012006b_
48 | 000606b_
49 | 001106b_
50 | 002406bs
51 | 014806b_
52 | 001007b_
53 | 003206b_
54 | 014505bv
55 | 003608b2
56 | 003907b_
57 | 000206b_
58 | 014806bv
59 | 014403b_
60 | 013906b_
--------------------------------------------------------------------------------
/bach_dataset_chords.txt:
--------------------------------------------------------------------------------
1 | Bb:maj7
2 | F:maj7
3 | F:maj6
4 | Bb:min6
5 | F:maj4
6 | F#:min
7 | F:min7
8 | F:min6
9 | E:maj4
10 | C#:dim
11 | Eb:maj7
12 | E:maj7
13 | E:min7
14 | Bb:min
15 | G:min
16 | E:min6
17 | Bb:maj
18 | B:maj
19 | F:dim
20 | B:min
21 | G#:min
22 | D#:min
23 | Eb:maj
24 | G:maj
25 | D#:dim6
26 | D#:dim7
27 | C:dim6
28 | F:dim7
29 | A:maj
30 | C:dim7
31 | A:min
32 | Gb:maj7
33 | Db:maj7
34 | E:dim
35 | Db:maj4
36 | C#:min7
37 | C:maj7
38 | C:min6
39 | Gb:maj4
40 | C:min7
41 | C#:min
42 | D:min
43 | E:maj
44 | C:maj4
45 | D:dim7
46 | Bb:dim
47 | C:maj6
48 | G:dim
49 | B:maj4
50 | C:maj
51 | F:maj
52 | F#:dim
53 | C:min
54 | B:min6
55 | B:min7
56 | G#:dim7
57 | B:maj7
58 | A:dim
59 | F#:dim7
60 | B:dim7
61 | F:min
62 | B:dim
63 | Db:maj
64 | F#:min7
65 | Ab:maj
66 | A:min7
67 | C#:dim7
68 | A:min6
69 | F#:min6
70 | C#:dim6
71 | G:min7
72 | D:min6
73 | A:min4
74 | D:min7
75 | E:min
76 | A:maj7
77 | A:maj6
78 | G:maj7
79 | A:maj4
80 | D:maj4
81 | D:maj
82 | D:maj7
83 | G:min6
84 | G#:dim
85 | D:maj6
86 | G:maj4
87 | Gb:maj
88 | D#:dim
89 | Bb:dim7
90 | G:maj6
--------------------------------------------------------------------------------
/src/cr/SongNetwork.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | import com.statnlp.commons.types.Instance;
4 | import com.statnlp.hybridnetworks.LocalNetworkParam;
5 | import com.statnlp.hybridnetworks.TableLookupNetwork;
6 |
7 | /**
8 | * The data structure to represent SMS messages with their annotations as networks/graphs
9 | * A network represents the model view of the problem.
10 | * Compare with {@link SMSNPInstance}, which is the real-world view of the problem
11 | * This is based on StatNLP framework for CRF on acyclic graphs
12 | * @author Aldrian Obaja
13 | *
14 | */
15 | public class SongNetwork extends TableLookupNetwork {
16 |
17 | private static final long serialVersionUID = -8384557055081197941L;
18 | public int numNodes = -1;
19 |
20 | public SongNetwork() {}
21 |
22 | public SongNetwork(int networkId, Instance inst, LocalNetworkParam param) {
23 | super(networkId, inst, param);
24 | }
25 |
26 | public SongNetwork(int networkId, Instance inst, long[] nodes, int[][][] children, LocalNetworkParam param, int numNodes) {
27 | super(networkId, inst, nodes, children, param);
28 | this.numNodes = numNodes;
29 | }
30 |
31 | public int countNodes(){
32 | if(numNodes < 0){
33 | return super.countNodes();
34 | }
35 | return numNodes;
36 | }
37 |
38 | public void remove(int k){}
39 |
40 | public boolean isRemoved(int k){
41 | return false;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/fold_gen/fold_gen.py:
--------------------------------------------------------------------------------
1 | # creates 10 folds for training/testing from 60 Bach chorales
2 |
3 | import sys
4 |
5 | # open file with names of Bach chorale files
6 | file = 'all_songs.txt' # our folds = "our_folds/all_songs.txt"
7 | # their folds = "breve_folds/all_songs.txt"
8 | folds_folder = '../folds' # output folder for folds (e.g. 'our_folds', 'breve_folds')
9 | datapath = sys.argv[1] # datapath to ChordRecognition repo
10 | # datapath = '/Users/kristenmasada/Documents/ChordRecognition/source/masada/fold_gen/'
11 | with open(file, 'r') as chorales:
12 | chorale_names = chorales.read().splitlines()
13 | chorale_names = [c + "annotated_events.xml" for c in chorale_names]
14 |
15 | # create 10 folds
16 | for i in range(0, 60, 6):
17 |
18 | # create training file
19 | with open(folds_folder + '/train' + str(int((i / 6) + 1)) + '.txt', 'w') as training_fold:
20 | for chorale_name in (chorale_names[0:i] + chorale_names[i+6:60]):
21 | chorale_name_with_path = datapath + 'bach/' + chorale_name
22 | training_fold.write("%s\n" % chorale_name_with_path)
23 |
24 | # create testing file
25 | with open(folds_folder + '/test' + str(int((i / 6) + 1)) + '.txt', 'w') as testing_fold:
26 | for chorale_name in chorale_names[i:i+6]:
27 | chorale_name_with_path = datapath + 'bach/' + chorale_name
28 | testing_fold.write("%s\n" % chorale_name_with_path)
29 |
--------------------------------------------------------------------------------
/run-folds.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # first argument - number of folds
4 | # second argument - number of folds per iteration
5 | # third argument - starting fold
6 | # fourth argument - chords path
7 |
8 | JAVA=java
9 | CLASSPATH=bin:lib/statnlp-core-2015.1-SNAPSHOT.jar:lib/xom-1.2.10.jar:lib/commons-lang3-3.5.jar
10 | CURRENTDIRECTORYPATH=${PWD##*/}/
11 | FOLDSPATH=folds/
12 | STARTINGFOLD=$1
13 | NUMFOLDS=$2
14 | NUMFOLDSPERIT=$3
15 | CHORDSPATH=$4
16 |
17 | # count features
18 | for fold in $(seq $STARTINGFOLD $NUMFOLDS);
19 | do
20 | echo $fold
21 | nice $JAVA -Xmx250000m -classpath $CLASSPATH cr.CRMain -currentDirectoryPath $CURRENTDIRECTORYPATH -foldsPath $FOLDSPATH -foldNum $fold -simplify generic_added_notes -writeModelText -normalizeEnharmonics -countFeatures -useAllChords -useAllChordsPath $CHORDSPATH &> output-c-${fold}.txt
22 | done
23 |
24 | # run folds
25 | for fold in $(seq $STARTINGFOLD $NUMFOLDS);
26 | do
27 | echo "Started fold $fold"
28 | nice $JAVA -Xmx250000m -classpath $CLASSPATH cr.CRMain -currentDirectoryPath $CURRENTDIRECTORYPATH -foldsPath $FOLDSPATH -foldNum $fold -simplify generic_added_notes -writeModelText -normalizeEnharmonics -useAllChords -useAllChordsPath $CHORDSPATH &> output-e-${fold}.txt &
29 | echo "$fold % $NUMFOLDSPERIT" | bc
30 | if [ `echo "$fold % $NUMFOLDSPERIT" | bc` -eq 0 ]
31 | then
32 | wait
33 | echo "Fold set finished"
34 | fi
35 | done
36 |
37 | echo "$NUMFOLDS % $NUMFOLDSPERIT" | bc
38 | if [ `echo "$NUMFOLDS % $NUMFOLDSPERIT" | bc` -ne 0 ]
39 | then
40 | wait
41 | echo "Fold set finished"
42 | fi
43 |
44 | exit 0
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/cr/SpanLabel.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | import java.io.Serializable;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 |
7 | public class SpanLabel implements Comparable, Serializable {
8 |
9 | private static final long serialVersionUID = -4455671752828268868L;
10 | // private static final long serialVersionUID = -2821034438335023157L; ?
11 | public static final Map LABELS = new HashMap();
12 | public static final Map LABELS_INDEX = new HashMap();
13 |
14 | public static SpanLabel get(String form){
15 | if(!LABELS.containsKey(form)){
16 | SpanLabel label = new SpanLabel(form, LABELS.size());
17 | LABELS.put(form, label);
18 | LABELS_INDEX.put(label.id, label);
19 | }
20 | return LABELS.get(form);
21 | }
22 |
23 | public static SpanLabel get(int id){
24 | return LABELS_INDEX.get(id);
25 | }
26 |
27 | public String form;
28 | public int id;
29 |
30 | private SpanLabel(String form, int id) {
31 | this.form = form;
32 | this.id = id;
33 | }
34 |
35 | @Override
36 | public int hashCode() {
37 | return form.hashCode();
38 | }
39 |
40 | @Override
41 | public boolean equals(Object obj) {
42 | if (this == obj)
43 | return true;
44 | if (obj == null)
45 | return false;
46 | if (!(obj instanceof SpanLabel))
47 | return false;
48 | SpanLabel other = (SpanLabel) obj;
49 | if (form == null) {
50 | if (other.form != null)
51 | return false;
52 | } else if (!form.equals(other.form))
53 | return false;
54 | return true;
55 | }
56 |
57 | public String toString(){
58 | return String.format("%s (id: %d)", form, id);
59 | }
60 |
61 | @Override
62 | public int compareTo(SpanLabel o) {
63 | return Integer.compare(id, o.id);
64 | }
65 |
66 | public static int compare(SpanLabel o1, SpanLabel o2){
67 | if(o1 == null){
68 | if(o2 == null) return 0;
69 | else return -1;
70 | } else {
71 | if(o2 == null) return 1;
72 | else return o1.compareTo(o2);
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/cr/Event.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import nu.xom.Element;
7 | import nu.xom.Elements;
8 |
9 | public class Event {
10 |
11 | // Should I include a serialVersionUID?
12 |
13 | public double onset; // onset of event (measured in quarter length)
14 | public double duration; // duration of event (measured in quarter length)
15 | public int measureNumber; // number of measure that event occurs in
16 | public double accent; // accent of event (based on Music21's beatStrength() method)
17 | public List notes; // list of notes within event
18 |
19 | public Event() {
20 | notes = new ArrayList();
21 | }
22 |
23 | public Event(double onset, double duration, int measureNumber, double accent, List notes) {
24 | this.onset = onset;
25 | this.duration = duration;
26 | this.measureNumber = measureNumber;
27 | this.accent = accent;
28 | this.notes = notes;
29 | }
30 |
31 | public static Event parseXML(Element element, Event previousEvent) {
32 | Event event = new Event();
33 |
34 | event.onset = Double.parseDouble(element.getFirstChildElement("onset").getValue());
35 | event.duration = Double.parseDouble(element.getFirstChildElement("duration").getValue());
36 | event.measureNumber = Integer.parseInt(element.getFirstChildElement("measureNumber").getValue());
37 | event.accent = Double.parseDouble(element.getFirstChildElement("accent").getValue());
38 |
39 | Elements notes = element.getFirstChildElement("notes").getChildElements();
40 | for (int i = 0; i < notes.size(); i++) {
41 | event.notes.add(Note.parseXML(notes.get(i), previousEvent));
42 | }
43 |
44 | // System.out.println(event.toString());
45 |
46 | return event;
47 | }
48 |
49 | public String toString() {
50 | String text = new String("Event:\n"
51 | + "- Onset: " + this.onset + "\n"
52 | + "- Duration: " + this.duration + "\n"
53 | + "- Measure Number: " + this.measureNumber + "\n"
54 | + "- Accent: " + this.accent + "\n"
55 | + "- Notes:\n");
56 | for (Note note : notes) {
57 | text += note.toString();
58 | }
59 | return text;
60 | }
61 | }
--------------------------------------------------------------------------------
/src/cr/WordLabel.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | import java.io.Serializable;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 |
7 | /**
8 | * The class representing a label for a word/token
9 | * This class stores singleton objects, which can be retrieved by its ID or name.
10 | * @author Aldrian Obaja
11 | *
12 | */
13 | public class WordLabel implements Comparable, Serializable{
14 |
15 | private static final long serialVersionUID = 3941855494601533166L;
16 | public static final Map LABELS = new HashMap();
17 | public static final Map LABELS_INDEX = new HashMap();
18 |
19 | public static WordLabel get(String form){
20 | if(!LABELS.containsKey(form)){
21 | WordLabel label = new WordLabel(form, LABELS.size());
22 | LABELS.put(form, label);
23 | LABELS_INDEX.put(label.id, label);
24 | }
25 | return LABELS.get(form);
26 | }
27 |
28 | public static WordLabel get(int id){
29 | return LABELS_INDEX.get(id);
30 | }
31 |
32 | public String form;
33 | public int id;
34 |
35 | private WordLabel(String form, int id) {
36 | this.form = form;
37 | this.id = id;
38 | }
39 |
40 | @Override
41 | public int hashCode() {
42 | return form.hashCode();
43 | }
44 |
45 | @Override
46 | public boolean equals(Object obj) {
47 | if (this == obj)
48 | return true;
49 | if (obj == null)
50 | return false;
51 | if (!(obj instanceof WordLabel))
52 | return false;
53 | WordLabel other = (WordLabel) obj;
54 | if (form == null) {
55 | if (other.form != null)
56 | return false;
57 | } else if (!form.equals(other.form))
58 | return false;
59 | return true;
60 | }
61 |
62 | public String toString(){
63 | return String.format("%s (id: %d)", form, id);
64 | }
65 |
66 | @Override
67 | public int compareTo(WordLabel o) {
68 | return Integer.compare(id, o.id);
69 | }
70 |
71 | public static int compare(WordLabel o1, WordLabel o2){
72 | if(o1 == null){
73 | if(o2 == null) return 0;
74 | else return -1;
75 | } else {
76 | if(o2 == null) return 1;
77 | else return o1.compareTo(o2);
78 | }
79 | }
80 | }
81 |
82 |
--------------------------------------------------------------------------------
/src/cr/Note.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | import nu.xom.Element;
4 |
5 | public class Note {
6 |
7 | // Should I include a serialVersionUID?
8 |
9 | public String pitch;
10 | public double duration;
11 | public boolean fromPrevious;
12 | public double accent; // accent of event (based on Music21's beatStrength() method)
13 | public double onset;
14 |
15 | public Note() {
16 | pitch = "";
17 | }
18 |
19 | public Note(Note oldNote) {
20 | this.pitch = oldNote.pitch;
21 | this.duration = oldNote.duration;
22 | this.fromPrevious = oldNote.fromPrevious;
23 | this.accent = oldNote.accent;
24 | this.onset = oldNote.onset;
25 | }
26 |
27 | public Note(String pitch, double duration, Boolean fromPrevious, double accent, double onset) {
28 | this.pitch = pitch;
29 | this.duration = duration;
30 | this.fromPrevious = fromPrevious;
31 | this.accent = accent;
32 | this.onset = onset;
33 | }
34 |
35 | public static Note parseXML(Element element, Event previousEvent) {
36 | Note note = new Note();
37 |
38 | note.pitch = element.getFirstChildElement("pitch").getValue();
39 | note.duration = Double.parseDouble(element.getFirstChildElement("duration").getValue());
40 | note.fromPrevious = element.getFirstChildElement("fromPrevious").getValue().equals("True") ? true : false;
41 | note.accent = Double.parseDouble(element.getFirstChildElement("accent").getValue());
42 | if(!note.fromPrevious) {
43 | note.onset = Double.parseDouble(element.getFirstChildElement("onset").getValue());
44 | }
45 | else {
46 | for(Note previousNote : previousEvent.notes) {
47 | if(note.pitch.equals(previousNote.pitch)) {
48 | note.onset = previousNote.onset;
49 | }
50 | }
51 | }
52 | return note;
53 | }
54 |
55 | private static boolean doubleEquals(double num1, double num2) {
56 | double epsilon = 0.0000001d;
57 | return (Math.abs(num1 - num2) < epsilon);
58 | }
59 |
60 | @Override
61 | public boolean equals(Object note) {
62 | if(note == null) {
63 | return false;
64 | }
65 | else if(getClass() != note.getClass()) {
66 | return false;
67 | }
68 | final Note compNote = (Note) note;
69 | if((pitch == compNote.pitch) && doubleEquals(duration, compNote.duration) && (fromPrevious == compNote.fromPrevious) && doubleEquals(accent, compNote.accent) && doubleEquals(onset, compNote.onset)) {
70 | return true;
71 | }
72 | return false;
73 | }
74 |
75 | public String toString() {
76 | return new String("-- Note:\n"
77 | + "--- Pitch: " + this.pitch + "\n"
78 | + "--- Duration: " + this.duration + "\n"
79 | + "--- From Previous: " + this.fromPrevious + "\n"
80 | + "--- Accent: " + this.accent + "\n"
81 | + "--- Onset: " + this.onset + "\n"
82 | + "");
83 | }
84 | }
--------------------------------------------------------------------------------
/src/cr/Span.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | import java.io.IOException;
4 | import java.io.Serializable;
5 |
6 | import cr.CRMain.Simplify;
7 | import static cr.SongUtil.simplifyLabel;
8 | import static cr.SongUtil.normalizeEnharmonicChords;
9 | import nu.xom.Element;
10 |
11 | public class Span implements Comparable, Serializable{
12 |
13 | // private static final long serialVersionUID = 1849557517361796614L; ?!
14 | public SpanLabel label;
15 | public double onset;
16 | public double offset;
17 | public int start;
18 | public int stop;
19 |
20 | public Span() {
21 |
22 | }
23 |
24 | public Span(double onset, double offset, int start, int stop, SpanLabel label) {
25 | this.onset = onset;
26 | this.offset = offset;
27 | this.start = start;
28 | this.stop = stop;
29 | this.label = label;
30 | }
31 |
32 | public static Span parseXML(Element element, Simplify simplification, boolean normalizeEnharmonics) throws IOException {
33 | Span span = new Span();
34 |
35 | span.label = SpanLabel.get(normalizeEnharmonicChords(simplifyLabel(element.getFirstChildElement("chordLabel").getValue().trim(), simplification), normalizeEnharmonics));
36 | span.onset = Double.parseDouble(element.getFirstChildElement("onset").getValue());
37 | span.offset = Double.parseDouble(element.getFirstChildElement("offset").getValue());
38 | span.start = Integer.parseInt(element.getFirstChildElement("eventStart").getValue());
39 | span.stop = Integer.parseInt(element.getFirstChildElement("eventStop").getValue());
40 |
41 | // System.out.println(span.toString());
42 |
43 | return span;
44 | }
45 |
46 | public boolean equals(Object o){
47 | if(o instanceof Span){
48 | Span s = (Span)o;
49 | // if(onset != s.onset) return false;
50 | // if(offset != s.offset) return false;
51 | if(start != s.start) return false;
52 | if(stop != s.stop) return false;
53 | return label.equals(s.label);
54 | }
55 | return false;
56 | }
57 |
58 | @Override
59 | public int compareTo(Span o) {
60 | if(onset < o.onset) return -1;
61 | if(onset > o.onset) return 1;
62 | if(offset < o.onset) return -1;
63 | if(offset > o.offset) return 1;
64 | if (start < o.start) return -1;
65 | if (stop > o.stop) return 1;
66 | if(label == null){
67 | if(o.label == null){
68 | return 0;
69 | }
70 | return -1;
71 | } else {
72 | if(o.label == null){
73 | return 1;
74 | }
75 | return label.compareTo(o.label);
76 | }
77 | }
78 |
79 | public String toString(){
80 | String text = new String("Segment:\n"
81 | + "- Label: " + this.label.toString() + "\n"
82 | + "- Onset: " + this.onset + "\n"
83 | + "- Offset: " + this.offset + "\n"
84 | + "- Event Start: " + this.start + "\n"
85 | + "- Event Stop: " + this.stop + "\n");
86 | return text;
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ChordRecognition
2 | #### Kristen Masada and Razvan Bunescu
3 |
4 | This repository contains code for our semi-CRF system detailed in "[Chord Recognition in Symbolic Music using semi-Markov Conditional Random Fields](https://kristenmasada.github.io/publications/ismir17/ismir17.pdf)". The code here can be used to run semi-CRF on the BaCh dataset using [Radicioni and Esposito](https://pdfs.semanticscholar.org/3fe9/2031e8093b00b4b39ed0fc2bdb323b8dffb6.pdf)'s original 10 folds.
5 |
6 | # Instructions:
7 | 1. Generate fold files for your machine: `rm folds/*`, `cd fold_gen`, then `python3 fold_gen.py ` (for example, `python3 fold_gen.py /home/km942412/ChordRecognition/`).
8 | 2. Run folds: `cd ..`, then `./run-folds.sh breve_chords_in_dataset.txt &`. For example, if I want to run folds 1 through 10, with 3 folds running at a time, using all of the chords that appear in the BaCh dataset as possible labels, `./run-folds.sh 1 10 3 bach_dataset_chords.txt > run_folds_output.txt &`. This will generate feature_count files (which contain the name of each feature and a count of how many times it appears in the training data), output-c files (initial output files generated when counting the number of features in the training data), and output-e files (the output files that will contain the test results for each fold). It will also generate model.txt files (which contain the weights learned for each feature), .model files (the saved model trained on a given fold set), and .log files (which contain general output information similar to the output-e files). The feature_count, output-c, and output-e files generated by running BaCh on the fold set given in `folds/` are provided in `sample_output_files/`. A sample model.txt file, .model file, and .log file is also provided for one fold.
9 | NOTE: Our system can require a decent amount of memory per fold. We originally ran our experiments on a computer with 250GB of memory, which allowed us to run three folds at once using the fold set provided.
10 |
11 |
12 | # Running the system on another dataset:
13 | * You will need to convert musicXML files to our XML format to use them with our system. We created a script to do this, which I have included in `musicxml_parser/`. You will need to install [LXML](http://lxml.de/installation.html) and [music21](http://web.mit.edu/music21/doc/installing/index.html) to use it. After installing both of these, `cd musicxml_parser` and run `python3 musicxml_parser.py `. The converted song will appear in the same location as the original XML file inputted to the script.
14 | * Make sure to change the capacity size of the network graph in WordWeakSemiCRFNetworkCompiler.java on line 39, as this graph is affected by the length of the training songs. I usually determine this number by trial and error. The size that it is set to right now works well for most songs of medium length.
15 | * If the system is running too slowly, this might be caused by the semi-CRF using a maximum segment length that is too long. Try making maxSegmentLength a smaller number (line 87 of CRMain.java).
16 | * Also make sure that the labels in your dataset use the same kind of labels mentioned in our paper (3 possible modes, 4 possible added notes, and 12 possible root notes). Our system can be modified to use other chord labels, but this will also affect how the features are encoded.
17 |
--------------------------------------------------------------------------------
/folds/train1.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/014608b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/000408b_annotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/014406b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/012306b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/000707b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/015403b_annotated_events.xml
7 | /home/razvan/bunescu/ChordRecognition/bach/003006b_annotated_events.xml
8 | /home/razvan/bunescu/ChordRecognition/bach/015305b_annotated_events.xml
9 | /home/razvan/bunescu/ChordRecognition/bach/002908channotated_events.xml
10 | /home/razvan/bunescu/ChordRecognition/bach/014505b_annotated_events.xml
11 | /home/razvan/bunescu/ChordRecognition/bach/003806b_annotated_events.xml
12 | /home/razvan/bunescu/ChordRecognition/bach/000907b_annotated_events.xml
13 | /home/razvan/bunescu/ChordRecognition/bach/003907bvannotated_events.xml
14 | /home/razvan/bunescu/ChordRecognition/bach/001207b_annotated_events.xml
15 | /home/razvan/bunescu/ChordRecognition/bach/000507b_annotated_events.xml
16 | /home/razvan/bunescu/ChordRecognition/bach/001805b_annotated_events.xml
17 | /home/razvan/bunescu/ChordRecognition/bach/004006b_annotated_events.xml
18 | /home/razvan/bunescu/ChordRecognition/bach/015309b_annotated_events.xml
19 | /home/razvan/bunescu/ChordRecognition/bach/002506b_annotated_events.xml
20 | /home/razvan/bunescu/ChordRecognition/bach/001306b_annotated_events.xml
21 | /home/razvan/bunescu/ChordRecognition/bach/004008b_annotated_events.xml
22 | /home/razvan/bunescu/ChordRecognition/bach/015505b_annotated_events.xml
23 | /home/razvan/bunescu/ChordRecognition/bach/014007b_annotated_events.xml
24 | /home/razvan/bunescu/ChordRecognition/bach/000306b_annotated_events.xml
25 | /home/razvan/bunescu/ChordRecognition/bach/015105b_annotated_events.xml
26 | /home/razvan/bunescu/ChordRecognition/bach/012206b_annotated_events.xml
27 | /home/razvan/bunescu/ChordRecognition/bach/015301b_annotated_events.xml
28 | /home/razvan/bunescu/ChordRecognition/bach/001907channotated_events.xml
29 | /home/razvan/bunescu/ChordRecognition/bach/014500baannotated_events.xml
30 | /home/razvan/bunescu/ChordRecognition/bach/012106b_annotated_events.xml
31 | /home/razvan/bunescu/ChordRecognition/bach/000106b_annotated_events.xml
32 | /home/razvan/bunescu/ChordRecognition/bach/012606bvannotated_events.xml
33 | /home/razvan/bunescu/ChordRecognition/bach/015408b_annotated_events.xml
34 | /home/razvan/bunescu/ChordRecognition/bach/012705b_annotated_events.xml
35 | /home/razvan/bunescu/ChordRecognition/bach/012506b_annotated_events.xml
36 | /home/razvan/bunescu/ChordRecognition/bach/001707b_annotated_events.xml
37 | /home/razvan/bunescu/ChordRecognition/bach/012406b_annotated_events.xml
38 | /home/razvan/bunescu/ChordRecognition/bach/012606b_annotated_events.xml
39 | /home/razvan/bunescu/ChordRecognition/bach/013506b_annotated_events.xml
40 | /home/razvan/bunescu/ChordRecognition/bach/012805b_annotated_events.xml
41 | /home/razvan/bunescu/ChordRecognition/bach/012006b_annotated_events.xml
42 | /home/razvan/bunescu/ChordRecognition/bach/000606b_annotated_events.xml
43 | /home/razvan/bunescu/ChordRecognition/bach/001106b_annotated_events.xml
44 | /home/razvan/bunescu/ChordRecognition/bach/002406bsannotated_events.xml
45 | /home/razvan/bunescu/ChordRecognition/bach/014806b_annotated_events.xml
46 | /home/razvan/bunescu/ChordRecognition/bach/001007b_annotated_events.xml
47 | /home/razvan/bunescu/ChordRecognition/bach/003206b_annotated_events.xml
48 | /home/razvan/bunescu/ChordRecognition/bach/014505bvannotated_events.xml
49 | /home/razvan/bunescu/ChordRecognition/bach/003608b2annotated_events.xml
50 | /home/razvan/bunescu/ChordRecognition/bach/003907b_annotated_events.xml
51 | /home/razvan/bunescu/ChordRecognition/bach/000206b_annotated_events.xml
52 | /home/razvan/bunescu/ChordRecognition/bach/014806bvannotated_events.xml
53 | /home/razvan/bunescu/ChordRecognition/bach/014403b_annotated_events.xml
54 | /home/razvan/bunescu/ChordRecognition/bach/013906b_annotated_events.xml
55 |
--------------------------------------------------------------------------------
/folds/train10.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003306b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/013705channotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/002806b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/005708b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003109b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/001606b_annotated_events.xml
7 | /home/razvan/bunescu/ChordRecognition/bach/014608b_annotated_events.xml
8 | /home/razvan/bunescu/ChordRecognition/bach/000408b_annotated_events.xml
9 | /home/razvan/bunescu/ChordRecognition/bach/014406b_annotated_events.xml
10 | /home/razvan/bunescu/ChordRecognition/bach/012306b_annotated_events.xml
11 | /home/razvan/bunescu/ChordRecognition/bach/000707b_annotated_events.xml
12 | /home/razvan/bunescu/ChordRecognition/bach/015403b_annotated_events.xml
13 | /home/razvan/bunescu/ChordRecognition/bach/003006b_annotated_events.xml
14 | /home/razvan/bunescu/ChordRecognition/bach/015305b_annotated_events.xml
15 | /home/razvan/bunescu/ChordRecognition/bach/002908channotated_events.xml
16 | /home/razvan/bunescu/ChordRecognition/bach/014505b_annotated_events.xml
17 | /home/razvan/bunescu/ChordRecognition/bach/003806b_annotated_events.xml
18 | /home/razvan/bunescu/ChordRecognition/bach/000907b_annotated_events.xml
19 | /home/razvan/bunescu/ChordRecognition/bach/003907bvannotated_events.xml
20 | /home/razvan/bunescu/ChordRecognition/bach/001207b_annotated_events.xml
21 | /home/razvan/bunescu/ChordRecognition/bach/000507b_annotated_events.xml
22 | /home/razvan/bunescu/ChordRecognition/bach/001805b_annotated_events.xml
23 | /home/razvan/bunescu/ChordRecognition/bach/004006b_annotated_events.xml
24 | /home/razvan/bunescu/ChordRecognition/bach/015309b_annotated_events.xml
25 | /home/razvan/bunescu/ChordRecognition/bach/002506b_annotated_events.xml
26 | /home/razvan/bunescu/ChordRecognition/bach/001306b_annotated_events.xml
27 | /home/razvan/bunescu/ChordRecognition/bach/004008b_annotated_events.xml
28 | /home/razvan/bunescu/ChordRecognition/bach/015505b_annotated_events.xml
29 | /home/razvan/bunescu/ChordRecognition/bach/014007b_annotated_events.xml
30 | /home/razvan/bunescu/ChordRecognition/bach/000306b_annotated_events.xml
31 | /home/razvan/bunescu/ChordRecognition/bach/015105b_annotated_events.xml
32 | /home/razvan/bunescu/ChordRecognition/bach/012206b_annotated_events.xml
33 | /home/razvan/bunescu/ChordRecognition/bach/015301b_annotated_events.xml
34 | /home/razvan/bunescu/ChordRecognition/bach/001907channotated_events.xml
35 | /home/razvan/bunescu/ChordRecognition/bach/014500baannotated_events.xml
36 | /home/razvan/bunescu/ChordRecognition/bach/012106b_annotated_events.xml
37 | /home/razvan/bunescu/ChordRecognition/bach/000106b_annotated_events.xml
38 | /home/razvan/bunescu/ChordRecognition/bach/012606bvannotated_events.xml
39 | /home/razvan/bunescu/ChordRecognition/bach/015408b_annotated_events.xml
40 | /home/razvan/bunescu/ChordRecognition/bach/012705b_annotated_events.xml
41 | /home/razvan/bunescu/ChordRecognition/bach/012506b_annotated_events.xml
42 | /home/razvan/bunescu/ChordRecognition/bach/001707b_annotated_events.xml
43 | /home/razvan/bunescu/ChordRecognition/bach/012406b_annotated_events.xml
44 | /home/razvan/bunescu/ChordRecognition/bach/012606b_annotated_events.xml
45 | /home/razvan/bunescu/ChordRecognition/bach/013506b_annotated_events.xml
46 | /home/razvan/bunescu/ChordRecognition/bach/012805b_annotated_events.xml
47 | /home/razvan/bunescu/ChordRecognition/bach/012006b_annotated_events.xml
48 | /home/razvan/bunescu/ChordRecognition/bach/000606b_annotated_events.xml
49 | /home/razvan/bunescu/ChordRecognition/bach/001106b_annotated_events.xml
50 | /home/razvan/bunescu/ChordRecognition/bach/002406bsannotated_events.xml
51 | /home/razvan/bunescu/ChordRecognition/bach/014806b_annotated_events.xml
52 | /home/razvan/bunescu/ChordRecognition/bach/001007b_annotated_events.xml
53 | /home/razvan/bunescu/ChordRecognition/bach/003206b_annotated_events.xml
54 | /home/razvan/bunescu/ChordRecognition/bach/014505bvannotated_events.xml
55 |
--------------------------------------------------------------------------------
/folds/train2.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003306b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/013705channotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/002806b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/005708b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003109b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/001606b_annotated_events.xml
7 | /home/razvan/bunescu/ChordRecognition/bach/003006b_annotated_events.xml
8 | /home/razvan/bunescu/ChordRecognition/bach/015305b_annotated_events.xml
9 | /home/razvan/bunescu/ChordRecognition/bach/002908channotated_events.xml
10 | /home/razvan/bunescu/ChordRecognition/bach/014505b_annotated_events.xml
11 | /home/razvan/bunescu/ChordRecognition/bach/003806b_annotated_events.xml
12 | /home/razvan/bunescu/ChordRecognition/bach/000907b_annotated_events.xml
13 | /home/razvan/bunescu/ChordRecognition/bach/003907bvannotated_events.xml
14 | /home/razvan/bunescu/ChordRecognition/bach/001207b_annotated_events.xml
15 | /home/razvan/bunescu/ChordRecognition/bach/000507b_annotated_events.xml
16 | /home/razvan/bunescu/ChordRecognition/bach/001805b_annotated_events.xml
17 | /home/razvan/bunescu/ChordRecognition/bach/004006b_annotated_events.xml
18 | /home/razvan/bunescu/ChordRecognition/bach/015309b_annotated_events.xml
19 | /home/razvan/bunescu/ChordRecognition/bach/002506b_annotated_events.xml
20 | /home/razvan/bunescu/ChordRecognition/bach/001306b_annotated_events.xml
21 | /home/razvan/bunescu/ChordRecognition/bach/004008b_annotated_events.xml
22 | /home/razvan/bunescu/ChordRecognition/bach/015505b_annotated_events.xml
23 | /home/razvan/bunescu/ChordRecognition/bach/014007b_annotated_events.xml
24 | /home/razvan/bunescu/ChordRecognition/bach/000306b_annotated_events.xml
25 | /home/razvan/bunescu/ChordRecognition/bach/015105b_annotated_events.xml
26 | /home/razvan/bunescu/ChordRecognition/bach/012206b_annotated_events.xml
27 | /home/razvan/bunescu/ChordRecognition/bach/015301b_annotated_events.xml
28 | /home/razvan/bunescu/ChordRecognition/bach/001907channotated_events.xml
29 | /home/razvan/bunescu/ChordRecognition/bach/014500baannotated_events.xml
30 | /home/razvan/bunescu/ChordRecognition/bach/012106b_annotated_events.xml
31 | /home/razvan/bunescu/ChordRecognition/bach/000106b_annotated_events.xml
32 | /home/razvan/bunescu/ChordRecognition/bach/012606bvannotated_events.xml
33 | /home/razvan/bunescu/ChordRecognition/bach/015408b_annotated_events.xml
34 | /home/razvan/bunescu/ChordRecognition/bach/012705b_annotated_events.xml
35 | /home/razvan/bunescu/ChordRecognition/bach/012506b_annotated_events.xml
36 | /home/razvan/bunescu/ChordRecognition/bach/001707b_annotated_events.xml
37 | /home/razvan/bunescu/ChordRecognition/bach/012406b_annotated_events.xml
38 | /home/razvan/bunescu/ChordRecognition/bach/012606b_annotated_events.xml
39 | /home/razvan/bunescu/ChordRecognition/bach/013506b_annotated_events.xml
40 | /home/razvan/bunescu/ChordRecognition/bach/012805b_annotated_events.xml
41 | /home/razvan/bunescu/ChordRecognition/bach/012006b_annotated_events.xml
42 | /home/razvan/bunescu/ChordRecognition/bach/000606b_annotated_events.xml
43 | /home/razvan/bunescu/ChordRecognition/bach/001106b_annotated_events.xml
44 | /home/razvan/bunescu/ChordRecognition/bach/002406bsannotated_events.xml
45 | /home/razvan/bunescu/ChordRecognition/bach/014806b_annotated_events.xml
46 | /home/razvan/bunescu/ChordRecognition/bach/001007b_annotated_events.xml
47 | /home/razvan/bunescu/ChordRecognition/bach/003206b_annotated_events.xml
48 | /home/razvan/bunescu/ChordRecognition/bach/014505bvannotated_events.xml
49 | /home/razvan/bunescu/ChordRecognition/bach/003608b2annotated_events.xml
50 | /home/razvan/bunescu/ChordRecognition/bach/003907b_annotated_events.xml
51 | /home/razvan/bunescu/ChordRecognition/bach/000206b_annotated_events.xml
52 | /home/razvan/bunescu/ChordRecognition/bach/014806bvannotated_events.xml
53 | /home/razvan/bunescu/ChordRecognition/bach/014403b_annotated_events.xml
54 | /home/razvan/bunescu/ChordRecognition/bach/013906b_annotated_events.xml
55 |
--------------------------------------------------------------------------------
/folds/train3.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003306b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/013705channotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/002806b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/005708b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003109b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/001606b_annotated_events.xml
7 | /home/razvan/bunescu/ChordRecognition/bach/014608b_annotated_events.xml
8 | /home/razvan/bunescu/ChordRecognition/bach/000408b_annotated_events.xml
9 | /home/razvan/bunescu/ChordRecognition/bach/014406b_annotated_events.xml
10 | /home/razvan/bunescu/ChordRecognition/bach/012306b_annotated_events.xml
11 | /home/razvan/bunescu/ChordRecognition/bach/000707b_annotated_events.xml
12 | /home/razvan/bunescu/ChordRecognition/bach/015403b_annotated_events.xml
13 | /home/razvan/bunescu/ChordRecognition/bach/003907bvannotated_events.xml
14 | /home/razvan/bunescu/ChordRecognition/bach/001207b_annotated_events.xml
15 | /home/razvan/bunescu/ChordRecognition/bach/000507b_annotated_events.xml
16 | /home/razvan/bunescu/ChordRecognition/bach/001805b_annotated_events.xml
17 | /home/razvan/bunescu/ChordRecognition/bach/004006b_annotated_events.xml
18 | /home/razvan/bunescu/ChordRecognition/bach/015309b_annotated_events.xml
19 | /home/razvan/bunescu/ChordRecognition/bach/002506b_annotated_events.xml
20 | /home/razvan/bunescu/ChordRecognition/bach/001306b_annotated_events.xml
21 | /home/razvan/bunescu/ChordRecognition/bach/004008b_annotated_events.xml
22 | /home/razvan/bunescu/ChordRecognition/bach/015505b_annotated_events.xml
23 | /home/razvan/bunescu/ChordRecognition/bach/014007b_annotated_events.xml
24 | /home/razvan/bunescu/ChordRecognition/bach/000306b_annotated_events.xml
25 | /home/razvan/bunescu/ChordRecognition/bach/015105b_annotated_events.xml
26 | /home/razvan/bunescu/ChordRecognition/bach/012206b_annotated_events.xml
27 | /home/razvan/bunescu/ChordRecognition/bach/015301b_annotated_events.xml
28 | /home/razvan/bunescu/ChordRecognition/bach/001907channotated_events.xml
29 | /home/razvan/bunescu/ChordRecognition/bach/014500baannotated_events.xml
30 | /home/razvan/bunescu/ChordRecognition/bach/012106b_annotated_events.xml
31 | /home/razvan/bunescu/ChordRecognition/bach/000106b_annotated_events.xml
32 | /home/razvan/bunescu/ChordRecognition/bach/012606bvannotated_events.xml
33 | /home/razvan/bunescu/ChordRecognition/bach/015408b_annotated_events.xml
34 | /home/razvan/bunescu/ChordRecognition/bach/012705b_annotated_events.xml
35 | /home/razvan/bunescu/ChordRecognition/bach/012506b_annotated_events.xml
36 | /home/razvan/bunescu/ChordRecognition/bach/001707b_annotated_events.xml
37 | /home/razvan/bunescu/ChordRecognition/bach/012406b_annotated_events.xml
38 | /home/razvan/bunescu/ChordRecognition/bach/012606b_annotated_events.xml
39 | /home/razvan/bunescu/ChordRecognition/bach/013506b_annotated_events.xml
40 | /home/razvan/bunescu/ChordRecognition/bach/012805b_annotated_events.xml
41 | /home/razvan/bunescu/ChordRecognition/bach/012006b_annotated_events.xml
42 | /home/razvan/bunescu/ChordRecognition/bach/000606b_annotated_events.xml
43 | /home/razvan/bunescu/ChordRecognition/bach/001106b_annotated_events.xml
44 | /home/razvan/bunescu/ChordRecognition/bach/002406bsannotated_events.xml
45 | /home/razvan/bunescu/ChordRecognition/bach/014806b_annotated_events.xml
46 | /home/razvan/bunescu/ChordRecognition/bach/001007b_annotated_events.xml
47 | /home/razvan/bunescu/ChordRecognition/bach/003206b_annotated_events.xml
48 | /home/razvan/bunescu/ChordRecognition/bach/014505bvannotated_events.xml
49 | /home/razvan/bunescu/ChordRecognition/bach/003608b2annotated_events.xml
50 | /home/razvan/bunescu/ChordRecognition/bach/003907b_annotated_events.xml
51 | /home/razvan/bunescu/ChordRecognition/bach/000206b_annotated_events.xml
52 | /home/razvan/bunescu/ChordRecognition/bach/014806bvannotated_events.xml
53 | /home/razvan/bunescu/ChordRecognition/bach/014403b_annotated_events.xml
54 | /home/razvan/bunescu/ChordRecognition/bach/013906b_annotated_events.xml
55 |
--------------------------------------------------------------------------------
/folds/train4.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003306b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/013705channotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/002806b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/005708b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003109b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/001606b_annotated_events.xml
7 | /home/razvan/bunescu/ChordRecognition/bach/014608b_annotated_events.xml
8 | /home/razvan/bunescu/ChordRecognition/bach/000408b_annotated_events.xml
9 | /home/razvan/bunescu/ChordRecognition/bach/014406b_annotated_events.xml
10 | /home/razvan/bunescu/ChordRecognition/bach/012306b_annotated_events.xml
11 | /home/razvan/bunescu/ChordRecognition/bach/000707b_annotated_events.xml
12 | /home/razvan/bunescu/ChordRecognition/bach/015403b_annotated_events.xml
13 | /home/razvan/bunescu/ChordRecognition/bach/003006b_annotated_events.xml
14 | /home/razvan/bunescu/ChordRecognition/bach/015305b_annotated_events.xml
15 | /home/razvan/bunescu/ChordRecognition/bach/002908channotated_events.xml
16 | /home/razvan/bunescu/ChordRecognition/bach/014505b_annotated_events.xml
17 | /home/razvan/bunescu/ChordRecognition/bach/003806b_annotated_events.xml
18 | /home/razvan/bunescu/ChordRecognition/bach/000907b_annotated_events.xml
19 | /home/razvan/bunescu/ChordRecognition/bach/002506b_annotated_events.xml
20 | /home/razvan/bunescu/ChordRecognition/bach/001306b_annotated_events.xml
21 | /home/razvan/bunescu/ChordRecognition/bach/004008b_annotated_events.xml
22 | /home/razvan/bunescu/ChordRecognition/bach/015505b_annotated_events.xml
23 | /home/razvan/bunescu/ChordRecognition/bach/014007b_annotated_events.xml
24 | /home/razvan/bunescu/ChordRecognition/bach/000306b_annotated_events.xml
25 | /home/razvan/bunescu/ChordRecognition/bach/015105b_annotated_events.xml
26 | /home/razvan/bunescu/ChordRecognition/bach/012206b_annotated_events.xml
27 | /home/razvan/bunescu/ChordRecognition/bach/015301b_annotated_events.xml
28 | /home/razvan/bunescu/ChordRecognition/bach/001907channotated_events.xml
29 | /home/razvan/bunescu/ChordRecognition/bach/014500baannotated_events.xml
30 | /home/razvan/bunescu/ChordRecognition/bach/012106b_annotated_events.xml
31 | /home/razvan/bunescu/ChordRecognition/bach/000106b_annotated_events.xml
32 | /home/razvan/bunescu/ChordRecognition/bach/012606bvannotated_events.xml
33 | /home/razvan/bunescu/ChordRecognition/bach/015408b_annotated_events.xml
34 | /home/razvan/bunescu/ChordRecognition/bach/012705b_annotated_events.xml
35 | /home/razvan/bunescu/ChordRecognition/bach/012506b_annotated_events.xml
36 | /home/razvan/bunescu/ChordRecognition/bach/001707b_annotated_events.xml
37 | /home/razvan/bunescu/ChordRecognition/bach/012406b_annotated_events.xml
38 | /home/razvan/bunescu/ChordRecognition/bach/012606b_annotated_events.xml
39 | /home/razvan/bunescu/ChordRecognition/bach/013506b_annotated_events.xml
40 | /home/razvan/bunescu/ChordRecognition/bach/012805b_annotated_events.xml
41 | /home/razvan/bunescu/ChordRecognition/bach/012006b_annotated_events.xml
42 | /home/razvan/bunescu/ChordRecognition/bach/000606b_annotated_events.xml
43 | /home/razvan/bunescu/ChordRecognition/bach/001106b_annotated_events.xml
44 | /home/razvan/bunescu/ChordRecognition/bach/002406bsannotated_events.xml
45 | /home/razvan/bunescu/ChordRecognition/bach/014806b_annotated_events.xml
46 | /home/razvan/bunescu/ChordRecognition/bach/001007b_annotated_events.xml
47 | /home/razvan/bunescu/ChordRecognition/bach/003206b_annotated_events.xml
48 | /home/razvan/bunescu/ChordRecognition/bach/014505bvannotated_events.xml
49 | /home/razvan/bunescu/ChordRecognition/bach/003608b2annotated_events.xml
50 | /home/razvan/bunescu/ChordRecognition/bach/003907b_annotated_events.xml
51 | /home/razvan/bunescu/ChordRecognition/bach/000206b_annotated_events.xml
52 | /home/razvan/bunescu/ChordRecognition/bach/014806bvannotated_events.xml
53 | /home/razvan/bunescu/ChordRecognition/bach/014403b_annotated_events.xml
54 | /home/razvan/bunescu/ChordRecognition/bach/013906b_annotated_events.xml
55 |
--------------------------------------------------------------------------------
/folds/train5.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003306b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/013705channotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/002806b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/005708b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003109b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/001606b_annotated_events.xml
7 | /home/razvan/bunescu/ChordRecognition/bach/014608b_annotated_events.xml
8 | /home/razvan/bunescu/ChordRecognition/bach/000408b_annotated_events.xml
9 | /home/razvan/bunescu/ChordRecognition/bach/014406b_annotated_events.xml
10 | /home/razvan/bunescu/ChordRecognition/bach/012306b_annotated_events.xml
11 | /home/razvan/bunescu/ChordRecognition/bach/000707b_annotated_events.xml
12 | /home/razvan/bunescu/ChordRecognition/bach/015403b_annotated_events.xml
13 | /home/razvan/bunescu/ChordRecognition/bach/003006b_annotated_events.xml
14 | /home/razvan/bunescu/ChordRecognition/bach/015305b_annotated_events.xml
15 | /home/razvan/bunescu/ChordRecognition/bach/002908channotated_events.xml
16 | /home/razvan/bunescu/ChordRecognition/bach/014505b_annotated_events.xml
17 | /home/razvan/bunescu/ChordRecognition/bach/003806b_annotated_events.xml
18 | /home/razvan/bunescu/ChordRecognition/bach/000907b_annotated_events.xml
19 | /home/razvan/bunescu/ChordRecognition/bach/003907bvannotated_events.xml
20 | /home/razvan/bunescu/ChordRecognition/bach/001207b_annotated_events.xml
21 | /home/razvan/bunescu/ChordRecognition/bach/000507b_annotated_events.xml
22 | /home/razvan/bunescu/ChordRecognition/bach/001805b_annotated_events.xml
23 | /home/razvan/bunescu/ChordRecognition/bach/004006b_annotated_events.xml
24 | /home/razvan/bunescu/ChordRecognition/bach/015309b_annotated_events.xml
25 | /home/razvan/bunescu/ChordRecognition/bach/015105b_annotated_events.xml
26 | /home/razvan/bunescu/ChordRecognition/bach/012206b_annotated_events.xml
27 | /home/razvan/bunescu/ChordRecognition/bach/015301b_annotated_events.xml
28 | /home/razvan/bunescu/ChordRecognition/bach/001907channotated_events.xml
29 | /home/razvan/bunescu/ChordRecognition/bach/014500baannotated_events.xml
30 | /home/razvan/bunescu/ChordRecognition/bach/012106b_annotated_events.xml
31 | /home/razvan/bunescu/ChordRecognition/bach/000106b_annotated_events.xml
32 | /home/razvan/bunescu/ChordRecognition/bach/012606bvannotated_events.xml
33 | /home/razvan/bunescu/ChordRecognition/bach/015408b_annotated_events.xml
34 | /home/razvan/bunescu/ChordRecognition/bach/012705b_annotated_events.xml
35 | /home/razvan/bunescu/ChordRecognition/bach/012506b_annotated_events.xml
36 | /home/razvan/bunescu/ChordRecognition/bach/001707b_annotated_events.xml
37 | /home/razvan/bunescu/ChordRecognition/bach/012406b_annotated_events.xml
38 | /home/razvan/bunescu/ChordRecognition/bach/012606b_annotated_events.xml
39 | /home/razvan/bunescu/ChordRecognition/bach/013506b_annotated_events.xml
40 | /home/razvan/bunescu/ChordRecognition/bach/012805b_annotated_events.xml
41 | /home/razvan/bunescu/ChordRecognition/bach/012006b_annotated_events.xml
42 | /home/razvan/bunescu/ChordRecognition/bach/000606b_annotated_events.xml
43 | /home/razvan/bunescu/ChordRecognition/bach/001106b_annotated_events.xml
44 | /home/razvan/bunescu/ChordRecognition/bach/002406bsannotated_events.xml
45 | /home/razvan/bunescu/ChordRecognition/bach/014806b_annotated_events.xml
46 | /home/razvan/bunescu/ChordRecognition/bach/001007b_annotated_events.xml
47 | /home/razvan/bunescu/ChordRecognition/bach/003206b_annotated_events.xml
48 | /home/razvan/bunescu/ChordRecognition/bach/014505bvannotated_events.xml
49 | /home/razvan/bunescu/ChordRecognition/bach/003608b2annotated_events.xml
50 | /home/razvan/bunescu/ChordRecognition/bach/003907b_annotated_events.xml
51 | /home/razvan/bunescu/ChordRecognition/bach/000206b_annotated_events.xml
52 | /home/razvan/bunescu/ChordRecognition/bach/014806bvannotated_events.xml
53 | /home/razvan/bunescu/ChordRecognition/bach/014403b_annotated_events.xml
54 | /home/razvan/bunescu/ChordRecognition/bach/013906b_annotated_events.xml
55 |
--------------------------------------------------------------------------------
/folds/train6.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003306b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/013705channotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/002806b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/005708b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003109b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/001606b_annotated_events.xml
7 | /home/razvan/bunescu/ChordRecognition/bach/014608b_annotated_events.xml
8 | /home/razvan/bunescu/ChordRecognition/bach/000408b_annotated_events.xml
9 | /home/razvan/bunescu/ChordRecognition/bach/014406b_annotated_events.xml
10 | /home/razvan/bunescu/ChordRecognition/bach/012306b_annotated_events.xml
11 | /home/razvan/bunescu/ChordRecognition/bach/000707b_annotated_events.xml
12 | /home/razvan/bunescu/ChordRecognition/bach/015403b_annotated_events.xml
13 | /home/razvan/bunescu/ChordRecognition/bach/003006b_annotated_events.xml
14 | /home/razvan/bunescu/ChordRecognition/bach/015305b_annotated_events.xml
15 | /home/razvan/bunescu/ChordRecognition/bach/002908channotated_events.xml
16 | /home/razvan/bunescu/ChordRecognition/bach/014505b_annotated_events.xml
17 | /home/razvan/bunescu/ChordRecognition/bach/003806b_annotated_events.xml
18 | /home/razvan/bunescu/ChordRecognition/bach/000907b_annotated_events.xml
19 | /home/razvan/bunescu/ChordRecognition/bach/003907bvannotated_events.xml
20 | /home/razvan/bunescu/ChordRecognition/bach/001207b_annotated_events.xml
21 | /home/razvan/bunescu/ChordRecognition/bach/000507b_annotated_events.xml
22 | /home/razvan/bunescu/ChordRecognition/bach/001805b_annotated_events.xml
23 | /home/razvan/bunescu/ChordRecognition/bach/004006b_annotated_events.xml
24 | /home/razvan/bunescu/ChordRecognition/bach/015309b_annotated_events.xml
25 | /home/razvan/bunescu/ChordRecognition/bach/002506b_annotated_events.xml
26 | /home/razvan/bunescu/ChordRecognition/bach/001306b_annotated_events.xml
27 | /home/razvan/bunescu/ChordRecognition/bach/004008b_annotated_events.xml
28 | /home/razvan/bunescu/ChordRecognition/bach/015505b_annotated_events.xml
29 | /home/razvan/bunescu/ChordRecognition/bach/014007b_annotated_events.xml
30 | /home/razvan/bunescu/ChordRecognition/bach/000306b_annotated_events.xml
31 | /home/razvan/bunescu/ChordRecognition/bach/000106b_annotated_events.xml
32 | /home/razvan/bunescu/ChordRecognition/bach/012606bvannotated_events.xml
33 | /home/razvan/bunescu/ChordRecognition/bach/015408b_annotated_events.xml
34 | /home/razvan/bunescu/ChordRecognition/bach/012705b_annotated_events.xml
35 | /home/razvan/bunescu/ChordRecognition/bach/012506b_annotated_events.xml
36 | /home/razvan/bunescu/ChordRecognition/bach/001707b_annotated_events.xml
37 | /home/razvan/bunescu/ChordRecognition/bach/012406b_annotated_events.xml
38 | /home/razvan/bunescu/ChordRecognition/bach/012606b_annotated_events.xml
39 | /home/razvan/bunescu/ChordRecognition/bach/013506b_annotated_events.xml
40 | /home/razvan/bunescu/ChordRecognition/bach/012805b_annotated_events.xml
41 | /home/razvan/bunescu/ChordRecognition/bach/012006b_annotated_events.xml
42 | /home/razvan/bunescu/ChordRecognition/bach/000606b_annotated_events.xml
43 | /home/razvan/bunescu/ChordRecognition/bach/001106b_annotated_events.xml
44 | /home/razvan/bunescu/ChordRecognition/bach/002406bsannotated_events.xml
45 | /home/razvan/bunescu/ChordRecognition/bach/014806b_annotated_events.xml
46 | /home/razvan/bunescu/ChordRecognition/bach/001007b_annotated_events.xml
47 | /home/razvan/bunescu/ChordRecognition/bach/003206b_annotated_events.xml
48 | /home/razvan/bunescu/ChordRecognition/bach/014505bvannotated_events.xml
49 | /home/razvan/bunescu/ChordRecognition/bach/003608b2annotated_events.xml
50 | /home/razvan/bunescu/ChordRecognition/bach/003907b_annotated_events.xml
51 | /home/razvan/bunescu/ChordRecognition/bach/000206b_annotated_events.xml
52 | /home/razvan/bunescu/ChordRecognition/bach/014806bvannotated_events.xml
53 | /home/razvan/bunescu/ChordRecognition/bach/014403b_annotated_events.xml
54 | /home/razvan/bunescu/ChordRecognition/bach/013906b_annotated_events.xml
55 |
--------------------------------------------------------------------------------
/folds/train7.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003306b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/013705channotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/002806b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/005708b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003109b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/001606b_annotated_events.xml
7 | /home/razvan/bunescu/ChordRecognition/bach/014608b_annotated_events.xml
8 | /home/razvan/bunescu/ChordRecognition/bach/000408b_annotated_events.xml
9 | /home/razvan/bunescu/ChordRecognition/bach/014406b_annotated_events.xml
10 | /home/razvan/bunescu/ChordRecognition/bach/012306b_annotated_events.xml
11 | /home/razvan/bunescu/ChordRecognition/bach/000707b_annotated_events.xml
12 | /home/razvan/bunescu/ChordRecognition/bach/015403b_annotated_events.xml
13 | /home/razvan/bunescu/ChordRecognition/bach/003006b_annotated_events.xml
14 | /home/razvan/bunescu/ChordRecognition/bach/015305b_annotated_events.xml
15 | /home/razvan/bunescu/ChordRecognition/bach/002908channotated_events.xml
16 | /home/razvan/bunescu/ChordRecognition/bach/014505b_annotated_events.xml
17 | /home/razvan/bunescu/ChordRecognition/bach/003806b_annotated_events.xml
18 | /home/razvan/bunescu/ChordRecognition/bach/000907b_annotated_events.xml
19 | /home/razvan/bunescu/ChordRecognition/bach/003907bvannotated_events.xml
20 | /home/razvan/bunescu/ChordRecognition/bach/001207b_annotated_events.xml
21 | /home/razvan/bunescu/ChordRecognition/bach/000507b_annotated_events.xml
22 | /home/razvan/bunescu/ChordRecognition/bach/001805b_annotated_events.xml
23 | /home/razvan/bunescu/ChordRecognition/bach/004006b_annotated_events.xml
24 | /home/razvan/bunescu/ChordRecognition/bach/015309b_annotated_events.xml
25 | /home/razvan/bunescu/ChordRecognition/bach/002506b_annotated_events.xml
26 | /home/razvan/bunescu/ChordRecognition/bach/001306b_annotated_events.xml
27 | /home/razvan/bunescu/ChordRecognition/bach/004008b_annotated_events.xml
28 | /home/razvan/bunescu/ChordRecognition/bach/015505b_annotated_events.xml
29 | /home/razvan/bunescu/ChordRecognition/bach/014007b_annotated_events.xml
30 | /home/razvan/bunescu/ChordRecognition/bach/000306b_annotated_events.xml
31 | /home/razvan/bunescu/ChordRecognition/bach/015105b_annotated_events.xml
32 | /home/razvan/bunescu/ChordRecognition/bach/012206b_annotated_events.xml
33 | /home/razvan/bunescu/ChordRecognition/bach/015301b_annotated_events.xml
34 | /home/razvan/bunescu/ChordRecognition/bach/001907channotated_events.xml
35 | /home/razvan/bunescu/ChordRecognition/bach/014500baannotated_events.xml
36 | /home/razvan/bunescu/ChordRecognition/bach/012106b_annotated_events.xml
37 | /home/razvan/bunescu/ChordRecognition/bach/012406b_annotated_events.xml
38 | /home/razvan/bunescu/ChordRecognition/bach/012606b_annotated_events.xml
39 | /home/razvan/bunescu/ChordRecognition/bach/013506b_annotated_events.xml
40 | /home/razvan/bunescu/ChordRecognition/bach/012805b_annotated_events.xml
41 | /home/razvan/bunescu/ChordRecognition/bach/012006b_annotated_events.xml
42 | /home/razvan/bunescu/ChordRecognition/bach/000606b_annotated_events.xml
43 | /home/razvan/bunescu/ChordRecognition/bach/001106b_annotated_events.xml
44 | /home/razvan/bunescu/ChordRecognition/bach/002406bsannotated_events.xml
45 | /home/razvan/bunescu/ChordRecognition/bach/014806b_annotated_events.xml
46 | /home/razvan/bunescu/ChordRecognition/bach/001007b_annotated_events.xml
47 | /home/razvan/bunescu/ChordRecognition/bach/003206b_annotated_events.xml
48 | /home/razvan/bunescu/ChordRecognition/bach/014505bvannotated_events.xml
49 | /home/razvan/bunescu/ChordRecognition/bach/003608b2annotated_events.xml
50 | /home/razvan/bunescu/ChordRecognition/bach/003907b_annotated_events.xml
51 | /home/razvan/bunescu/ChordRecognition/bach/000206b_annotated_events.xml
52 | /home/razvan/bunescu/ChordRecognition/bach/014806bvannotated_events.xml
53 | /home/razvan/bunescu/ChordRecognition/bach/014403b_annotated_events.xml
54 | /home/razvan/bunescu/ChordRecognition/bach/013906b_annotated_events.xml
55 |
--------------------------------------------------------------------------------
/folds/train8.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003306b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/013705channotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/002806b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/005708b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003109b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/001606b_annotated_events.xml
7 | /home/razvan/bunescu/ChordRecognition/bach/014608b_annotated_events.xml
8 | /home/razvan/bunescu/ChordRecognition/bach/000408b_annotated_events.xml
9 | /home/razvan/bunescu/ChordRecognition/bach/014406b_annotated_events.xml
10 | /home/razvan/bunescu/ChordRecognition/bach/012306b_annotated_events.xml
11 | /home/razvan/bunescu/ChordRecognition/bach/000707b_annotated_events.xml
12 | /home/razvan/bunescu/ChordRecognition/bach/015403b_annotated_events.xml
13 | /home/razvan/bunescu/ChordRecognition/bach/003006b_annotated_events.xml
14 | /home/razvan/bunescu/ChordRecognition/bach/015305b_annotated_events.xml
15 | /home/razvan/bunescu/ChordRecognition/bach/002908channotated_events.xml
16 | /home/razvan/bunescu/ChordRecognition/bach/014505b_annotated_events.xml
17 | /home/razvan/bunescu/ChordRecognition/bach/003806b_annotated_events.xml
18 | /home/razvan/bunescu/ChordRecognition/bach/000907b_annotated_events.xml
19 | /home/razvan/bunescu/ChordRecognition/bach/003907bvannotated_events.xml
20 | /home/razvan/bunescu/ChordRecognition/bach/001207b_annotated_events.xml
21 | /home/razvan/bunescu/ChordRecognition/bach/000507b_annotated_events.xml
22 | /home/razvan/bunescu/ChordRecognition/bach/001805b_annotated_events.xml
23 | /home/razvan/bunescu/ChordRecognition/bach/004006b_annotated_events.xml
24 | /home/razvan/bunescu/ChordRecognition/bach/015309b_annotated_events.xml
25 | /home/razvan/bunescu/ChordRecognition/bach/002506b_annotated_events.xml
26 | /home/razvan/bunescu/ChordRecognition/bach/001306b_annotated_events.xml
27 | /home/razvan/bunescu/ChordRecognition/bach/004008b_annotated_events.xml
28 | /home/razvan/bunescu/ChordRecognition/bach/015505b_annotated_events.xml
29 | /home/razvan/bunescu/ChordRecognition/bach/014007b_annotated_events.xml
30 | /home/razvan/bunescu/ChordRecognition/bach/000306b_annotated_events.xml
31 | /home/razvan/bunescu/ChordRecognition/bach/015105b_annotated_events.xml
32 | /home/razvan/bunescu/ChordRecognition/bach/012206b_annotated_events.xml
33 | /home/razvan/bunescu/ChordRecognition/bach/015301b_annotated_events.xml
34 | /home/razvan/bunescu/ChordRecognition/bach/001907channotated_events.xml
35 | /home/razvan/bunescu/ChordRecognition/bach/014500baannotated_events.xml
36 | /home/razvan/bunescu/ChordRecognition/bach/012106b_annotated_events.xml
37 | /home/razvan/bunescu/ChordRecognition/bach/000106b_annotated_events.xml
38 | /home/razvan/bunescu/ChordRecognition/bach/012606bvannotated_events.xml
39 | /home/razvan/bunescu/ChordRecognition/bach/015408b_annotated_events.xml
40 | /home/razvan/bunescu/ChordRecognition/bach/012705b_annotated_events.xml
41 | /home/razvan/bunescu/ChordRecognition/bach/012506b_annotated_events.xml
42 | /home/razvan/bunescu/ChordRecognition/bach/001707b_annotated_events.xml
43 | /home/razvan/bunescu/ChordRecognition/bach/001106b_annotated_events.xml
44 | /home/razvan/bunescu/ChordRecognition/bach/002406bsannotated_events.xml
45 | /home/razvan/bunescu/ChordRecognition/bach/014806b_annotated_events.xml
46 | /home/razvan/bunescu/ChordRecognition/bach/001007b_annotated_events.xml
47 | /home/razvan/bunescu/ChordRecognition/bach/003206b_annotated_events.xml
48 | /home/razvan/bunescu/ChordRecognition/bach/014505bvannotated_events.xml
49 | /home/razvan/bunescu/ChordRecognition/bach/003608b2annotated_events.xml
50 | /home/razvan/bunescu/ChordRecognition/bach/003907b_annotated_events.xml
51 | /home/razvan/bunescu/ChordRecognition/bach/000206b_annotated_events.xml
52 | /home/razvan/bunescu/ChordRecognition/bach/014806bvannotated_events.xml
53 | /home/razvan/bunescu/ChordRecognition/bach/014403b_annotated_events.xml
54 | /home/razvan/bunescu/ChordRecognition/bach/013906b_annotated_events.xml
55 |
--------------------------------------------------------------------------------
/folds/train9.txt:
--------------------------------------------------------------------------------
1 | /home/razvan/bunescu/ChordRecognition/bach/003306b_annotated_events.xml
2 | /home/razvan/bunescu/ChordRecognition/bach/013705channotated_events.xml
3 | /home/razvan/bunescu/ChordRecognition/bach/002806b_annotated_events.xml
4 | /home/razvan/bunescu/ChordRecognition/bach/005708b_annotated_events.xml
5 | /home/razvan/bunescu/ChordRecognition/bach/003109b_annotated_events.xml
6 | /home/razvan/bunescu/ChordRecognition/bach/001606b_annotated_events.xml
7 | /home/razvan/bunescu/ChordRecognition/bach/014608b_annotated_events.xml
8 | /home/razvan/bunescu/ChordRecognition/bach/000408b_annotated_events.xml
9 | /home/razvan/bunescu/ChordRecognition/bach/014406b_annotated_events.xml
10 | /home/razvan/bunescu/ChordRecognition/bach/012306b_annotated_events.xml
11 | /home/razvan/bunescu/ChordRecognition/bach/000707b_annotated_events.xml
12 | /home/razvan/bunescu/ChordRecognition/bach/015403b_annotated_events.xml
13 | /home/razvan/bunescu/ChordRecognition/bach/003006b_annotated_events.xml
14 | /home/razvan/bunescu/ChordRecognition/bach/015305b_annotated_events.xml
15 | /home/razvan/bunescu/ChordRecognition/bach/002908channotated_events.xml
16 | /home/razvan/bunescu/ChordRecognition/bach/014505b_annotated_events.xml
17 | /home/razvan/bunescu/ChordRecognition/bach/003806b_annotated_events.xml
18 | /home/razvan/bunescu/ChordRecognition/bach/000907b_annotated_events.xml
19 | /home/razvan/bunescu/ChordRecognition/bach/003907bvannotated_events.xml
20 | /home/razvan/bunescu/ChordRecognition/bach/001207b_annotated_events.xml
21 | /home/razvan/bunescu/ChordRecognition/bach/000507b_annotated_events.xml
22 | /home/razvan/bunescu/ChordRecognition/bach/001805b_annotated_events.xml
23 | /home/razvan/bunescu/ChordRecognition/bach/004006b_annotated_events.xml
24 | /home/razvan/bunescu/ChordRecognition/bach/015309b_annotated_events.xml
25 | /home/razvan/bunescu/ChordRecognition/bach/002506b_annotated_events.xml
26 | /home/razvan/bunescu/ChordRecognition/bach/001306b_annotated_events.xml
27 | /home/razvan/bunescu/ChordRecognition/bach/004008b_annotated_events.xml
28 | /home/razvan/bunescu/ChordRecognition/bach/015505b_annotated_events.xml
29 | /home/razvan/bunescu/ChordRecognition/bach/014007b_annotated_events.xml
30 | /home/razvan/bunescu/ChordRecognition/bach/000306b_annotated_events.xml
31 | /home/razvan/bunescu/ChordRecognition/bach/015105b_annotated_events.xml
32 | /home/razvan/bunescu/ChordRecognition/bach/012206b_annotated_events.xml
33 | /home/razvan/bunescu/ChordRecognition/bach/015301b_annotated_events.xml
34 | /home/razvan/bunescu/ChordRecognition/bach/001907channotated_events.xml
35 | /home/razvan/bunescu/ChordRecognition/bach/014500baannotated_events.xml
36 | /home/razvan/bunescu/ChordRecognition/bach/012106b_annotated_events.xml
37 | /home/razvan/bunescu/ChordRecognition/bach/000106b_annotated_events.xml
38 | /home/razvan/bunescu/ChordRecognition/bach/012606bvannotated_events.xml
39 | /home/razvan/bunescu/ChordRecognition/bach/015408b_annotated_events.xml
40 | /home/razvan/bunescu/ChordRecognition/bach/012705b_annotated_events.xml
41 | /home/razvan/bunescu/ChordRecognition/bach/012506b_annotated_events.xml
42 | /home/razvan/bunescu/ChordRecognition/bach/001707b_annotated_events.xml
43 | /home/razvan/bunescu/ChordRecognition/bach/012406b_annotated_events.xml
44 | /home/razvan/bunescu/ChordRecognition/bach/012606b_annotated_events.xml
45 | /home/razvan/bunescu/ChordRecognition/bach/013506b_annotated_events.xml
46 | /home/razvan/bunescu/ChordRecognition/bach/012805b_annotated_events.xml
47 | /home/razvan/bunescu/ChordRecognition/bach/012006b_annotated_events.xml
48 | /home/razvan/bunescu/ChordRecognition/bach/000606b_annotated_events.xml
49 | /home/razvan/bunescu/ChordRecognition/bach/003608b2annotated_events.xml
50 | /home/razvan/bunescu/ChordRecognition/bach/003907b_annotated_events.xml
51 | /home/razvan/bunescu/ChordRecognition/bach/000206b_annotated_events.xml
52 | /home/razvan/bunescu/ChordRecognition/bach/014806bvannotated_events.xml
53 | /home/razvan/bunescu/ChordRecognition/bach/014403b_annotated_events.xml
54 | /home/razvan/bunescu/ChordRecognition/bach/013906b_annotated_events.xml
55 |
--------------------------------------------------------------------------------
/musicxml_parser/musicxml_parser.py:
--------------------------------------------------------------------------------
1 | # Kristen Masada
2 | # Converts MusicXML file to XML file with event-based info
3 |
4 |
5 | import sys
6 | import io
7 | import re
8 | from lxml import builder, etree
9 | from music21 import converter, note, chord, stream, search
10 |
11 | # import MusicXML file
12 | file = sys.argv[1]
13 | filename = file[:-4]
14 | score = converter.parse(file)
15 |
16 | # initialize song tag, which will be root tag of xml file
17 | song = etree.Element("song")
18 |
19 | # top-level comment providing brief description about units for onset/duration
20 | comment = "Durations are in quarter length format, in which a quarter note is of length 1.0, an eighth note is of length 0.5, etc. Onsets are relative to the beginning of the score, starting at index 0.0, and are in quarter length format as well."
21 | song.addprevious(etree.Comment(comment))
22 |
23 | # create title tag from song tag; include song title as text
24 | etree.SubElement(song, "title").text = filename
25 |
26 | # create XML for length of song
27 | etree.SubElement(song, "length").text = str(score.quarterLength)
28 |
29 | # convert score to TimespanTree object
30 | scoreTree = score.asTimespans(classList = (note.Note,chord.Chord))
31 |
32 | # grab events from scoreTree
33 | chord_events = list(scoreTree.iterateVerticalities())
34 |
35 | # get chords from lyrics
36 | reSearchChords = re.compile(r'[^\s]+', re.IGNORECASE)
37 | ls = search.lyrics.LyricSearcher(score)
38 | chords = ls.search(reSearchChords)
39 |
40 | # put chords into sorted dictionary, with key as onset time and value as chord name
41 | chords_dict = {}
42 | for c in chords:
43 | chords_dict[c.els[0].getOffsetInHierarchy(score)] = c.matchText.split("|")[0] # get preferred chord annotation
44 | chords_keys = sorted(chords_dict.keys())
45 |
46 | # create XML for events
47 | events = etree.SubElement(song, "events")
48 | i = 0 # counter for index number of event in array
49 | events_dict = {} # events dictionary, with key as onset time and value as index number;
50 | # used later for getting eventStart and eventStop info for segments
51 | prev_label = chords_dict[min(chords_dict)] # chord label of event with smallest key
52 | for e in chord_events:
53 | event = etree.SubElement(events, "event")
54 | etree.SubElement(event, "index").text = str(i)
55 | if e.offset in chords_keys:
56 | etree.SubElement(event, "tag").text = "B-" + chords_dict[e.offset]
57 | prev_label = chords_dict[e.offset]
58 | else:
59 | etree.SubElement(event, "tag").text = "I-" + prev_label
60 | etree.SubElement(event, "onset").text = str(e.offset)
61 | events_dict[e.offset] = i
62 | if e.nextStartOffset:
63 | etree.SubElement(event, "duration").text = str(e.nextStartOffset - e.offset)
64 | else:
65 | etree.SubElement(event, "duration").text = str(score.quarterLength - e.offset)
66 | etree.SubElement(event, "measureNumber").text = str(e.measureNumber)
67 | etree.SubElement(event, "accent").text = str(e.beatStrength)
68 | notes = etree.SubElement(event, "notes")
69 | for s in e.startTimespans:
70 | duration = s.quarterLength
71 | for p in s.pitches:
72 | note = etree.SubElement(notes, "note")
73 | noteNameWithOctave = p.nameWithOctave
74 | noteNameWithOctave = noteNameWithOctave.replace("-", "b")
75 | etree.SubElement(note, "pitch").text = noteNameWithOctave
76 | etree.SubElement(note, "duration").text = str(duration)
77 | etree.SubElement(note, "fromPrevious").text = "False"
78 | etree.SubElement(note, "accent").text = str(e.beatStrength)
79 | etree.SubElement(note, "onset").text = str(e.offset)
80 | for v in e.overlapTimespans:
81 | duration = v.quarterLength
82 | for p in v.pitches:
83 | note = etree.SubElement(notes, "note")
84 | noteNameWithOctave = p.nameWithOctave
85 | noteNameWithOctave = noteNameWithOctave.replace("-", "b")
86 | etree.SubElement(note, "pitch").text = noteNameWithOctave
87 | etree.SubElement(note, "duration").text = str(duration)
88 | etree.SubElement(note, "fromPrevious").text = "True"
89 | etree.SubElement(note, "accent").text = str(e.beatStrength)
90 | i += 1
91 |
92 | # create XML for segments
93 | segments = etree.SubElement(song, "segments")
94 | for i, key in enumerate(chords_keys):
95 | segment = etree.SubElement(segments, "segment")
96 | etree.SubElement(segment, "chordLabel").text = chords_dict[key]
97 | etree.SubElement(segment, "onset").text = str(key)
98 | if i < (len(chords) - 1):
99 | etree.SubElement(segment, "offset").text = str(chords_keys[i + 1])
100 | else:
101 | etree.SubElement(segment, "offset").text = str(score.quarterLength)
102 | etree.SubElement(segment, "eventStart").text = str(events_dict[key])
103 | if i < (len(chords) - 1):
104 | etree.SubElement(segment, "eventStop").text = str(events_dict[chords_keys[i + 1]])
105 | else:
106 | etree.SubElement(segment, "eventStop").text = str(len(events_dict))
107 |
108 |
109 | # output xml file
110 | xml_filename = filename + "_events.xml"
111 | et = etree.ElementTree(song)
112 | et.write(xml_filename, encoding = "UTF-8", pretty_print = True, xml_declaration = True)
113 |
114 |
--------------------------------------------------------------------------------
/src/cr/Song.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.Arrays;
6 | import java.util.Collections;
7 | import java.util.List;
8 | import com.statnlp.example.base.BaseInstance;
9 |
10 | import static cr.SongUtil.simplifyLabel;
11 | import static cr.SongUtil.normalizeEnharmonicChords;
12 |
13 | import cr.CRMain.Simplify;
14 | import nu.xom.Element;
15 | import nu.xom.Elements;
16 |
17 | public class Song extends BaseInstance, List> {
18 |
19 | private static final long serialVersionUID = -6338401873189645364L;
20 |
21 | public String title; // title of song
22 | public List outputTokenized; // tokenized output
23 | public List predictionTokenized; // tokenized predictions
24 | public double length; // total length of song in quarterLength
25 |
26 | public Song() {
27 | this(1, 1.0, new ArrayList(), new ArrayList(), "", 0.0);
28 | }
29 |
30 | public Song(int instanceId) {
31 | this(instanceId, 1.0, new ArrayList(), new ArrayList(), "", 0.0, new ArrayList());
32 | }
33 |
34 | public Song(int instanceId, double weight) {
35 | this(instanceId, weight, (List) null, (List) null, (String) null, 0.0, (List) null);
36 | }
37 |
38 | public Song(int instanceId, double weight, List input, List output, String title, double length) {
39 | super(instanceId, weight);
40 | this.input = input;
41 | this.output = output;
42 | this.prediction = Collections.emptyList();
43 | this.title = title;
44 | this.length = length;
45 | this.outputTokenized = null;
46 | this.predictionTokenized = null;
47 | }
48 |
49 | public Song(int instanceId, double weight, List input, List output, String title, double length, List outputTokenized) {
50 | super(instanceId, weight);
51 | this.input = input;
52 | this.output = output;
53 | this.prediction = Collections.emptyList();
54 | this.title = title;
55 | this.length = length;
56 | this.outputTokenized = outputTokenized;
57 | this.predictionTokenized = null;
58 | }
59 |
60 | public Song duplicate(){
61 | Song result = super.duplicate();
62 | result.title = this.title;
63 | result.length = this.length;
64 | result.outputTokenized = this.outputTokenized == null ? null : new ArrayList(this.outputTokenized);
65 | result.predictionTokenized = this.predictionTokenized == null ? null : new ArrayList(this.predictionTokenized);
66 | return result;
67 | }
68 |
69 | public static Song parseXML(Element element, int instanceId, Simplify simplification, boolean normalizeEnharmonics) throws IOException {
70 | Song song = new Song(instanceId);
71 | String tag;
72 |
73 | // weight as 1.0?
74 | song.title = element.getFirstChildElement("title").getValue();
75 | song.length = Double.parseDouble(element.getFirstChildElement("length").getValue());
76 | // System.out.println("Title: " + song.title + ", Length: " + song.length);
77 |
78 | Elements events = element.getFirstChildElement("events").getChildElements();
79 | for (int i = 0; i < events.size(); i++) {
80 | if(i == 0) {
81 | song.input.add(Event.parseXML(events.get(i), null));
82 | }
83 | else {
84 | song.input.add(Event.parseXML(events.get(i), song.input.get(i - 1)));
85 | }
86 | tag = events.get(i).getFirstChildElement("tag").getValue().trim();
87 | song.outputTokenized.add(WordLabel.get(normalizeEnharmonicChords(simplifyLabel(tag, simplification), normalizeEnharmonics)));
88 | }
89 |
90 | Elements segments = element.getFirstChildElement("segments").getChildElements();
91 | for (int i = 0; i < segments.size(); i++) {
92 | song.output.add(Span.parseXML(segments.get(i), simplification, normalizeEnharmonics));
93 | }
94 |
95 | return song;
96 | }
97 |
98 | public void setPredictionTokenized(List predictionTokenized){
99 | this.predictionTokenized = predictionTokenized;
100 | if(predictionTokenized == null){
101 | this.prediction = null;
102 | } else {
103 | this.prediction = SongUtil.labelsToSpans(predictionTokenized, input, length);
104 | }
105 | }
106 |
107 | public String toString() {
108 | String text = "Title: " + this.title + "\n";
109 | text += "Length: " + this.length + "\n";
110 | for (Event event : this.input) {
111 | int eventIndex = this.input.indexOf(event);
112 | text += event.toString();
113 | text += "- Tag: " + this.outputTokenized.get(eventIndex).toString() + "\n";
114 | }
115 |
116 | text += "Output:\n";
117 |
118 | for (Span span : this.output) {
119 | text += span.toString();
120 | }
121 |
122 | text += "Predictions:\n";
123 |
124 | for (Span span : this.prediction) {
125 | text += span.toString();
126 | }
127 |
128 | return text;
129 | }
130 |
131 | public List getInputTokenized(){
132 | if(input == null){
133 | throw new RuntimeException("Input not available.");
134 | }
135 | return input;
136 | }
137 |
138 | public List getOutputTokenized(){
139 | if(outputTokenized == null){
140 | throw new RuntimeException("Output not yet tokenized.");
141 | }
142 | return outputTokenized;
143 | }
144 |
145 | public List duplicateInput() {
146 | return input == null ? null : new ArrayList(input);
147 | }
148 |
149 | public List duplicateOutput() {
150 | return output == null ? null : new ArrayList(output);
151 | }
152 |
153 | public List duplicatePrediction() {
154 | return prediction == null ? null : new ArrayList(prediction);
155 | }
156 |
157 | @Override
158 | public int size() {
159 | return getInput().size();
160 | }
161 | }
--------------------------------------------------------------------------------
/src/cr/WordWeakSemiCRFNetworkCompiler.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.List;
6 |
7 | import com.statnlp.commons.types.Instance;
8 | import com.statnlp.hybridnetworks.LocalNetworkParam;
9 | import com.statnlp.hybridnetworks.Network;
10 | import com.statnlp.hybridnetworks.NetworkCompiler;
11 | import com.statnlp.hybridnetworks.NetworkException;
12 | import com.statnlp.hybridnetworks.NetworkIDMapper;
13 |
14 | /**
15 | * The class that defines the network/graph structure
16 | * This is based on StatNLP framework for CRF on acyclic graphs
17 | * @author Aldrian Obaja
18 | *
19 | */
20 | public class WordWeakSemiCRFNetworkCompiler extends NetworkCompiler {
21 |
22 | private final static boolean DEBUG = true;
23 |
24 | private static final long serialVersionUID = 6585870230920484539L;
25 | public SpanLabel[] labels;
26 | public int maxLength = 20;
27 | public int maxSegmentLength = 1;
28 | public transient long[] allNodes;
29 | public transient int[][][] allChildren;
30 |
31 | public enum NodeType {
32 | LEAF,
33 | ROOT,
34 | BEGIN,
35 | END,
36 | }
37 |
38 | static {
39 | NetworkIDMapper.setCapacity(new int[]{200, 150, 150});
40 | }
41 |
42 | public WordWeakSemiCRFNetworkCompiler(SpanLabel[] labels, int maxLength, int maxSegmentLength) {
43 | this.labels = labels;
44 | this.maxLength = Math.max(maxLength, this.maxLength);
45 | this.maxSegmentLength = Math.max(maxSegmentLength, this.maxSegmentLength);
46 | System.out.println(String.format("Max size: %s, Max segment length: %s", maxLength, maxSegmentLength));
47 | System.out.println(Arrays.asList(labels));
48 | buildUnlabeled();
49 | }
50 |
51 | @Override
52 | public SongNetwork compile(int networkId, Instance inst, LocalNetworkParam param) {
53 | try{
54 | if(inst.isLabeled()){
55 | return compileLabeled(networkId, (Song)inst, param);
56 | } else {
57 | return compileUnlabeled(networkId, (Song)inst, param);
58 | }
59 | } catch (NetworkException e){
60 | System.out.println(inst);
61 | throw e;
62 | }
63 | }
64 |
65 | private SpanLabel wordLabelToSpanLabel(WordLabel label){
66 | String form = label.form;
67 | if(form.startsWith("O")) {
68 | return SpanLabel.get("O");
69 | } else {
70 | return SpanLabel.get(form.substring(form.indexOf("-")+1));
71 | }
72 | }
73 |
74 | private SongNetwork compileLabeled(int networkId, Song instance, LocalNetworkParam param){
75 | SongNetwork network = new SongNetwork(networkId, instance, param);
76 |
77 | List output = instance.getOutputTokenized();
78 | int size = output.size();
79 |
80 | long leaf = toNode_leaf();
81 | network.addNode(leaf);
82 | long prevNode = leaf;
83 | int prevLabelId = -1;
84 | int lastPos = 0;
85 | for(int pos=0; pos= maxSegmentLength){
90 | if(prevLabelId != -1){
91 | long end = toNode_end(pos-1, prevLabelId);
92 | network.addNode(end);
93 | network.addEdge(end, new long[]{prevNode});
94 | prevNode = end;
95 | }
96 | long begin = toNode_begin(pos, labelId);
97 | network.addNode(begin);
98 | network.addEdge(begin, new long[]{prevNode});
99 | prevNode = begin;
100 | prevLabelId = labelId;
101 | lastPos = pos;
102 | }
103 | }
104 | long root = toNode_root(size);
105 | network.addNode(root);
106 | long end = toNode_end(size-1, prevLabelId);
107 | network.addNode(end);
108 | network.addEdge(end, new long[]{prevNode});
109 | network.addEdge(root, new long[]{end});
110 |
111 | network.finalizeNetwork();
112 |
113 | if(DEBUG){
114 | System.out.println(network);
115 | SongNetwork unlabeled = compileUnlabeled(networkId, instance, param);
116 | System.out.println("Contained: "+unlabeled.contains(network));
117 | }
118 | return network;
119 | }
120 |
121 | private SongNetwork compileUnlabeled(int networkId, Song instance, LocalNetworkParam param){
122 | if(allNodes == null){
123 | buildUnlabeled();
124 | }
125 | int size = instance.getInputTokenized().size();
126 | long root = toNode_root(size);
127 | int root_k = Arrays.binarySearch(allNodes, root);
128 | int numNodes = root_k + 1;
129 | return new SongNetwork(networkId, instance, allNodes, allChildren, param, numNodes);
130 | }
131 |
132 | private void buildUnlabeled(){
133 | SongNetwork network = new SongNetwork();
134 |
135 | long leaf = toNode_leaf();
136 | network.addNode(leaf);
137 | List prevNodes = new ArrayList();
138 | List currNodes = new ArrayList();
139 | prevNodes.add(leaf);
140 | for(int pos=0; pos pos-maxSegmentLength && prevPos >= 0; prevPos--){
152 | long prevBeginNode = toNode_begin(prevPos, labelId);
153 | network.addEdge(endNode, new long[]{prevBeginNode});
154 | }
155 |
156 | for(long prevNode: prevNodes){
157 | network.addEdge(beginNode, new long[]{prevNode});
158 | }
159 | }
160 | long root = toNode_root(pos+1);
161 | network.addNode(root);
162 | for(long currNode: currNodes){
163 | network.addEdge(root, new long[]{currNode});
164 | }
165 | prevNodes = currNodes;
166 | currNodes = new ArrayList();
167 | }
168 | network.finalizeNetwork();
169 | allNodes = network.getAllNodes();
170 | allChildren = network.getAllChildren();
171 | }
172 |
173 | private long toNode_leaf(){
174 | return toNode(0, 0, NodeType.LEAF);
175 | }
176 |
177 | private long toNode_root(int pos){
178 | return toNode(pos+1, 0, NodeType.ROOT);
179 | }
180 |
181 | private long toNode_begin(int pos, int labelId){
182 | return toNode(pos+1, labelId+1, NodeType.BEGIN);
183 | }
184 |
185 | private long toNode_end(int pos, int labelId){
186 | return toNode(pos+1, labelId+1, NodeType.END);
187 | }
188 |
189 | private long toNode(int pos, int labelId, NodeType type){
190 | return NetworkIDMapper.toHybridNodeID(new int[]{pos, type.ordinal(), labelId});
191 | }
192 |
193 | @Override
194 | public Song decompile(Network net) {
195 | SongNetwork network = (SongNetwork)net;
196 | Song result = (Song)network.getInstance().duplicate();
197 | List predictionTokenized = new ArrayList();
198 | int node_k = network.countNodes()-1;
199 | while(node_k > 0){
200 | int[] children_k = network.getMaxPath(node_k);
201 | int[] child_arr = network.getNodeArray(children_k[0]);
202 | int end = child_arr[0]-1;
203 | NodeType nodeType = NodeType.values()[child_arr[1]];
204 | if(nodeType == NodeType.LEAF){
205 | break;
206 | } else {
207 | assert nodeType == NodeType.END;
208 | }
209 | int labelId = child_arr[2]-1;
210 | children_k = network.getMaxPath(children_k[0]);
211 | child_arr = network.getNodeArray(children_k[0]);
212 | int start = child_arr[0]-1;
213 | for(int pos=end; pos>=start; pos--){
214 | WordLabel wordLabel;
215 | String form = SpanLabel.get(labelId).form;
216 | if(pos > start){
217 | wordLabel = WordLabel.get("I-"+form);
218 | } else {
219 | wordLabel = WordLabel.get("B-"+form);
220 | }
221 | predictionTokenized.add(0, wordLabel);
222 | }
223 | node_k = children_k[0];
224 | }
225 | result.setPredictionTokenized(predictionTokenized);
226 | return result;
227 | }
228 |
229 | }
230 |
231 |
--------------------------------------------------------------------------------
/src/cr/SongEvaluator.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | import static cr.SongUtil.print;
4 |
5 | import java.io.PrintStream;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.ListIterator;
9 |
10 | import com.statnlp.commons.types.Instance;
11 |
12 |
13 |
14 |
15 | public class SongEvaluator {
16 | private static class Statistics {
17 | public int correct = 0;
18 | public int totalPred = 0;
19 | public int totalGold = 0;
20 |
21 | public void add(Statistics s){
22 | this.correct += s.correct;
23 | this.totalPred += s.totalPred;
24 | this.totalGold += s.totalGold;
25 | }
26 |
27 | public double calculatePrecision(){
28 | if(totalPred == 0){
29 | return 0;
30 | }
31 | return 1.0*correct/totalPred;
32 | }
33 |
34 | public double calculateRecall(){
35 | if(totalGold == 0){
36 | return 0;
37 | }
38 | return 1.0*correct/totalGold;
39 | }
40 |
41 | public double calculateF1(){
42 | double precision = calculatePrecision();
43 | double recall = calculateRecall();
44 | double f1 = precision*recall;
45 | if(f1 == 0){
46 | return 0;
47 | }
48 | f1 = 2*f1/(precision+recall);
49 | return f1;
50 | }
51 |
52 | public void printScore(PrintStream... outstreams){
53 | double precision = calculatePrecision();
54 | double recall = calculateRecall();
55 | double f1 = calculateF1();
56 | print(String.format("(Segment-Based) Correct: %1$d, Predicted: %2$d, Gold: %3$d ", correct, totalPred, totalGold), true, outstreams);
57 | print(String.format("(Segment-Based) Overall P: %#5.2f%%, R: %#5.2f%%, F: %#5.2f%%", 100*precision, 100*recall, 100*f1), true, outstreams);
58 | }
59 |
60 | public void printEventScore(PrintStream... outstreams) {
61 | double accuracy = calculateRecall();
62 | print(String.format("(Event-Based) Correct: %1$d, Predicted: %2$d, Gold: %3$d ", correct, totalPred, totalGold), true, outstreams);
63 | print(String.format("(Event-Based) Overall A: %#5.2f%%", 100*accuracy), true, outstreams);
64 | }
65 | }
66 |
67 | public static void evaluate(Instance[] predictions, PrintStream outstream, int printLimit){
68 | int count = 0;
69 | PrintStream[] outstreams = new PrintStream[]{outstream, System.out};
70 | Statistics finalSpanResult = new Statistics();
71 | Statistics finalEventResult = new Statistics();
72 | for(Instance inst: predictions){
73 | if(count >= printLimit){
74 | outstreams = new PrintStream[]{outstream};
75 | }
76 | Song instance = (Song)inst;
77 | print("Title:", true, outstreams);
78 | print(instance.title.toString(), true, outstreams);
79 | print("Input:", true, outstreams);
80 | print(instance.input.toString(), true, outstreams);
81 | print("Gold:", true, outstreams);
82 | print(instance.output.toString(), true, outstreams);
83 | print("Prediction:", true, outstreams);
84 | print(instance.prediction.toString(), true, outstreams);
85 | Statistics[] spanScores = getSpanScore(new Instance[]{instance});
86 | Statistics[] eventScores = getEventScore(new Instance[]{instance});
87 | Statistics spanOverall = sum(spanScores);
88 | Statistics eventOverall = sum(eventScores);
89 | finalSpanResult.add(spanOverall);
90 | finalEventResult.add(eventOverall);
91 | spanOverall.printScore(outstreams);
92 | eventOverall.printEventScore(outstreams);
93 | print("", true, outstreams);
94 | // printDetailedScore(spanScores, outstreams);
95 | print("", true, outstreams);
96 | count += 1;
97 | }
98 | if(printLimit > 0){
99 | print("", true, outstream, System.out);
100 | } else {
101 | print("", true, outstreams);
102 | }
103 | outstreams = new PrintStream[]{outstream, System.out};
104 | print("### Overall score ###", true, outstream, System.out);
105 | finalSpanResult.printScore(outstreams);
106 | finalEventResult.printEventScore(outstreams);
107 | print("", true, outstream, System.out);
108 | // Statistics[] scores = getSpanScore(predictions);
109 | // printDetailedScore(scores, outstream, System.out);
110 | }
111 |
112 | private static Statistics sum(Statistics[] scores){
113 | Statistics result = new Statistics();
114 | for(Statistics score: scores){
115 | result.add(score);
116 | }
117 | return result;
118 | }
119 |
120 | private static Statistics[] getSpanScore(Instance[] instances) {
121 | int size = SpanLabel.LABELS.size();
122 | Statistics[] result = createStatistics(size);
123 | for(Instance inst: instances) {
124 | Song instance = (Song)inst;
125 | List predicted;
126 | List actual;
127 | predicted = duplicate(instance.getPrediction());
128 | actual = duplicate(instance.getOutput());
129 | for(Span span : actual) {
130 | if(predicted.contains(span)) {
131 | predicted.remove(span);
132 | SpanLabel label = span.label;
133 | result[label.id].correct += 1;
134 | result[label.id].totalPred += 1;
135 | }
136 | result[span.label.id].totalGold += 1;
137 | }
138 | for(Span span: predicted){
139 | result[span.label.id].totalPred += 1;
140 | }
141 | }
142 | return result;
143 | }
144 |
145 | private static Statistics[] getEventScore(Instance[] instances) {
146 | int size = SpanLabel.LABELS.size();
147 | Statistics[] result = createStatistics(size);
148 | for(Instance inst: instances) {
149 | Song instance = (Song)inst;
150 | List predicted;
151 | List actual;
152 | predicted = duplicate(instance.getPrediction());
153 | actual = duplicate(instance.getOutput());
154 | ListIterator it_act = actual.listIterator();
155 | ListIterator it_pred = predicted.listIterator();
156 | Span span_act = new Span();
157 | Span span_pred = new Span();
158 | Event e_act = new Event();
159 | Event e_pred = new Event();
160 | int numPredEvents = span_pred.stop - span_pred.start;
161 | int ip = 0;
162 | while(it_act.hasNext()) {
163 | span_act = it_act.next();
164 | int numActualEvents = span_act.stop - span_act.start;
165 | for(int i = 0; i < numActualEvents; i++) {
166 | System.out.println("Event Num: " + (span_act.start + i) + ", Measure Num: " + instance.input.get(span_act.start).measureNumber);
167 | if(ip < numPredEvents) {
168 | ip++;
169 | }
170 | else {
171 | span_pred = it_pred.next();
172 | ip = 0;
173 | numPredEvents = span_pred.stop - span_pred.start;
174 | ip++;
175 | }
176 |
177 | if(span_pred.label.id == span_act.label.id) {
178 | result[span_act.label.id].correct += 1;
179 | }
180 | System.out.println("Actual: " + span_act.label + " Predicted: " + span_pred.label);
181 | result[span_act.label.id].totalGold += 1;
182 | result[span_pred.label.id].totalPred += 1;
183 | }
184 | }
185 | }
186 | return result;
187 | }
188 |
189 | private static Statistics[] createStatistics(int size){
190 | Statistics[] result = new Statistics[size];
191 | for(int i=0; i duplicate(List list){
210 | List result = new ArrayList();
211 | for(Span span: list){
212 | result.add(span);
213 | }
214 | return result;
215 | }
216 | }
217 |
--------------------------------------------------------------------------------
/src/cr/SongUtil.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.FileInputStream;
6 | import java.io.FileNotFoundException;
7 | import java.io.IOException;
8 | import java.io.InputStreamReader;
9 | import java.io.PrintStream;
10 | import java.io.UnsupportedEncodingException;
11 | import java.lang.reflect.Method;
12 | import java.util.ArrayList;
13 | import java.util.Arrays;
14 | import java.util.Collections;
15 | import java.util.HashMap;
16 | import java.util.List;
17 | import java.util.regex.Matcher;
18 | import java.util.regex.Pattern;
19 |
20 | import com.statnlp.hybridnetworks.GlobalNetworkParam;
21 |
22 | import cr.CRMain.Simplify;
23 | import nu.xom.Builder;
24 | import nu.xom.Document;
25 | import nu.xom.Element;
26 | import nu.xom.Elements;
27 | import nu.xom.ParsingException;
28 |
29 | public class SongUtil {
30 | public static List enharmonicIDToMajChord = new ArrayList<>(Arrays.asList("A", "Bb", "B", "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab"));
31 | public static List enharmonicIDToMinOrDimChord = new ArrayList<>(Arrays.asList("A", "Bb", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"));
32 | public static List enharmonicIDToAug6Chord = new ArrayList<>(Arrays.asList("A", "Bb", "B", "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab"));
33 | public static List enharmonicIDToSus4 = new ArrayList<>(Arrays.asList("A", "Bb", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"));
34 | public static List enharmonicIDToSus2 = new ArrayList<>(Arrays.asList("A", "Bb", "B", "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab"));
35 | public static HashMap enharmonicNotesToID = new HashMap();
36 | static {
37 | enharmonicNotesToID.put("A", 0);
38 | enharmonicNotesToID.put("Bbb", 0);
39 | enharmonicNotesToID.put("A#", 1);
40 | enharmonicNotesToID.put("Bb", 1);
41 | enharmonicNotesToID.put("B", 2);
42 | enharmonicNotesToID.put("Cb", 2);
43 | enharmonicNotesToID.put("B#", 3);
44 | enharmonicNotesToID.put("C", 3);
45 | enharmonicNotesToID.put("C#", 4);
46 | enharmonicNotesToID.put("Db", 4);
47 | enharmonicNotesToID.put("C##", 5);
48 | enharmonicNotesToID.put("D", 5);
49 | enharmonicNotesToID.put("Ebb", 5);
50 | enharmonicNotesToID.put("D#", 6);
51 | enharmonicNotesToID.put("Eb", 6);
52 | enharmonicNotesToID.put("E", 7);
53 | enharmonicNotesToID.put("Fb", 7);
54 | enharmonicNotesToID.put("E#", 8);
55 | enharmonicNotesToID.put("F", 8);
56 | enharmonicNotesToID.put("F#", 9);
57 | enharmonicNotesToID.put("Gb", 9);
58 | enharmonicNotesToID.put("F##", 10);
59 | enharmonicNotesToID.put("G", 10);
60 | enharmonicNotesToID.put("Abb", 10);
61 | enharmonicNotesToID.put("G#", 11);
62 | enharmonicNotesToID.put("Ab", 11);
63 | }
64 |
65 | public static void print(String message, boolean printEndline, PrintStream... outstream){
66 | if(outstream.length == 0){
67 | outstream = new PrintStream[]{System.out};
68 | }
69 | for(PrintStream stream: outstream){
70 | if(stream != null){
71 | if(printEndline){
72 | stream.println(message);
73 | } else {
74 | stream.print(message);
75 | }
76 | }
77 | }
78 | }
79 |
80 | public static void addAllLabels(String filename) throws IOException {
81 | InputStreamReader isr = new InputStreamReader(new FileInputStream(filename), "UTF-8");
82 | BufferedReader br = new BufferedReader(isr);
83 |
84 | while(br.ready()) {
85 | String chordLabel = br.readLine().trim();
86 | SpanLabel.get(chordLabel);
87 | WordLabel.get("B-" + chordLabel);
88 | WordLabel.get("I-" + chordLabel);
89 | }
90 |
91 | br.close();
92 |
93 | return;
94 | }
95 |
96 | public static Song[] readData(String filename, boolean setLabeled, Simplify simplification, boolean normalizeEnharmonics) throws IOException {
97 | ArrayList songFiles = new ArrayList();
98 | ArrayList result = new ArrayList();
99 |
100 | InputStreamReader isr = new InputStreamReader(new FileInputStream(filename), "UTF-8");
101 | BufferedReader br = new BufferedReader(isr);
102 |
103 | // read in names of song files
104 | while(br.ready()) {
105 | String songFilename = br.readLine();
106 | songFiles.add(songFilename);
107 | }
108 |
109 | br.close();
110 |
111 | File directory = new File("./");
112 | System.out.println(directory.getAbsolutePath());
113 |
114 | try {
115 | Builder parser = new Builder();
116 |
117 | // begin instance id at 1
118 | int instanceId = 1;
119 |
120 | for(int i = 0; i < songFiles.size(); i++) {
121 | Document doc = parser.build(songFiles.get(i));
122 |
123 | // for one song---fix to iterate over multiple songs
124 | Element root = doc.getRootElement();
125 |
126 | // read in a song instance
127 | Song song = Song.parseXML(root, instanceId, simplification, normalizeEnharmonics);
128 |
129 | // if true, guarantees that this song instance will be considered
130 | // during training (see Instance.java)
131 | if(setLabeled) {
132 | song.setLabeled();
133 | }
134 | else {
135 | song.setUnlabeled();
136 | }
137 |
138 | // predictions?
139 |
140 | // output song info
141 | System.out.println(song.title);
142 |
143 | // add song instance to result
144 | result.add(song);
145 | instanceId += 1;
146 | }
147 | } catch (ParsingException e) {
148 | System.err.println("Cafe con Leche is malformed today. How embarrassing!");
149 | } catch (IOException ex) {
150 | System.err.println("Could not connect to Cafe con Leche. The site may be down.");
151 | }
152 |
153 | return result.toArray(new Song[result.size()]);
154 | }
155 |
156 | public static String simplifyLabel(String label, Simplify simplification) {
157 | switch(simplification) {
158 | case MODES:
159 | String pattern = "([BI]-)?[A-G][#b]?:(maj|min|dim|aug)"; // only match chord modes
160 | Pattern r = Pattern.compile(pattern); // create pattern object
161 | Matcher m = r.matcher(label); // simplify label
162 | if(m.find()) {
163 | return m.group(0);
164 | }
165 | else {
166 | return label;
167 | }
168 | case GENERIC_ADDED_NOTES:
169 | pattern = "([BI]-)?[A-G][#b]?:(maj|min|dim|aug|ger|it|fr)(4|6|7)?"; // match added notes
170 | r = Pattern.compile(pattern); // create pattern object
171 | m = r.matcher(label); // simplify label
172 | if(m.find()) {
173 | return m.group(0);
174 | }
175 | else {
176 | return label;
177 | }
178 | case GENERIC_ADDED_NOTES_PLUS_SUS_AND_POW:
179 | pattern = "([BI]-)?[A-G][#b]?:(maj|7sus|dim|min|sus)(2|4|6|7)?(\\(\\*3\\))?"; // match added notes
180 | r = Pattern.compile(pattern); // create pattern object
181 | m = r.matcher(label); // simplify label
182 | if(m.find()) {
183 | return m.group(0);
184 | }
185 | else {
186 | return label;
187 | }
188 | case ADDED_NOTES:
189 | pattern = "([BI]-)?[A-G][#b]?:(7|minmaj|maj|min|dim|hdim|aug)(4|6|7)?"; // match added notes and
190 | // chord modes
191 | r = Pattern.compile(pattern); // create pattern object
192 | m = r.matcher(label); // simplify label
193 | if(m.find()) {
194 | return m.group(0);
195 | }
196 | else {
197 | return label;
198 | }
199 | case NONE:
200 | return label;
201 | default:
202 | return label;
203 | }
204 | }
205 |
206 | public static String getMode(String parentLabel) {
207 | String pattern = "(7sus4|sus4|sus2|maj\\(\\*3\\)|maj|min|dim|aug|ger|it|fr)";
208 | Pattern r = Pattern.compile(pattern);
209 | Matcher m = r.matcher(parentLabel);
210 | String mode = m.find() ? m.group(0) : "";
211 | // System.out.println("Mode: " + mode);
212 | return mode;
213 | }
214 |
215 | public static String getRoot(String parentLabel) {
216 | // get root note
217 | String pattern = "[A-G][#b]?";
218 | Pattern r = Pattern.compile(pattern);
219 | Matcher m = r.matcher(parentLabel);
220 | String root = m.find() ? m.group(0) : "";
221 |
222 | return root;
223 | }
224 |
225 | public static String normalizeEnharmonicChords(String label, boolean normalizeEnharmonics) throws IOException {
226 | if(!normalizeEnharmonics) {
227 | return label;
228 | }
229 |
230 | String prefix = new String();
231 | String root = new String();
232 | String suffix = new String();
233 | String pattern = "([BI]-)?(.*)(:(7sus|maj|min|dim|aug|ger|fr|it|sus)(2|4|6|7)?(\\(\\*3\\))?)";
234 | Pattern r = Pattern.compile(pattern);
235 | Matcher m = r.matcher(label);
236 |
237 | if(m.find()) {
238 | prefix = m.group(1);
239 | root = m.group(2);
240 | suffix = m.group(3);
241 | }
242 | String mode = getMode(label);
243 | String correctRoot = new String();
244 | int enharmonicRootID = root != "" ? enharmonicNotesToID.get(root) : 0;
245 |
246 | switch(mode) {
247 | case "maj":
248 | case "sus2":
249 | case "maj(*3)":
250 | correctRoot = enharmonicIDToMajChord.get(enharmonicRootID);
251 | break;
252 | case "min":
253 | case "dim":
254 | case "sus4":
255 | case "7sus4":
256 | correctRoot = enharmonicIDToMinOrDimChord.get(enharmonicRootID);
257 | break;
258 | case "ger":
259 | case "it":
260 | case "fr":
261 | correctRoot = enharmonicIDToAug6Chord.get(enharmonicRootID);
262 | break;
263 | default:
264 | correctRoot = enharmonicIDToMajChord.get(enharmonicRootID);
265 | break;
266 | }
267 |
268 | // System.out.println("");
269 | // System.out.println("Original label: " + label);
270 | // System.out.println("enharmonicRootID: " + enharmonicRootID + " original root: " + root + " correct root: " + correctRoot);
271 |
272 | if(!root.equals(correctRoot)) {
273 | // System.out.println("Original label: " + label);
274 | if(prefix != null) {
275 | label = prefix + correctRoot + suffix;
276 | }
277 | else {
278 | label = correctRoot + suffix;
279 | }
280 | // System.out.println("New label: " + label);
281 | }
282 |
283 | return label;
284 | }
285 |
286 | public static List labelsToSpans(List labels, List input, double length) {
287 | List result = new ArrayList();
288 | double onset = 0.0;
289 | double offset = 0.0;
290 | int startIndx = 0;
291 | int stopIndx = 0;
292 | SpanLabel label = null;
293 |
294 | for(int i = 0; i <= labels.size(); i++) {
295 | if (i == labels.size()) {
296 | stopIndx = i;
297 | offset = length;
298 | result.add(new Span(onset, offset, startIndx, stopIndx, label));
299 | }
300 | else {
301 | String form = labels.get(i).form;
302 | Event curEvent = input.get(i);
303 | if(form.startsWith("B")) {
304 | if(i != 0) {
305 | offset = curEvent.onset;
306 | stopIndx = i;
307 | result.add(new Span(onset, offset, startIndx, stopIndx, label));
308 | }
309 | onset = curEvent.onset;
310 | startIndx = i;
311 | label = SpanLabel.get(form.substring(form.indexOf("-")+1));
312 | }
313 | }
314 | }
315 | return result;
316 | }
317 |
318 |
319 | public static void setupFeatures(Class extends IFeatureType> featureTypeClass, String[] features){
320 | try {
321 | Method valueOf = featureTypeClass.getMethod("valueOf", String.class);
322 | IFeatureType[] featureTypes = (IFeatureType[])featureTypeClass.getMethod("values").invoke(null);
323 | if(features != null && features.length > 0){
324 | for(IFeatureType feature: featureTypes){
325 | feature.disable();
326 | }
327 | for(String feature: features){
328 | ((IFeatureType)valueOf.invoke(null, feature.toUpperCase())).enable();
329 | }
330 | }
331 | } catch (Exception e) {
332 | throw new RuntimeException(e);
333 | }
334 | }
335 |
336 | public static int[] listToArray(List list){
337 | for(int i = list.size() - 1; i >= 0; i--){
338 | if(list.get(i) == -1){
339 | list.remove(i);
340 | }
341 | }
342 | int[] result = new int[list.size()];
343 | for(int i = 0; i < list.size(); i++){
344 | result[i] = list.get(i);
345 | }
346 | return result;
347 | }
348 |
349 |
350 | }
--------------------------------------------------------------------------------
/src/cr/CRMain.java:
--------------------------------------------------------------------------------
1 | package cr;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.Calendar;
6 | import java.util.Collections;
7 | import java.util.Comparator;
8 | import java.util.HashMap;
9 | import java.util.List;
10 | import java.util.Set;
11 | import java.util.Vector;
12 |
13 | import static cr.SongUtil.print;
14 |
15 | import java.io.BufferedOutputStream;
16 | import java.io.File;
17 | import java.io.FileInputStream;
18 | import java.io.FileOutputStream;
19 | import java.io.IOException;
20 | import java.io.ObjectInputStream;
21 | import java.io.ObjectOutputStream;
22 | import java.io.PrintStream;
23 | import java.lang.reflect.Field;
24 |
25 | import com.statnlp.commons.types.Instance;
26 | import com.statnlp.hybridnetworks.DiscriminativeNetworkModel;
27 | import com.statnlp.hybridnetworks.FeatureArray;
28 | import com.statnlp.hybridnetworks.GenerativeNetworkModel;
29 | import com.statnlp.hybridnetworks.NetworkConfig;
30 |
31 | import com.statnlp.hybridnetworks.FeatureManager;
32 | import com.statnlp.hybridnetworks.GlobalNetworkParam;
33 | import com.statnlp.hybridnetworks.LocalNetworkParam;
34 | import com.statnlp.hybridnetworks.Network;
35 | import com.statnlp.hybridnetworks.NetworkCompiler;
36 | import com.statnlp.hybridnetworks.NetworkModel;
37 |
38 |
39 | public class CRMain {
40 |
41 | public enum Simplify {
42 | MODES, // simplify chord labels to major/minor/diminished/augmented triads
43 | GENERIC_ADDED_NOTES, // include added notes in chord labels (4ths, 6ths, 7ths) + aug6 chords
44 | GENERIC_ADDED_NOTES_PLUS_SUS_AND_POW, // include maj/min/dim modes, plus added notes (4ths, 6ths,
45 | // 7ths), plus sus2, sus4, maj(*3) (power chords), and 7sus4
46 | // (mostly in place for Rock dataset)
47 | ADDED_NOTES, // include added notes in chord labels (4ths, 6ths, 7ths) + additional
48 | // modes for 7ths (dom [i.e. 7], min-maj, hdim)
49 | NONE // include everything in chord label (modes, added notes, inversions,
50 | // missing notes)
51 | ;
52 |
53 | public static String helpString() {
54 | return "Please specify the simplification from the following choices:\n"
55 | + "\t-MODES\n"
56 | + "\t-NONE\n";
57 | }
58 | }
59 |
60 | public static Simplify simplification = Simplify.valueOf("NONE"); // simplification of chord labels used for training/testing
61 | // (see Simplify enum defined on line 19)
62 |
63 | public static void main(String[] args) throws IllegalArgumentException, InterruptedException, IOException, ClassNotFoundException, IllegalAccessException, NoSuchFieldException, SecurityException {
64 | // System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("output.txt")))); // redirect System.out output to "outOutput.txt"
65 | String dataPath = null; // prefix for training/testing files
66 | String foldsPath = null;
67 | String currentDirectoryPath = null;
68 | String trainFile = "";
69 | String testFile = "";
70 | String featureCountFile = "";
71 | String trainFilePath = null; // filename for training data
72 | String testFilePath = null; // filename for testing data
73 | String result_filename = null; // filename to store results
74 | String timestamp = Calendar.getInstance().getTime().toString();
75 | String modelFile = "";
76 | String modelPath = null;
77 | String featureCountPath = null;
78 | String useAllChordsPath = "all_chords.txt";
79 | String logFile = "";
80 | String logPath = null;
81 | Song[] trainInstances = null; // training data instances
82 | Song[] testInstances = null; // testing data instances
83 | boolean findMaxSegmentLength = true; // find maximum segment length?
84 | boolean writeModelText = false;
85 | boolean countFeatures = false;
86 | boolean normalizeEnharmonics = false;
87 | boolean useAllChords = false;
88 | boolean serializeModel = true;
89 | int maxLength = 955; // maximum song length
90 | int maxSegmentLength = 20; // maximum segment length
91 | int numExamplesPrinted = 20;
92 | int totalNumEvents = 0;
93 | int totalNumSegments = 0;
94 | int foldNum = 0;
95 | NetworkConfig._numThreads = 4; // number of threads used
96 | NetworkConfig.L2_REGULARIZATION_CONSTANT = 0.125;
97 | NetworkConfig.objtol = 1e-6;
98 | String weightInit = "random";
99 | int maxNumIterations = 5000; // maximum number of iterations for training
100 | String[] features = new String[0]; // list of features to be used
101 | NetworkCompiler compiler = null;
102 | NetworkModel model = null;
103 |
104 | // read in command line arguments
105 | int argIndex = 0; // index of command line argument within args
106 | String[] moreArgs = new String[0]; // additional command line arguments for FeatureManager, etc.
107 | while(argIndex < args.length) {
108 | String arg = args[argIndex];
109 | if(arg.charAt(0) == '-') {
110 | switch(arg.substring(1)) {
111 | case "dataPath":
112 | dataPath = args[argIndex + 1];
113 | argIndex += 2;
114 | break;
115 | case "foldsPath":
116 | foldsPath = args[argIndex + 1];
117 | argIndex += 2;
118 | break;
119 | case "currentDirectoryPath":
120 | currentDirectoryPath = args[argIndex + 1];
121 | argIndex += 2;
122 | break;
123 | case "trainFile":
124 | trainFile = args[argIndex + 1];
125 | argIndex += 2;
126 | break;
127 | case "testFile":
128 | testFile = args[argIndex + 1];
129 | argIndex += 2;
130 | break;
131 | case "foldNum":
132 | foldNum = Integer.parseInt(args[argIndex + 1]);
133 | argIndex += 2;
134 | break;
135 | case "features":
136 | features = args[argIndex + 1].split(",");
137 | argIndex += 2;
138 | break;
139 | case "resultPath":
140 | result_filename = args[argIndex + 1];
141 | argIndex += 2;
142 | break;
143 | case "logPath":
144 | logPath = args[argIndex + 1];
145 | argIndex += 2;
146 | break;
147 | // case "featureCountPath":
148 | // featureCountPath = args[argIndex + 1];
149 | // argIndex += 2;
150 | // break;
151 | case "useAllChordsPath":
152 | useAllChordsPath = args[argIndex + 1];
153 | argIndex += 2;
154 | break;
155 | case "simplify":
156 | try {
157 | simplification = Simplify.valueOf(args[argIndex+1].toUpperCase());
158 | } catch (IllegalArgumentException e) {
159 | throw new IllegalArgumentException("Unrecognized simplification: " + args[argIndex + 1] + "\n" + Simplify.helpString());
160 | }
161 | argIndex += 2;
162 | break;
163 | case "writeModelText":
164 | writeModelText = true;
165 | argIndex += 1;
166 | break;
167 | case "nThreads":
168 | NetworkConfig._numThreads = Integer.parseInt(args[argIndex+1]);
169 | argIndex += 2;
170 | break;
171 | case "modelFile":
172 | modelFile = args[argIndex + 1];
173 | argIndex += 2;
174 | break;
175 | case "l2":
176 | NetworkConfig.L2_REGULARIZATION_CONSTANT = Double.parseDouble(args[argIndex+1]);
177 | argIndex += 2;
178 | break;
179 | case "weightInit":
180 | weightInit = args[argIndex+1];
181 | if(weightInit.equals("random")){
182 | NetworkConfig.RANDOM_INIT_WEIGHT = true;
183 | } else {
184 | NetworkConfig.RANDOM_INIT_WEIGHT = false;
185 | NetworkConfig.FEATURE_INIT_WEIGHT = Double.parseDouble(weightInit);
186 | }
187 | argIndex += 2;
188 | break;
189 | case "numExamplesPrinted":
190 | numExamplesPrinted = Integer.parseInt(args[argIndex+1]);
191 | argIndex += 2;
192 | break;
193 | case "objtol":
194 | NetworkConfig.objtol = Double.parseDouble(args[argIndex+1]);
195 | argIndex += 2;
196 | break;
197 | case "countFeatures":
198 | countFeatures = true;
199 | argIndex += 1;
200 | break;
201 | case "normalizeEnharmonics":
202 | normalizeEnharmonics = true;
203 | argIndex += 1;
204 | break;
205 | case "useAllChords":
206 | useAllChords = true;
207 | argIndex += 1;
208 | break;
209 | case "-":
210 | moreArgs = Arrays.copyOfRange(args, argIndex+1, args.length);
211 | argIndex = args.length;
212 | break;
213 | default:
214 | throw new IllegalArgumentException("Unrecognized argument: " + arg);
215 | }
216 | } else {
217 | throw new IllegalArgumentException("Error while parsing: " + arg);
218 | }
219 | }
220 |
221 |
222 |
223 | if(trainFile.isEmpty()) {
224 | trainFile = "train" + foldNum + ".txt";
225 | }
226 |
227 | if(testFile.isEmpty()) {
228 | testFile = "test" + foldNum + ".txt";
229 | }
230 |
231 | if(featureCountFile.isEmpty()) {
232 | featureCountFile = "feature_count" + foldNum + ".txt";
233 | }
234 |
235 | if(modelFile.isEmpty()) {
236 | modelFile = timestamp + " Fold " + foldNum + ".model";
237 | }
238 |
239 | if(logFile.isEmpty()) {
240 | logFile = timestamp + " Fold " + foldNum + ".log";
241 | }
242 |
243 |
244 | // create train, test, feature count, model, and log paths
245 | trainFilePath = foldsPath + trainFile;
246 | System.out.println(trainFilePath);
247 | testFilePath = foldsPath + testFile;
248 | System.out.println(testFilePath);
249 | featureCountPath = featureCountFile;
250 | modelPath = modelFile;
251 | logPath = logFile;
252 |
253 | PrintStream outstream = null;
254 | if(logPath != null) {
255 | outstream = new PrintStream(logPath, "UTF-8");
256 | }
257 |
258 | WordWeakSemiCRFFeatureManager fm = null;
259 | if(trainFilePath != null) {
260 | List trainInstancesList; // list of songs used as training data
261 |
262 | // read in songs
263 | trainInstancesList = Arrays.asList(SongUtil.readData(trainFilePath, true, simplification, normalizeEnharmonics));
264 |
265 | // use all chord labels option
266 | if(useAllChords) {
267 | SongUtil.addAllLabels(useAllChordsPath);
268 | }
269 |
270 | // labels
271 | SpanLabel[] labels = SpanLabel.LABELS.values().toArray(new SpanLabel[SpanLabel.LABELS.size()]);
272 |
273 | String max_song_length = "";
274 | int max_song_onset = 0;
275 | for(int instanceIdx = trainInstancesList.size()-1; instanceIdx >= 0; instanceIdx--) {
276 | Song instance = trainInstancesList.get(instanceIdx);
277 |
278 | // find max song length
279 | int size = instance.size();
280 | maxLength = Math.max(maxLength, size);
281 | totalNumEvents += size;
282 | totalNumSegments += instance.output.size();
283 |
284 | // find max segment length
285 | if(findMaxSegmentLength) {
286 | List output = instance.output;
287 | for(Span span: output) {
288 | double maxSegmentLengthTmp = maxSegmentLength;
289 | maxSegmentLength = Math.max(maxSegmentLength, span.stop - span.start);
290 | if(maxSegmentLengthTmp < maxSegmentLength) {
291 | max_song_length = instance.title;
292 | max_song_onset = span.start;
293 | }
294 | }
295 | }
296 | }
297 | System.out.println("Max song length: " + maxLength + " Max segment length: " + maxSegmentLength + " Title: " + max_song_length + " Onset: " + max_song_onset);
298 | System.out.println("Total num events: " + totalNumEvents + ", Total num segments: " + totalNumSegments);
299 |
300 | trainInstances = trainInstancesList.toArray(new Song[trainInstancesList.size()]);
301 |
302 | NetworkConfig.TRAIN_MODE_IS_GENERATIVE = false;
303 | NetworkConfig._CACHE_FEATURES_DURING_TRAINING = true;
304 |
305 | int size = trainInstances.length;
306 |
307 | print("Read..."+size+" instances.", true, outstream, System.err);
308 |
309 | compiler = new WordWeakSemiCRFNetworkCompiler(labels, maxLength, maxSegmentLength);
310 |
311 | if(countFeatures) {
312 | fm = new WordWeakSemiCRFFeatureManager(new GlobalNetworkParam(), features, countFeatures, featureCountPath, moreArgs);
313 | List counts = new ArrayList(Collections.nCopies(10000, 0));
314 |
315 | for(Instance trainInstance : trainInstances) {
316 | Network network = compiler.compile(-1, trainInstance, new LocalNetworkParam(-1, fm, -1));
317 | for(int k = 0; k labelsUsed = new ArrayList