sander-wood
commited on
Commit
•
391ba08
1
Parent(s):
01f7146
Update README.md
Browse files
README.md
CHANGED
@@ -18,8 +18,135 @@ In [CLaMP: Contrastive Language-Music Pre-training for Cross-Modal Symbolic Musi
|
|
18 |
|
19 |
WikiMT is a unique resource to support the evaluation of semantic search and music classification. However, it is important to acknowledge that the dataset was curated from publicly available sources, and there may be limitations concerning the accuracy and completeness of the genre and description information. Further research is needed to explore the potential biases and limitations of the dataset and to develop strategies to address them. Therefore, to support additional investigations, we also provide the [source files](https://github.com/microsoft/muzic/blob/main/clamp/wikimusictext/source_files.zip) of WikiMT, including the MusicXML files from Wikifonia and the original entries from Wikipedia.
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
## Copyright Disclaimer
|
22 |
-
WikiMT was curated from publicly available sources and
|
23 |
|
24 |
## BibTeX entry and citation info
|
25 |
```
|
|
|
18 |
|
19 |
WikiMT is a unique resource to support the evaluation of semantic search and music classification. However, it is important to acknowledge that the dataset was curated from publicly available sources, and there may be limitations concerning the accuracy and completeness of the genre and description information. Further research is needed to explore the potential biases and limitations of the dataset and to develop strategies to address them. Therefore, to support additional investigations, we also provide the [source files](https://github.com/microsoft/muzic/blob/main/clamp/wikimusictext/source_files.zip) of WikiMT, including the MusicXML files from Wikifonia and the original entries from Wikipedia.
|
20 |
|
21 |
+
## Obtaining ABC Notation Music Scores
|
22 |
+
|
23 |
+
To access ABC notation music scores from the WikiMT dataset, you will need to follow these steps:
|
24 |
+
|
25 |
+
1. **Find the Wikifonia Data Link:** The code provided does not offer a direct link to download Wikifonia.zip. To obtain the Wikifonia dataset, you must first locate a download link for the ABC notation data. You can search for it on the internet or on Wikifonia-related websites.
|
26 |
+
|
27 |
+
2. **Run the Provided Code:** After finding the download link for the Wikifonia ABC notation data, you can execute the provided Python code. The code will prompt you to input the URL from which to fetch the ABC notation data.
|
28 |
+
|
29 |
+
For example, you will be prompted to enter the URL as follows:
|
30 |
+
|
31 |
+
```python
|
32 |
+
Enter the Wikifonia URL: [Paste your URL here]
|
33 |
+
```
|
34 |
+
|
35 |
+
Paste the URL to the Wikifonia.zip file and press Enter. The code will then proceed to download, process, and extract the musical content, making it accessible for your research or applications.
|
36 |
+
|
37 |
+
By following these steps, you can successfully obtain ABC notation music scores from the WikiMT dataset after providing the necessary download link.
|
38 |
+
|
39 |
+
```python
|
40 |
+
import subprocess
|
41 |
+
import os
|
42 |
+
import json
|
43 |
+
import zipfile
|
44 |
+
import io
|
45 |
+
|
46 |
+
# Install the required packages if they are not installed
|
47 |
+
try:
|
48 |
+
from unidecode import unidecode
|
49 |
+
except ImportError:
|
50 |
+
subprocess.check_call(["python", '-m', 'pip', 'install', 'unidecode'])
|
51 |
+
from unidecode import unidecode
|
52 |
+
|
53 |
+
try:
|
54 |
+
from tqdm import tqdm
|
55 |
+
except ImportError:
|
56 |
+
subprocess.check_call(["python", '-m', 'pip', 'install', 'tqdm'])
|
57 |
+
from tqdm import tqdm
|
58 |
+
|
59 |
+
try:
|
60 |
+
import requests
|
61 |
+
except ImportError:
|
62 |
+
subprocess.check_call(["python", '-m', 'pip', 'install', 'requests'])
|
63 |
+
import requests
|
64 |
+
|
65 |
+
def filter(lines):
|
66 |
+
# Filter out all lines that include language information
|
67 |
+
music = ""
|
68 |
+
for line in lines:
|
69 |
+
if line[:2] in ['A:', 'B:', 'C:', 'D:', 'F:', 'G', 'H:', 'I:', 'N:', 'O:', 'R:', 'r:', 'S:', 'T:', 'W:', 'w:', 'X:', 'Z:'] \
|
70 |
+
or line=='\n' \
|
71 |
+
or (line.startswith('%') and not line.startswith('%%score')):
|
72 |
+
continue
|
73 |
+
else:
|
74 |
+
if "%" in line and not line.startswith('%%score'):
|
75 |
+
line = "%".join(line.split('%')[:-1])
|
76 |
+
music += line[:-1] + '\n'
|
77 |
+
else:
|
78 |
+
music += line + '\n'
|
79 |
+
return music
|
80 |
+
|
81 |
+
def load_music(filename):
|
82 |
+
# Convert the file to ABC notation
|
83 |
+
p = subprocess.Popen(
|
84 |
+
f'cmd /u /c python xml2abc_145/xml2abc.py -m 2 -c 6 -x "{filename}"',
|
85 |
+
stdout=subprocess.PIPE,
|
86 |
+
stderr=subprocess.PIPE,
|
87 |
+
shell=True
|
88 |
+
)
|
89 |
+
out, err = p.communicate()
|
90 |
+
|
91 |
+
output = out.decode('utf-8').replace('\r', '') # Capture standard output
|
92 |
+
music = unidecode(output).split('\n')
|
93 |
+
music = filter(music).strip()
|
94 |
+
|
95 |
+
return music
|
96 |
+
|
97 |
+
def download_and_extract(url):
|
98 |
+
print(f"Downloading {url}")
|
99 |
+
|
100 |
+
# Send an HTTP GET request to the URL and get the response
|
101 |
+
response = requests.get(url, stream=True)
|
102 |
+
|
103 |
+
if response.status_code == 200:
|
104 |
+
# Create a BytesIO object and write the HTTP response content into it
|
105 |
+
zip_data = io.BytesIO()
|
106 |
+
total_size = int(response.headers.get('content-length', 0))
|
107 |
+
|
108 |
+
with tqdm(total=total_size, unit='B', unit_scale=True) as pbar:
|
109 |
+
for data in response.iter_content(chunk_size=1024):
|
110 |
+
pbar.update(len(data))
|
111 |
+
zip_data.write(data)
|
112 |
+
|
113 |
+
# Use the zipfile library to extract the file
|
114 |
+
print("Extracting the zip file...")
|
115 |
+
with zipfile.ZipFile(zip_data, "r") as zip_ref:
|
116 |
+
zip_ref.extractall("")
|
117 |
+
|
118 |
+
print("Done!")
|
119 |
+
|
120 |
+
else:
|
121 |
+
print("Failed to download the file. HTTP response code:", response.status_code)
|
122 |
+
|
123 |
+
# Special thanks to Wim Vree for xml2abc.py
|
124 |
+
download_and_extract("https://wim.vree.org/svgParse/xml2abc.py-145.zip")
|
125 |
+
|
126 |
+
# Download the Wikifonia dataset
|
127 |
+
wikifonia_url = input("Enter the Wikifonia URL: ")
|
128 |
+
download_and_extract(wikifonia_url)
|
129 |
+
|
130 |
+
wikimusictext = []
|
131 |
+
with open("wikimusictext.jsonl", "r", encoding="utf-8") as f:
|
132 |
+
for line in f.readlines():
|
133 |
+
wikimusictext.append(json.loads(line))
|
134 |
+
|
135 |
+
updated_wikimusictext = []
|
136 |
+
|
137 |
+
for song in tqdm(wikimusictext):
|
138 |
+
filename = song["artist"] + " - " + song["title"] + ".mxl"
|
139 |
+
filepath = os.path.join("Wikifonia", filename)
|
140 |
+
song["music"] = load_music(filepath)
|
141 |
+
updated_wikimusictext.append(song)
|
142 |
+
|
143 |
+
with open("wikimusictext.jsonl", "w", encoding="utf-8") as f:
|
144 |
+
for song in updated_wikimusictext:
|
145 |
+
f.write(json.dumps(song, ensure_ascii=False)+"\n")
|
146 |
+
```
|
147 |
+
|
148 |
## Copyright Disclaimer
|
149 |
+
WikiMT was curated from publicly available sources, and all rights to the original content and data remain with their respective copyright holders. The dataset is made available for research and educational purposes, and any use, distribution, or modification of the dataset should comply with the terms and conditions set forth by the original data providers.
|
150 |
|
151 |
## BibTeX entry and citation info
|
152 |
```
|